Advertisement
Guest User

Place piece

a guest
Jan 20th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. public void playerMove(Piece thePiece){
  2.             boolean validInput = false;
  3.             do{
  4.                
  5.            
  6.                 if (thePiece == Piece.Cross){
  7.                     System.out.println("Player 1's turn (X), please enter a number between 1-7 to choose which colum to place your piece");
  8.                 } else{
  9.                         System.out.println("Player 2's turn (0), please enter a number between 1-7 to choose which colum to place your piece");    
  10.                 }
  11.            
  12.                 int col = in.nextInt() - 1;
  13.                
  14.                 if ((0 <= col && col < 7)){
  15.                     validInput = true;
  16.                     }
  17.                 else{
  18.                     System.out.println("Move placed on " + (col +1) + ", is not valid, please enter again");
  19.                 }
  20.              
  21.                 if(board.position[0][col].content!=Piece.Empty)
  22.                 {
  23.                     validInput = false;
  24.                     System.out.println("The Column is already full. Please Select Another Column");
  25.                     continue;
  26.                 }
  27.                 for(int h = 5; h>= 0; h--){
  28.                    
  29.                     if(board.position[h][col].content==Piece.Empty){
  30.                         {
  31.                             board.position[h][col].content=thePiece;
  32.                             return;
  33.                         }
  34.                     }
  35.                    
  36.                 }
  37.                
  38.                 } while (!validInput);
  39.          
  40.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement