One of the reasons microcomputers progressed so fast is people are willing to accept crashes. It's faster to build something and try it, even if it means you'll have to rebuild later... If you spent too much time building and massaging one vehicle, you don't learn anything.
John Carmack,
lead programmer of Doom (and more)
In this project your job is to implement the Battleship game for two players. Use newly learned OOP practices.
You will practice the fundamentals of Object-Oriented Programming such as:
- UML diagrams,
- clean code,
- encapsulation,
- abstraction,
- polymorphism,
- inheritance,
- enums
- S and O principles from SOLID,
- packaging in Java,
- getters and setters in Java
-
Gain good understanding of the OOP principles and implement it in your code.
- Program does not use static context.
- Classes are groupped in packages.
- Classes have fields and methods that are related only to them.
- Classes have access modifiers exposing their content as little as possible.
- Classes have getters and setters for private fields only when it is necessary.
- Classes are logically structured and inherit from parents which eliminates the code duplication.
- Classes use public methods to communicate with the outside code, and private methods for eliminating code duplication and better readability.
- Polymorphism is used wherever possible, in order to make the code as universal as possible and avoid code duplication.
-
Implement the
Battleshipclass that will be used as the highest level class.- Class
Battleshiphas fieldsDisplayandInputthat are used throughout the program. - Class
Battleshiphas a loop in which program runs. - Class
Battleshipshows main menu and allows the user to start new game, display highscores and exit.
- Class
-
Implement class
Displayand its methods.- Class
Displayprints the game menu. - Class
Displayprints the board during manual ship placement process. - Class
Displayprints the gameplay. - Class
Displayprints the outcome of the game when it's over. - No
System.out.print()happens outside ofDisplayclass.
- Class
-
Implement class
Inputand its methods.- Class
Inputis responsible for gathering every needed kind of input and provides seperate method for each case. - Class
Inputhandles the input validation.
- Class
-
Implement class
Gameand its methods.- Class
Gamehas a loop in which players make moves. - Class
Gamehas logic which determines the flow of round. - Class
Gamehas condition on which game ends. - Class
Gameprovides different game modes which use different round flow.
- Class
-
Implement class
Playerand its methods.- Class
Playerhas logic responsible for handling shot. - Class
Playerhas field of typeList<Ship>. - Class
Playerhas a methodisAliveto check if player has not lost all ships and returns true or false accordingly.
- Class
-
[OPTIONAL] Implement
ComputerPlayerclass and it's methods.- Class
ComputerPlayerEasytakes random shots excluding already struck fields. - Class
ComputerPlayerNormalalso excludes fields around ships when taking random hits. - Class
ComputerPlayerNormalshoots around a ship after hitting it to determine its direction. - Class
ComputerPlayerNormalchanges direction to opposite when can not go further. - Class
ComputerPlayerNormalfollows the direction until the ship is sunk. - Class
ComputerPlayerHardusesComputerPlayerNormallogic but shoots diagonal fields only.
- Class
-
Implement class
BoardFactoryand it's methods.- Class
BoardFactoryhas arandomPlacement()method that handles random ship placement on board. - Class
BoardFactoryhas amanualPlacement()method that handles manual ship placement on board.
- Class
-
Implement class
Boardand it's methods.- Class
Boardhas fieldSquare[][] ocean- squares the board consists of. - Class
Boardhas anisPlacementOk()method that verifies if placement of ship is possible.
- Class
-
Implement class
Shipand it's methods.- Class
Shiphas field ofList<Square>- all squares the ship consists of.
- Class
-
Implement enum
ShipTypeand it's methods.- Enum
ShipTyperepresents ship types - Carrier, Cruiser, Battleship, Submarine and Destroyer. - Each
ShipTypehas a unique length.
- Enum
-
Implement class
Squareand its methods.- Class
Squarehas fieldsXandY. - Class
Squarehas a fieldSquareStatus. - Class
Squarehas method that returns givenSquareStatus's graphical representation.
- Class
-
Implement enum
SquareStatus.- Enum
SquareStatusrepresents possible square statuses (empty, ship, hit, missed). - Each
SquareStatushas a unicode character that can be used to print it out. This unicode character is returned by aSquareStatus.GetCharacter()method.
- Enum
None
- There is no skeleton code for this project (on purpose), just an empty file. Try to create it from scratch.
- Focus on features first, and refactor it at the end.