Question: Code In Java Swing. Write a program that lets two people play the simple game of Pontoon. Pontoon is a simple game, where the aim
Code In Java Swing.
Write a program that lets two people play the simple game of Pontoon.
Pontoon is a simple game, where the aim is to force the other player to cause the running total to go above 21.
The game begins with a grid of squares. Each square contains a random value between 1 and 5:
The program will randomly choose which player goes first. That player must then select a square:
Notice that the value of that square is added to the 'Current' total. The other player then takes their turn:
Players cannot select a square that's already been chosen by either player.
When a player is forced to make the total go above 21 (in this case it was Player 1), the game ends and the other player is declared the winner:
Provide clear instructions for how to compile, run and use your program. Example instructions are given below:
How to compile and run:
1. Place all the .java class files in a single folder
2. Open Terminal/Console/Command Prompt (depending on your OS)
3. Enter javac *.java
4. Enter java Driver (you will need to change this to the name of the class that contains your main() method)
5. When the game runs, click on New Game to begin. Take turns to select a square until a winner is announced. Click on 'New Game' to start a new game at any time.
Adjust these instructions as necessary for your particular implementation. Don't just copy paste them. Test that they work.
You cannot tell the user to use an IDE (such as BlueJ or Eclipse), they must be able to compile the program in Terminal/Console/Command Prompt.
Most common reasons that a program won't compile? Either your code contains package statements that were added by your IDE and need to be removed, or you need to changing a filename to match a classname.
The program must use a GUI to receive user input, to show player moves and to display the current state of the squares.
At launch the GUI should display a simple instruction, a new game button and a 5 x 5 grid of squares.
The system should initialize the grid so that no values appear in the squares until 'New Game' is pressed.
When 'New Game' is pressed, each square should be assigned a random value between 1 and 5.
Player 1 or Player 2 should be randomly selected to take the first turn. The user interface should tell the user whose turn it is.
The player should then be able to click on a square to cause its value to be added to the current total.
The other player is then allowed their turn.
During a game, once a square has been selected, it cannot be selected again by either player.
When a player causes the total to go above 21, the user interface should display a message to show who won, and prevent further selection of squares.
At all times during play the player should be given the option to begin playing a new game. When 'New Game' is clicked on, a new set of random values should appear in the squares and the current total should reset to zero.
Do not worry too much about the quality of your code design or on the look of the user interface - functionality is what is key. But the code must work/execute.
The code should have all of the following features:
Start Up: displays a GUI displays a 'New Game' button in the GUI displays a simple instruction in the GUI such as "Keep the total below 22. Click New Game to begin." draws the 5 x 5 grid in the GUI and each square can be seen clearly when New Game is clicked, random values from 1 to 5 appear in the squares, not the same set of values each time.
Game Play: the user is told whose turn it is, all messages must appear in the GUI the player is able to select a grid square that has not already been chosen the square changes colour to show that it's been selected, with a different color used for each player the current total updates to reflect the chosen square's value play switches correctly between players user is able to start a new game at any time by clicking on the New Game button
End of Game: the program recognizes when the game is won and announces the winner, for example, when all the lights are out a message such as "Well done!" or similar is displayed when a game has finished players cannot select any more squares Quit Game: allows user to close the window to quit such as by clicking the 'X' button in the top corner of the window frame Documentation: compile and run instructions provided, must say how to compile in Console/Terminal and must not say to compile and run in BlueJ or any other IDE
Note: All programming will be in Java and runnable without modification. You must provide the original .java files as well as compile and run instructions. It must not require the use of an IDE, such as BlueJ to run.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
