Question: need help creating a connect four game using the methods above, can't import anything other than what has been imported. 6 public class Board {

need help creating a connect four game using the methods above, can'timport anything other than what has been imported. 6 public class Board{ 7 // Add your own PRIVATE fields here. 8 // Theyneed help creating a connect four game using the methods above, can't import anything other than what has been imported.

6 public class Board { 7 // Add your own PRIVATE fields here. 8 // They must have type char, inte boolean, String, or they can be 10 or 2D arrays of these types. 9 100 /** 11 Constructs a new empty connect 4 game board with player X being the first player 12 * and player 'o' being the second player. 13 */ 140 public Board() { 15 throw new RuntimeException("Not implemented"); 16 } 17 180 /** 19 Gets the current player (either 'X' or '0') 20 21 @return the current player 22 230 public char currentPlayer() { 24 throw new RuntimeException ("Not implemented"); 25 } 26 270 /** 28 * The current player tries to make a move in a given column. If the move 29 * is valid, the board is updated and {@code true} is returned. If the move 30 is invalid (not a valid column number of the column is already full) 31 * the board remains unchanged and {@code false} is returned. If the game is 32 already over, a RuntimeException is thrown instead. 33 34 @param column the column in which to make a move. For the move to be valid, 35 * the column value must an {@code int} between 1 and 7 inclusive, and 36 there must have been fewer than 6 moves already made in the given column. 37 * @return {@code true} if the move is valid and false if it is not valid. 38 @throws RuntimeException if the game is already over. 39 */ 400 public boolean play(int column) { 41 throw new RuntimeException("Not implemented"); 42 } 43 /** * Determines if the game is already over. * @return {@acade true} if the game is over and {@code false} if it is not over. */ public boolean gameOver() { throw new RuntimeException("Not implemented"); } 44 45 460 47 48 49 50 510 52 53 54 550 56 57 58 59 60 610 62 63 64 650 66 67 68 69 70 71 A 720 73 74 75 760 77 78 79 800 81 /** * Determine the winner (assuming the game is over). * @return {@code 'X'} or {@code 'o'} if either player has won and {@code ''} * if the game is not over or if the game is a draw. */ public char winner() { throw new RuntimeException("Not implemented"); } are /** * Construct a describi the state game. ot reguried to implement * this method, however, implementing this method will make debugging much easier so * you are encrouaged to implement this to return a string that looks like the game board. * @return a string representation of the game */ public String toString() { return "toString() method not implemented."; } /* * This main can be used to play a game of Connect 4. In order to display the game board * you must have defined the toString method. */ public static void main(String[] args) { Board b = new Board(); /** Construct a string describing the state of the game. You are not requried to implement this method, however, implementing this method will make debugging much easier so you are encrouaged to implement this to return a string that looks like the game board. * @return a string representation of the game */ public String toString() { return "toString() method not implemented."; } 64 650 66 67 68 69 70 71 720 73 74 75 760 77 78 79 800 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 } 192 This main can be used to play a game of Connect 4. In order to display the game board you must have defined the toString method. */ public static void main(String[] args) { Board b = new Board(); while (!b.gameOver()) { boolean legalMove = false; while (!legalMove) { Stdout.println(" "); Stdout.println(b); Stdout.println("Current player: " + b.currentPlayer()); Stdout.println("Enter column number for next move: "); int col = stdin.readInt(); legalMove = b.play(col); } } Stdout.println(" "); Stdout.println(b); Stdout.println("GAME OVER"); if (b.winner() == '') Stdout.println("It's a draw"); else Stdout.println(b.winner() + " WINS!!!"); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!