Let’s build a command-line number guessing game.
You must complete the following assignment using a circular linked-list.
- First, you will need to create a “Player” class. This class will contain a field that will hold the player’s name, a field that tracks the player’s number of wins (correct guesses), a field that tracks the number of incorrect guesses, and have methods to get, set, and construct the object appropriately.
- Your game’s underlying structure will rely on a circular linked-list. You can build your own Node class or use one of those provided by the book.
- You can perform the game logic in your main method or you can abstract some or all tasks behind aGuessingGameclass. The choice is yours.
- How does the game work?
- Prompt the user for the number of players that want to play your game.
- Prompt each player to enter their name. Create a new Player object for each player, add it to a Node, and then link it into the list.
- Once all of the players are added choose a random number between 1 and 100 and start playing. Each player gets 1 guess and then the next player gets a turn. The player that guesses the number wins. The players continuing taking turns in a “circular” fashion until one of them wins. Pay special attention to this interaction.
- For each turn a player can guess a number, a player can choose to leave the game and be removed from the linked-list, or a player can choose to skip their turn and allow a new player to join in the game and be added to the linked-list. You’ll need a small menu system to handle this interaction. If there is only 1 player left in the list, that player is the winner.
- Once a player is declared the winner, prompt them if they’d like to play again. If so, immediately start the next game with the existing players. The player that won the previous game will now go first. If they choose to not play again then show the statistics for each player during the run of games just played (total games played, wins, losses, etc.) and then exit the program.
- Extra Credit
- 10 points: Keep track of the numbers already guessed. If a player chooses a number that has already been guessed they lose their next turn (they are skipped).
- 20 points: If a player guesses a number that is evenly divisible by the randomly selected number then the game will reverse itself and go in the opposite direction. This requires the use of a doubly linked-list.
- 50 points: Build the game so you can play the game by yourself against the computer. This means the program should ask if the player wants to play single or multi-player. If they select single-player the game should randomly generate 2 to 6 computer competitors (including random names). In single-player mode guessing numbers is the only option allowed on each turn. Players can’t leave or join the game.
Here is the explanation for... View the full answer