Advertisement
pro-themes

Player (Java)

Jan 29th, 2018
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Player{
  4.     private char playerLetter;
  5.     private int space;
  6.     private Board board;
  7.     Scanner input = new Scanner(System.in);
  8.    
  9.     public Player(){ }
  10.    
  11.     public Player(Character playerLetter, Board board){
  12.         this.playerLetter = playerLetter;
  13.         this.board = board;
  14.     }
  15.    
  16.     public void turn(){
  17.         System.out.print("It is your turn. ");
  18.         do{
  19.             System.out.print("Where would you like to set your mark (Enter 1 - 9): ");
  20.             space = input.nextInt();
  21.         } while (!board.notOccupied((space-1))); //if space != '-'
  22.        
  23.         board.setSpace((space-1), playerLetter);
  24.            
  25.         System.out.println("Space set. Turn Over, displaying the board.");
  26.         board.displayBoard();
  27.     }
  28.    
  29.     public char getLetter(){
  30.         return this.playerLetter;
  31.     }
  32.    
  33.     public boolean isValidLetter(char letter){
  34.         return (letter == 'O' ^ letter == 'X');
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement