Question: JAVA PROGRAM: For this project, as discussed today in class, you are going to simulate a space battle game. Two players (user vs computer) are
JAVA PROGRAM:
For this project, as discussed today in class, you are going to simulate a space battle game. Two players (user vs computer) are participating in a space battle that involves their fleet of spaceships. The one who can destroy all opponent's ships and still survive with some ships left in his fleet wins the game.
The game has the following main components:
Starting Units & Resource
Both players start with a fixed amount of resource. Both players spend resources to build their "setup units" and add them to their fleet.
Battle Round
A Space Battle always follows the Space Battle Sequence:
Roll combat dice
Remove casualties
Roll Combat Dice
Players roll one combat die (1-10) for each of their spaceships in the battle. For each result that is equal to or higher than the combat value of its ship, a "hit" is scored. Remember the total number of successful hits.
Remove Casualties
Each player now takes casualties equal to the number of hits scored by the opponent.
For each hit from the opponent, the player must destroy one of his ships (randomly or of his choice, up to you), or damage one of his Dreadnoughts.
If a damaged Dreadnought receives a second hit, it is destroyed.
End of a Space Battle
After the first Space Battle round is completed, if both players still have surviving ships in their fleet, another Space Battle round begins. This continues until only one player has ships in their fleet (or the ships of both players have been destroyed).
Cost and Combat Value of each Ship
| Type | Cost | Combat Value |
| Dreadnought | 5 | 5 |
| Cruiser | 2 | 7 |
| Fighter | 1 | 9 |
Notes:
You can read each players fleet from a text file (preferably two separate files, one for each player)
A ship can be defined as a class.
An ArrayList can be used to store the spaceships of each player.
A sample input file
Make proper use of functions and comments when neccessary to make your program as readable as possible
A sample run of this game (resouce was set to 30 for this game, you can set any fixed resource value):
Player's fleet: D: ^ ^ ^ Computer's fleet: D: AAA Round 1: Computer took 5 hit(s) Dreadnought sustained a damage! Dreadnought sustained a damage! Cruiser destroyed! Dreadnought destroyed! Fighter destroyed! Player took 7 hit(s) Dreadnought sustained a damage! Cruiser destroyed! Fighter destroyed! Fighter destroyed! Fighter destroyed! Dreadnought sustained a damage! Dreadnought sustained a damage! Player's fleet: D: A A A Computer's fleet: D: AA A Round 2: Computer took 3 hit(s) Cruiser destroyed! Dreadnought destroyed! Dreadnought sustained a damage! Player took 4 hit(s) Cruiser destroyed! Dreadnought sustained a damage! Dreadnought destroyed! Dreadnought destroyed! Player's fleet: D: A A Computer's fleet: D: A A Round 3: Computer took 2 hit(s) Dreadnought sustained a damage! Fighter destroyed! Player took 4 hit(s) Fighter destroyed! Dreadnought destroyed! Cruiser destroyed! Dreadnought destroyed! Player's fleet: D: Computer's fleet: D AA C: Computer won! after 3 roundsStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
