I need help creating a class diagram for this please:
I am not sure what more you want? it has 2 classes at least Connect4 and Connect4TextConsole.
thanks for the question, I have designed 90% of the class, you just need to implement the winner method() in the Connect4 class, everything else is fully implemented.
==========================================================================================
public class Connect4 { private char[][] board; private int turn; public Connect4() { board = new char[6][7]; for (int r = 0; r < 6; r++) { for (int c = 0; c < 7; c++) { board[r][c] = ' '; } } turn = 0; } public boolean insert(int column, char letter) { if (1 <= column && column <= 7) { for (int row = 5; row >= 0; row--) { if (board[row][column - 1] == ' ') { board[row][column - 1] = letter; turn += 1; return true; } } System.out.println("There is no more room in that column"); } else { System.out.println("Invalid column entered"); } return false; } public void displayBoard() { for (int row = 0; row < 6; row++) { for (int col = 0; col < 7; col++) { System.out.print("|" + board[row][col] + ""); } System.out.println("|"); } } public boolean isWinner() { // need to implement return turn == 42; } }
=========================================================================================
import java.util.Scanner; public class Connect4TextConsole { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Connect4 connect4 = new Connect4(); connect4.displayBoard(); System.out.println("Begin Game"); int turn = 0; while (!connect4.isWinner()) { if (turn++ % 2 == 0) { while (true) { System.out.print("PlayerX - your turn. Choose a column number from 1-7: "); int column = scanner.nextInt(); boolean valid = connect4.insert(column, 'X'); if (valid) { break; } } }else{ while (true) { System.out.print("PlayerY - your turn. Choose a column number from 1-7: "); int column = scanner.nextInt(); boolean valid = connect4.insert(column, 'Y'); if (valid) { break; } } } connect4.displayBoard(); } } }
==========================================================================================
Instructions This assignment has to be completed by each student individually. NO COLLABORATION I...
The game Battleship is played on a grid board. Each opponent has multiple ships that are placed on the grid where the other opponent cannot see them. In order to attack, each player takes turns calling out coordinates on a grid. If the attacker calls out a coordinate that hits their opponent's ship, they must call out, "Hit." You are going to be developing a computer program to mimic this game. Use the Gridlayout that is six columns by six...
The game Battleship is played on a grid board. Each opponent has multiple ships that are placed on the grid where the other opponent cannot see them. In order to attack, each player takes turns calling out coordinates on a grid. If the attacker calls out a coordinate that hits their opponent's ship, they must call out, "Hit." You are going to be developing a computer program to mimic this game. Use the Gridlayout that is six columns by six...
Connect 4 is a 2 player game where each player has a set of colored tokens (red or yellow). Players take turns during which they place a single token into one of the columns of an n by m grid (where n is the number of rows and m is the number of columns. They place their token into a slot at the top of the column and it falls into the lowest unoccupied slot in that column. A player...
JAVA Only Help on the sections that say Student provide code. The student Provide code has comments that i put to state what i need help with. import java.util.Scanner; public class TicTacToe { private final int BOARDSIZE = 3; // size of the board private enum Status { WIN, DRAW, CONTINUE }; // game states private char[][] board; // board representation private boolean firstPlayer; // whether it's player 1's move private boolean gameOver; // whether...
Use Java language to create this program Write a program that allows two players to play a game of tic-tac-toe. Using a two-dimensional array with three rows and three columns as the game board. Each element of the array should be initialized with a number from 1 - 9 (like below): 1 2 3 4 5 6 7 8 9 The program should run a loop that Displays the contents of the board array allows player 1 to select the...
Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I will not be able to use those). Please ALSO create a flowchart using Flowgarithm program. Thank you so much, if answer is provided in Pseudocode and Flowchart, I will provide good feedback and thumbs up to the resonder. Thank you! Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional char array with three rows...
I need help with my programming assignment. The language used should be java and the algorithm should use search trees so that you play against the computer and he chooses the best move. The tree should have all possibilities on the leaves and you could use recursion to so that it populates itself. The game can be a 3*3 board (no need the make it n*n). Please put comments so that I can understand it. Thanks The game of ‘Walls’...
Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...
Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Displays the contents of the board array. Allows player 1 to select a location on the board for an X. The program should ask the user to enter...
(C++) Please create a tic tac toe game. Must write a Player class to store each players’ information (name and score) and to update their information (increase their score if appropriate) and to retrieve their information (name and score).The players must be called by name during the game. The turns alternate starting with player 1 in the first move of round 1. Whoever plays last in a round will play second in the next round (assuming there is one).The rows...