Problem Description
Write a program to determine whether the player wins or loses after playing the battleship game. If the player has hit all targets included within the game grid, then the program should print “Player Wins”. However, when a single or more target is missed by the player, then the program should print “Player Loses”.
As an example, a player who takes the following turns: C3 D3 C4 C5
Will be displayed on the game grid as the following:
Copyright By PowCoder代写 加微信 powcoder
ABCDEFGH 1
2 3XO 4X 5X
Since the ship targets were initially placed at C3, C4, and C5. This means that the player hit all of the targets listed above, regardless of the miss at cell D3.
You will receive (from the user) the following as input (in order):
The count of targets to include in the grid (e.g., 3)
The grid area where a target or ‘ship’ should be placed (e.g., C3 C4 C5)
The player turns taken to try and guess where the ship is located (e.g., C3 D3 C4 C5) A sentinel value to indicate the end of the game (i.e., -1)
Processing
1. Set each target within the game grid
2. Update the game grid given each turn taken by the player to guess the target location within the grid 3. Display the game grid with each target hits displayed as “ X “, misses as “ O “, and empty cells as “ _ “ 4. Print whether the player wins or loses
Method Details
Your program must include three methods with the following signature:
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com