If it is not explicitly told in following recipe, setting up services are described for Ubuntu 20.04 server, but applications are described for Xubuntu 20.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

13. Software design patterns

Review the presentation Software Design Articles

Tasks

  1. Review the package jtm.activity13
  2. Implement the necessary classes and methods for the Crocodile Game.
  3. CrocodileGame contains a 2D board with cells and a list of crocodiles.
    See the system design in the package file CrocodileGame.png.

The game board has already been implemented, and its design does not need to be changed!

Task 1

  1. Implement the Crocodile interface with two different classes CrocodileSimple and CrocodileGreedy
    1. CrocodileSimple MoveStrategy must be implemented in the MoveSimple class
    2. CrocodileGreedy MoveStrategy must be implemented in the MoveGreedy class
  2. 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

  1. CrocodileGame is created using the factory class GameFactory, which has
    setBoard(Board board) and addCrocodile(String crocodileType) methods.

  2. Implement setBoard(Board Board) and addCrocodile(String crocodileType) methods
    to create a CrocodileGame with lazy initialization.

More information


  

Created by Valdis Vītoliņš on 2025-01-28 17:41
Last modified by Valdis Vītoliņš on 2025-01-28 17:41
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License