Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Game {
- // The following five constants were defined in the starter code (kt54)
- private static String WHITEPLAYS_MSG = "White plays. Enter move:";
- private static String BLACKPLAYS_MSG = "Black plays. Enter move:";
- private static String ILLEGALMOVE_MSG = "Illegal move!";
- private static String WHITEWINS_MSG = "White wins!";
- private static String BLACKWINS_MSG = "Black wins!";
- private Board gameBoard;
- // Minimal constructor. Expand as needed (kt54)
- public Game() {
- gameBoard = new Board();
- }
- private void displayStatus(int movesMade, boolean done) {
- System.out.println("Moves made: " + movesMade);
- if (done)
- System.out.println("Game Over!");
- else if (gameBoard.getBlackToPlay())
- System.out.println(BLACKPLAYS_MSG);
- else
- System.out.println(WHITEPLAYS_MSG);
- }
- // Build on this method to implement game logic.
- public void play() {
- Scanner reader = new Scanner(System.in);
- gameBoard = new Board();
- int movesMade = 0;
- boolean done = false;
- String command = "";
- do {
- //Display board and status
- gameBoard.printBoard();
- displayStatus(movesMade, done);
- System.out.println("Enter command: move or quit");
- //Recieve command from user and act
- command = reader.next();
- if (command.equals("move")) {
- if (done)
- System.out.println("Game finished - no more moves allowed!");
- else {
- System.out.println("Select piece to move: ");
- String pos1 = reader.nextLine().trim();
- System.out.println("Select where to move piece: ");
- String pos2 = reader.nextLine().trim();
- //if (makeMove(x1, x2, y1, y2)){
- //movesMade++;
- //}
- //Check for victory
- // Change player
- }
- //else
- //System.out.println("Illegal move!");
- }
- //System.out.println(BLACKPLAYS_MSG);
- // This is just demonstration code, so we immediately let white win
- // to avoid unnecessary violence.
- //System.out.println(BLACKWINS_MSG);
- //done = true;
- //Terminates game
- }while(!command.equals("quit"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement