The main purpose of this excerise was to develop a different version of a classic game: "BattleShip".
Coding on Java SE Development Kit 16 while the Interface was made using SceneBuilder and JavaFx
- Make sure that you have JavaFx installed on your pc. If not, click here.
- Download the package
GameBattleship.jar
from this git-repo. - Open in Terminal and type:
java --module-path "path_to\javafx-sdk-15.0.1\lib" --add-modules javafx.controls,javafx.fxml -jar GameBattleship.jar"
The available ships are 5 and they are placed on a 10 x 10 grid.
Type | Ships | Positions | Points of hit | Bonus if sunk |
---|---|---|---|---|
1 | Carrier | 5 | 350 | 1000 |
2 | Battleship | 4 | 250 | 500 |
3 | Cruiser | 3 | 100 | 250 |
4 | Submarine | 3 | 100 | 0 |
5 | Destroyer | 2 | 0 | 0 |
Create two .txt
files one for the player: player_SCENARIO.txt
, and another one for the enemy enemy_SCENARIO.txt
Each .txt
file contains 5 lines. Each line is in the form: type, x_cordinate, y_cordinate, is_vertical
Example:
"1,3,2,1" means that Carrier ship will be placed on (3,2) position horizontally.
"2,5,5,2" means that Cruiser ship will be placed on (5,5) position vertically.
Restrinction in placement
- Ships can be placed only inside a grid
- In any cell one ship maximimum can be placed
- All ships are of different types
- Betwenn two ships at least should cells must intervene
If the placement is not proper, an exception is thrown and the user is notified with a message
After placing all ships, cick on the game icon to start playing. The window that shows up is :
Player is first notified whether he plays first or not. Each movement can be done inserting taget coordinates using the form x,y
. If not,
an exception is thrown and a message shows up. Of course in case a player shoots a ship, he plays again.
- Start : Start the game from the beggining. Initialize all shots
- Load : Load a proper scenario, by typing SCENARIO's name
- Exit : Close application
- Enemy Ships : Get information about enemy ships: Safe, In Danger, Sunken
- Player Shots : Get information about 5 last shots of player ( coordinates, hit/miss, in case of hit the type of ship)
- Enemy Shots : The same for enemy
The game ends when a player runs out of shots, or when all ships are sunk. Then, all ships are revealed with pink colour.
For bugs please contact me: gianniosgeorgios45@gmail.com
Enjoy Playing !
George Giannios