Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Game {
  4.  
  5. // The following five constants were defined in the starter code (kt54)
  6. private static String WHITEPLAYS_MSG = "White plays. Enter move:";
  7. private static String BLACKPLAYS_MSG = "Black plays. Enter move:";
  8. private static String ILLEGALMOVE_MSG = "Illegal move!";
  9. private static String WHITEWINS_MSG = "White wins!";
  10. private static String BLACKWINS_MSG = "Black wins!";
  11.  
  12. private Board gameBoard;
  13.  
  14. // Minimal constructor. Expand as needed (kt54)
  15. public Game() {
  16. gameBoard = new Board();
  17. }
  18.  
  19. private void displayStatus(int movesMade, boolean done) {
  20.  
  21. System.out.println("Moves made: " + movesMade);
  22.  
  23. if (done)
  24. System.out.println("Game Over!");
  25. else if (gameBoard.getBlackToPlay())
  26. System.out.println(BLACKPLAYS_MSG);
  27. else
  28. System.out.println(WHITEPLAYS_MSG);
  29. }
  30.  
  31. // Build on this method to implement game logic.
  32. public void play() {
  33.  
  34. Scanner reader = new Scanner(System.in);
  35.  
  36. gameBoard = new Board();
  37.  
  38. int movesMade = 0;
  39. boolean done = false;
  40.  
  41. String command = "";
  42. do {
  43. //Display board and status
  44. gameBoard.printBoard();
  45. displayStatus(movesMade, done);
  46. System.out.println("Enter command: move or quit");
  47.  
  48. //Recieve command from user and act
  49. command = reader.next();
  50.  
  51. if (command.equals("move")) {
  52. if (done)
  53. System.out.println("Game finished - no more moves allowed!");
  54. else {
  55. System.out.println("Select piece to move: ");
  56. String pos1 = reader.nextLine().trim();
  57. System.out.println("Select where to move piece: ");
  58. String pos2 = reader.nextLine().trim();
  59.  
  60. //if (makeMove(x1, x2, y1, y2)){
  61. //movesMade++;
  62. //}
  63. //Check for victory
  64.  
  65.  
  66. // Change player
  67.  
  68.  
  69. }
  70. //else
  71. //System.out.println("Illegal move!");
  72. }
  73. //System.out.println(BLACKPLAYS_MSG);
  74.  
  75.  
  76.  
  77. // This is just demonstration code, so we immediately let white win
  78. // to avoid unnecessary violence.
  79. //System.out.println(BLACKWINS_MSG);
  80. //done = true;
  81.  
  82. //Terminates game
  83. }while(!command.equals("quit"));
  84.  
  85.  
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement