13. Software design patterns
Review the presentation Software Design Articles
Tasks
- Review the package jtm.activity13
- Implement the necessary classes and methods for the Crocodile Game.
CrocodileGame contains a 2D board with cells and a list of crocodiles.
See the system design in the package file CrocodileGame.png.
Task 1
- Implement the Crocodile interface with two different classes CrocodileSimple and CrocodileGreedy
- CrocodileSimple MoveStrategy must be implemented in the MoveSimple class
- CrocodileGreedy MoveStrategy must be implemented in the MoveGreedy class
- If necessary, add additional methods (e.g. setters) to the CrocodileSimple and CrocodileGreedy classes.
Crocodiles are placed in the upper left corner of the field if there is only one cell on the board,
no crocodiles need to move at all, but they can eat candies if there are any.
The MoveSimple strategy only covers the first row and last column of the board. e.g.
↓
↓
MoveGreedy strategy covers all the cells of the board and the crocodile eats all the candies.
The movement always starts and ends on the X axis, e.g.
⇽⇽⇽
⇾⇾⇾
If the board has an even number of rows, the greedy crocodile goes through the last row twice:
⇽⇽⇾⇾
⇆⇆⇆
The game board has the following valid cell values:
○ — empty cell
● — cell with candy
◎ — cell with a crocodile's footprint
when the crocodile gets to a cell with candy ●, it eats this candy
When the crocodile leaves a cell, it leaves footprints in the cell ◎
Task 2
CrocodileGame is created using the factory class GameFactory, which has
setBoard(Board board) and addCrocodile(String crocodileType) methods.Implement setBoard(Board Board) and addCrocodile(String crocodileType) methods
to create a CrocodileGame with lazy initialization.