⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demohint3_p1_speed_unnumbered.java

📁 由于JAVA与平台无关的优点,现在用JAVA编写的小游戏已经非常普遍,相信对这款旋转俄罗斯方块会让大家耳目一新
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			int indexRadius = 0; // 作為移動計數器.
			boolean rowCentrifugal = false;
			for (int cordRadius = 0; cordRadius <= cordRadiusMax; ++cordRadius) {

				if (cordRadius <= cordRadiusMax - 1) {// 是否有真正進行離心作業.//注意是 != -10
					if (!rowCentrifugal && mapGame[cordAngel][cordRadius] != -10
							&& mapGame[cordAngel][cordRadius + 1] == -10) {
						++numRowCentrifugal;// 有真正 進行離心作業, 才遞增.
						rowCentrifugal = true;// rowCentrifugal使得numRowCentrifugal正確地遞增.
					}
				}

				if (mapGame[cordAngel][cordRadius] == -10) {
					mapGame[cordAngel][cordRadius] = -20;
					mapGame[cordAngel][indexRadius] = -10;
					++indexRadius;
				}

			}// end of inner for

			if (rowCentrifugal) {
				tetris.repaint();
				try {
					Thread.sleep(200);
				} catch (InterruptedException exc) {
				}
			}

		}// end of outter for
	}// end of centrifugal()

	void centrifugalL() {// 存在的徑向列, 一定是不可消除列.
		int firstRowCentrifugal = 0, numRowCentrifugal = 0;
		boolean findBrokenRow = false;
		for (int i = startAngelLPlayer; i <= endAngelLPlayer - 1; ++i) { // 從最頂部開始往下檢查
			for (int j = 0; j <= cordRadiusMax; ++j) {// 尋找第一列.
				if (mapGameL[i][j] == -10) {
					firstRowCentrifugal = i;
					findBrokenRow = true;
					break;// 找到不可以消除的逕向列, 所以跳出內部for迴圈.
				}
			} // end of inner for
			if (findBrokenRow)
				break; // 找到不可以消除的逕向列, 所以跳出外部for迴圈.
		} // end of outter for

		if (!findBrokenRow)
			return; // 很罕見, 徑向列被完全消除.
		// 執行離心作業.
		for (int cordAngel = firstRowCentrifugal; // cordAngel表示目前徑向座標,
		// 就是要進行離心作業的徑向列.
		cordAngel <= endAngelLPlayer - 1; ++cordAngel) {
			if (numRowCentrifugal >= 3)
				break;// 已經離心3個徑向列, 所以跳出.
			// 以下針對單一列, 進行離心移動.
			int indexRadius = 0; // 作為移動計數器.
			boolean rowCentrifugal = false;
			for (int cordRadius = 0; cordRadius <= cordRadiusMax; ++cordRadius) {

				if (cordRadius <= cordRadiusMax - 1) {// 是否有真正進行離心作業.//注意是 != -10
					if (!rowCentrifugal && mapGameL[cordAngel][cordRadius] != -10
							&& mapGameL[cordAngel][cordRadius + 1] == -10) {
						++numRowCentrifugal;// 有真正 進行離心作業, 才遞增.
						rowCentrifugal = true;// rowCentrifugal使得numRowCentrifugal正確地遞增.
					}
				}

				if (mapGameL[cordAngel][cordRadius] == -10) {
					mapGameL[cordAngel][cordRadius] = -20;
					mapGameL[cordAngel][indexRadius] = -10;
					++indexRadius;
				}

			}// end of inner for

			if (rowCentrifugal) {
				tetris.repaint();
				try {
					Thread.sleep(200);
				} catch (InterruptedException exc) {
				}
			}

		}// end of outter for
	}// end of centrifugal()

	void settxtField() {
		txtField.setText("\n" + "<==第3個方塊\n\n" + "<==第2個方塊\n\n" + "<==第1個方塊\n\n"
				+ "<==第3個方塊\n\n" + "<==第2個方塊\n\n" + "<==第1個方塊\n" + "速度: " + speed
				+ "       \n" + "煞車: " + brake + "       \n" + "rotateSpeed: "
				+ rotateSpeed + "       \n" + "列數: " + totalDeleted
				+ "       \n" + "圈數: " + circleRotate);
	}

	int brake = 0, speed = 1, speedIncreaseInterval = 0, speedIncreaseCount = 0,
			totalDeleted = 0, circleRotate = 0;

	boolean speedIncrease = true;

	boolean inGameLoop = false, inGameLoopL = false;
  int fallingConstant = 10, fallingInterval = fallingConstant;
  int speedContanst = 1, rotateSpeed = 19;
	void gameOneLoop() {
		boolean stopR = false, stopL = false;
		while (true) {
			tetris.repaint();
			try {
				Thread.sleep(rotateSpeed);
			} catch (InterruptedException exc) {
			}

			// if(nowRPlayer && !overR) {
			if (!fallingOK() || brickToSite)
				stopR = true; // 方塊不可以再下落了.
			if (inGameLoop) {
				setNewBrick();
				if(rotateSpeed <= 19) isSpeedDownBrick = true;
				inGameLoop = false;
			}
			if (!stopR) {
				--fallingInterval;
					if(fallingInterval <= 0) {
					setRPlayerFalling(); // 方塊的自由下落.
					fallingInterval = fallingConstant;
				}
				settxtField();
				// centrifugalValue = 0;
				speed = speedContanst;
				if (!rotateClockwise)
					rotateAngel = rotateAngel + speed;// 逆時針轉動
				else
					rotateAngel = rotateAngel - speed;// 順時針轉動
				if (speedIncreaseCount >= 6) {// 方塊每落下一格, 則遞增speedIncreaseInterval.
					// 依速度大小, 作為遞增多寡的依據.
					if (speed >= 3)
						speedIncreaseInterval = speedIncreaseInterval + 1;
					if (speed < 3)
						speedIncreaseInterval = speedIncreaseInterval + 3;
					speedIncreaseCount = 0;
				} else
					++speedIncreaseCount;

			}// end of if (!stopR)
			else {
				if (!overR) {
					scanAndErase(); // 其中有repaint().//右玩家掃描完畢.
					rotateSpeed = rotateSpeed -1;
					if (numDeleted != 0) {
						rotateSpeed = rotateSpeed +  3*numDeleted; // 速度依消去的列數減少.
						if (isSpeedDownBrick) // 如果是特殊方塊再減一次.
							rotateSpeed = rotateSpeed + 3*numDeleted;
						if (speed < 0)
							speed = 0;
					}
					
					setBrickNotInput = true;
					if (RBrickCanNotChange)
						RBrickCanNotChange = false;// 左玩家已經用掉交換方塊, 故左玩家回到可交換狀態.
					if (LPlayerChangRPlayer)
						LPlayerChangRPlayer = false;// 
					// 以下進行離心作業.
					// testCentrifugal = true;
					if (speed >= centrifugalValue && testCentrifugal && numDeleted > 0) { // 開始離心力
						centrifugal(); // testCentrifugal只是測試布林值, 表示開始離心作業.
						testCentrifugal = false;
					}

					totalDeleted = totalDeleted + numDeleted;
					if (speedIncreaseInterval >= 5) { // 速度增加.
						if (speed <= 12)
							speed = speed + 2;
						if (speed >= 12)
							speed = 12;
						speedIncreaseInterval = 0;
					}
					// if(!overL) nowRPlayer = false; //因為要輪流, 所以右玩家SCAN完, 設為TRUE, 換左玩家.
					fallingOver = false;
					brickToSite = false;
					currentBrickAngel = startAngelRPlayer + (2 - 1) + newBrickIncre;// 有增加newBrickIncre歐
					currentBrickRadius = (int) ((cordRadiusMax + 1) * Math.random());
					currentBrickRadius = cordRadiusMax / 2 + 1;
					if (!newBrickOK()) {// 只會傳回true或false
						overR = true;// 一方玩家結束, 將overR設為true.
					}// gameOver();
					else {// 可以起始一個新的方塊.
					// setNewBrick();
						inGameLoop = true;
						stopR = false;
						numDeleted = 0;
						// ++rotateAngel;
						try {
							Thread.sleep(newBrickTime);
						} catch (InterruptedException e) {
							// TODO 自動產生 catch 區塊
							e.printStackTrace();
						}
					}
				}
			} // end of else
			// }//end of nowRPlayer

			// else if(!nowRPlayer && !overL){//start of nowLPlayer
			// if (!fallingOKL() || brickToSiteL)
			// stopL = true; // 方塊不可以再下落了.
			// if(inGameLoopL) {
			// setNewBrickL();
			// inGameLoopL = false;
			// }
			// if (!stopL) {
			// setLPlayerFalling(); // 方塊的自由下落.
			// settxtField();
			// // centrifugalValue = 0;
			// speed = 0;
			// if (!rotateClockwise)
			// rotateAngel = rotateAngel + speed;// 逆時針轉動
			// else
			// rotateAngel = rotateAngel - speed;// 順時針轉動
			// if (speedIncreaseCount == 6) {// 方塊每落下一格, 則遞增speedIncreaseInterval.
			// // 依速度大小, 作為遞增多寡的依據.
			// if (speed >= 3)
			// speedIncreaseInterval = speedIncreaseInterval + 1;
			// if (speed < 3)
			// speedIncreaseInterval = speedIncreaseInterval + 3;
			// speedIncreaseCount = 0;
			// } else
			// ++speedIncreaseCount;
			//				
			// }//end of if (!stopR)
			// else {
			// if (!overL) {
			// scanAndEraseL(); // 其中有repaint().
			// setBrickNotInputL = true;
			// if(LBrickCanNotChange) LBrickCanNotChange = false;//左玩家已經用掉交換方塊,
			// 故左玩家回到可交換狀態.
			// if(RPlayerChangLPlayer) RPlayerChangLPlayer = false;
			// // 以下進行離心作業.
			// testCentrifugalL = true;
			// if (speed >= centrifugalValue && testCentrifugalL && numDeletedL > 0) {
			// // 開始離心力
			// centrifugalL(); // testCentrifugal只是測試布林值, 表示開始離心作業.
			// testCentrifugalL = false;
			// }
			//
			// totalDeleted = totalDeleted + numDeletedL;
			// if (speedIncreaseInterval >= 10) { // 速度增加.
			// if (speed <= 6)
			// speed = speed + 2;
			// if (speed >= 6)
			// speed = 6;
			// speedIncreaseInterval = 0;
			// }
			// if (numDeletedL != 0) {
			// speed = speed - numDeletedL; // 速度依消去的列數減少.
			// if (isSpeedDownBrickL) // 如果是特殊方塊再減一次.
			// speed = speed - numDeletedL;
			// if (speed < 0)
			// speed = 0;
			// }
			// if(!overR) nowRPlayer = true; //因為要輪流, 所以左玩家SCAN完, 設為TRUE, 換右玩家.
			// fallingOverL = false;
			// brickToSiteL = false;
			// currentBrickAngelL = startAngelLPlayer + (2 - 1) + newBrickIncreL;//
			// 有增加newBrickIncre歐
			// currentBrickRadiusL = (int) ((cordRadiusMax + 1) * Math.random());
			// currentBrickRadiusL = cordRadiusMax / 2;
			// if (!newBrickOKL()) {//只會傳回true或false
			// overL = true; //一方玩家結束, 將overL設為true.
			// }// gameOver();
			// else {//可以起始一個新的方塊.
			// // setNewBrickL();
			// inGameLoopL = true;
			// stopL = false;
			// numDeletedL = 0;
			// // ++rotateAngel;
			// try {
			// Thread.sleep(newBrickTime);
			// } catch (InterruptedException e) {
			// // TODO 自動產生 catch 區塊
			// e.printStackTrace();
			// }
			// }
			// }
			// } //end of else
			// }//end of nowLPlayer
		}// End Of While(GameLoop)
	}// End Of GameOneLoop

	class Tetris extends JPanel { // 可以設定背景、前景顏色
		public void clearBrick(Graphics2D g2d, int cordAngel, int cordRadius) {
			g2d.setColor(colorJPanel);
			if (!rotateClockwise)
				cordAngel = cordAngel - rotateAngel;
			else
				cordAngel = cordAngel + rotateAngel;
			g2d.fillArc(outerX + cordRadius * lengthBrick, outerY + cordRadius
					* lengthBrick,// 正方形左上角座標
					2 * outerR - 2 * cordRadius * lengthBrick, 2 * outerR - 2
							* cordRadius * lengthBrick,// 正方形的寬與高
					90 - cordAngel * degreeBrick, -degreeBrick);// 扇形的開始角度/ 終止角度/因為負角度是順時鐘
		}// end of paintBrick

		public void clearBrickL(Graphics2D g2d, int cordAngel, int cordRadius) {
			g2d.setColor(colorJPanel);
			cordAngel = (360 / degreeBrick) - 1 - cordAngel - rotateAngel;
			g2d.fillArc(outerX + cordRadius * lengthBrick, outerY + cordRadius
					* lengthBrick,// 正方形左上角座標
					2 * outerR - 2 * cordRadius * lengthBrick, 2 * outerR - 2
							* cordRadius * lengthBrick,// 正方形的寬與高
					90 - cordAngel * degreeBrick, -degreeBrick);// 扇形的開始角度/ 終止角度/因為負角度是順時鐘
		}// end of paintBrick

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -