feedbackHandler.java
上传用户:jhzhutan
上传日期:2021-03-28
资源大小:374k
文件大小:2k
源码类别:

射击游戏

开发平台:

Java

  1. //this class decode the instruction-string from the client program, then translate the string to real instructions that is
  2. //readable by the server program
  3. public class feedbackHandler{
  4. public static void handleInstruction(ServerModel gameModel, String instruction){
  5. if(instruction.length() == 0)
  6. return;
  7. int i = 0;
  8. while(i < instruction.length()){
  9. String perInstruction = "";
  10. //instructions are seperated by ";"  inside the instruction-string
  11. while(!instruction.substring(i, i+1).equals(";")){
  12. perInstruction+=instruction.substring(i, i+1);
  13. i++;
  14. }
  15. //instruction start with "m" indicate movement information from the client
  16. if(perInstruction.substring(0,1).equals("m")){
  17. gameModel.P2.moveUp = false;
  18. gameModel.P2.moveDown = false;
  19. gameModel.P2.moveLeft = false;
  20. gameModel.P2.moveRight = false;
  21. gameModel.P2.fire = false;
  22. String temp = perInstruction.substring(1,2);
  23. if(temp.equals("1"))
  24. gameModel.P2.moveUp = true;
  25. temp = perInstruction.substring(2,3);
  26. if(temp.equals("1"))
  27. gameModel.P2.moveDown = true;
  28. temp = perInstruction.substring(3,4);
  29. if(temp.equals("1"))
  30. gameModel.P2.moveLeft = true;
  31. temp = perInstruction.substring(4,5);
  32. if(temp.equals("1"))
  33. gameModel.P2.moveRight = true;
  34. temp = perInstruction.substring(5,6);
  35. if(temp.equals("1"))
  36. gameModel.P2.fire = true;
  37. }
  38. //instruction start with "m" indicates message from the server player
  39. if(perInstruction.substring(0,1).equals("e")){
  40. gameModel.addMessage("用户端玩家说:" + perInstruction.substring(1,perInstruction.length()));
  41. }
  42. //instruction start with "j" indicates client player want to play again
  43. if(perInstruction.substring(0,1).equals("j")){
  44. if(gameModel.gameOver)
  45. gameModel.clientVoteYes = true;
  46. }
  47. //instruction start with "x" indicates server player paused/unPaued the game
  48. if(perInstruction.substring(0,1).equals("x")){
  49. if(gameModel.gamePaused){
  50. gameModel.addMessage("用户端玩家取消了暂停");
  51. gameModel.gamePaused = false;
  52. } else if(!gameModel.gamePaused){
  53. gameModel.addMessage("用户端玩家暂停了游戏");
  54. gameModel.gamePaused = true;
  55. }
  56. }
  57. i++;
  58. }
  59. }
  60. }