Four in a row is a game in which players take turns adding tokens to the columns on the game board. Tokens fall to the lowest position in the chosen column that does not already have a token in it. Once one of the players has placed four of their tokens in a straight line (either vertically, horizontally, or diagonally), they win the game If the board is full and no player has won, then the game ends in a draw. TASK Using the following class descriptions, create a UML diagram and a version of Four in a row game
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Four in a row is a game in which players take turns adding tokens to the columns on the game board.
Tokens fall to the lowest position in the chosen column that does not already have a token in it. Once one of the players has placed four of their tokens in a straight line (either vertically, horizontally, or diagonally), they win the game
If the board is full and no player has won, then the game ends in a draw.
TASK
Using the following class descriptions, create a UML diagram and a version of Four in a row game
-
The game must allow for a minimum of two and maximum of four players
-
The game must allow each player to enter their name(duplicate names should not be accepted)
-
The game should give the players the ability to choose how many rows (between four and ten), and how many columns (between four and ten) the game board should have.
-
The code uses several classes, including "Player", "Board","Game" and exceptions for handling errors such as invalid moves and full columns.
Overview
-
Create the Player class, which will handle the players in the game.
-
Create the constructor, which will take in the player's name and player number as arguments and set them to instance variables.
-
Create the getName and getPlayerNumber methods, which will return the player's name and player number, respectively.
-
Create the makeMove method, which will prompt the user for the column where they want to drop their token and return that value.
-
Create a UML class diagram to visualize the relationships between classes and their methods and attributes. You can use a UML tool like Lucidchart, Visual Paradigm, or draw.io to create a class diagram.
Step by step
Solved in 4 steps