Menu

[solved]-Trouble Would Really Appreciate Help Problem Overview Goal Create Program Simulates Playin Q39089009

Having some trouble. Would really appreciate the help for thisproblem.

Overview
Your goal is to create a program that simulates playing Connect 4.Create a new project called “Project 4” and within it create aclass called Connect4.

Step 1: Simulating the Board (3 points)
The first thing you must do is simulate the Connect 4 board using atwo dimensional character array. A Connect 4 board has 6 rows and 7columns. In main(), create a two dimensional character array named“board” that has 6 rows and 7 columns.

Step 2: Displaying the Board (3 points)
The next thing you must do is create a method that displays theboard. Create a method with the following header:
private static void printBoard(char[][] charArr){
}
Assuming that no characters have been set inside charArr, a call tothe method printBoard() should display the following:
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
1 2 3 4 5 6 7

Step 3: Dropping Pieces (10 points)
Now that you can display your board, you must make a method thatallows you to “drop pieces” into the board. Create a method withthe following header.
private static void drop(char c, char[][] charArr, int col){
}
• Normally, Connect 4 has red and yellow pieces that you can dropinto the board. For our simulation, we will just be putting thecharacters “X” and “O” into our board. The character that you wantto drop into the board (either “X” or “O”) will be represented bythe first parameter, char c.
• The second parameter, char[][] charArr, will represent thecharacter array that you want to “drop” the first parameter, c,into.
• The third parameter, int col, will represent which column withincharArr you want to drop c into.
When you call the drop() method, it should place c into the lowestempty spot in column col of charArr.
Below is an example of using calls to drop() and printBoard()andwhat the corresponding output of printBoard() would be.
printBoard()
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
1 2 3 4 5 6 7
drop(“X”, board, 3);
printBoard();
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |X| | | | |
1 2 3 4 5 6 7
drop(“X”, board, 6);
printBoard();
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |X| | |X| |
1 2 3 4 5 6 7
drop(“O”, board, 3);
printBoard();
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |O| | | | |
| | |X| | |X| |
1 2 3 4 5 6 7

Step 4: Player Input (10 points)
Now that you can drop pieces in the board and display the board,you now have to create code that allows two players to alternatedropping pieces into the board.
In main() start by printing out the board using printBoard(). Then,using a while loop, create code that alternates between promptingtwo players (Player 1 and Player 2) to enter in an integer valuethat represents a column (a number 1 through 7) that they want todrop a piece into. When Player 1 enters in a column, drop an ‘X’into that column. When Player 2 enters in a column, drop an ‘O’into that column. Make sure you print out the board by callingprintBoard() every time after a player enters in a column.
Below is an example of what this should look like (user input inbold):
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
1 2 3 4 5 6 7
***PLAYER 1***
enter column: 3
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |X| | | | |
1 2 3 4 5 6 7
***PLAYER 2***
enter column: 6
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |X| | |O| |
1 2 3 4 5 6 7
***PLAYER 1***
enter column: 3
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |X| | | | |
| | |X| | |O| |
1 2 3 4 5 6 7
***PLAYER 2***
enter column:

Step 5: Input Checking (4 points)
Add code that prevents the players from inputting invalid columns.There are two cases for invalid columns:
• A player enters in a column less than 1 or greater than 7
o if a player enters a column less than 1 or greater than 7, anerror message should be printed out and they should be promptedagain.
o The game should not continue and the board should not be printedout until the player enters in a valid column
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
1 2 3 4 5 6 7
***PLAYER 1***
enter column: 0
***error: column must be between 1 and 7***
enter column: 8
***error: column must be between 1 and 7***
enter column: 3
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |X| | | | |
1 2 3 4 5 6 7
***PLAYER 2***
enter column:
• A player enters in a column that is already full
o If a player enters a column that is already full, an errormessage should be printed out and they should be promptedagain
o The game should not continue and the board should not be printedout until the player enters in a valid column
| | |O| | | | |
| | |X| | | | |
| | |O| | | | |
| | |X| | | | |
| | |O| | | | |
| | |X| | | | |
1 2 3 4 5 6 7
***PLAYER 1***
enter column: 3
***error: column is full. choose another column***
enter column: 3
***error: column is full. choose another column***
enter column: 4
| | |O| | | | |
| | |X| | | | |
| | |O| | | | |
| | |X| | | | |
| | |O| | | | |
| | |X|X| | | |
1 2 3 4 5 6 7
***PLAYER 2***
enter column:

Expert Answer


Answer to Having some trouble. Would really appreciate the help for this problem. Overview Your goal is to create a program that s… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *