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

📄 feedbackhandler.java

📁 1。支持双人连线 (适用于TCP/IP
💻 JAVA
字号:
//this class decode the instruction-string from the client program, then translate the string to real instructions that is
//readable by the server program

public class feedbackHandler{
	public static void handleInstruction(ServerModel gameModel, String instruction){
		if(instruction.length() == 0)
			return;

		int i = 0;
		while(i < instruction.length()){
			String perInstruction = "";

			//instructions are seperated by ";"  inside the instruction-string
			while(!instruction.substring(i, i+1).equals(";")){
				perInstruction+=instruction.substring(i, i+1);
				i++;
			}

			//instruction start with "m" indicate movement information from the client
			if(perInstruction.substring(0,1).equals("m")){
				gameModel.P2.moveUp = false;
				gameModel.P2.moveDown = false;
				gameModel.P2.moveLeft = false;
				gameModel.P2.moveRight = false;
				gameModel.P2.fire = false;

				String temp = perInstruction.substring(1,2);
				if(temp.equals("1"))
					gameModel.P2.moveUp = true;
				temp = perInstruction.substring(2,3);
				if(temp.equals("1"))
					gameModel.P2.moveDown = true;
				temp = perInstruction.substring(3,4);
				if(temp.equals("1"))
					gameModel.P2.moveLeft = true;
				temp = perInstruction.substring(4,5);
				if(temp.equals("1"))
					gameModel.P2.moveRight = true;
				temp = perInstruction.substring(5,6);
				if(temp.equals("1"))
					gameModel.P2.fire = true;
			}

			//instruction start with "m" indicates message from the server player
			if(perInstruction.substring(0,1).equals("e")){
				gameModel.addMessage("用户端玩家说:" + perInstruction.substring(1,perInstruction.length()));
			}

			//instruction start with "j" indicates client player want to play again
			if(perInstruction.substring(0,1).equals("j")){
				if(gameModel.gameOver)
					gameModel.clientVoteYes = true;
			}

			//instruction start with "x" indicates server player paused/unPaued the game
			if(perInstruction.substring(0,1).equals("x")){
				if(gameModel.gamePaused){
					gameModel.addMessage("用户端玩家取消了暂停");
					gameModel.gamePaused = false;
				} else if(!gameModel.gamePaused){
					gameModel.addMessage("用户端玩家暂停了游戏");
					gameModel.gamePaused = true;
				}
			}
			i++;
		}
	}

}

⌨️ 快捷键说明

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