| .. | ||
| src | ||
| tests | ||
| CMakeLists.txt | ||
| main.cpp | ||
| README.md | ||
Linux compilation
> mkdir build
> cd build
> cmake -DCMAKE_BUILD_TYPE=Debug ..
> make
Exercise 1
- Go into directory Player and implement a base class
Player, this class should have 3 public virtual members:virtual int attack(Ship& playerShip) = 0;virtual Ship& getShip() = 0;virtual const Ship& getShip() const = 0;
- Add to
Playerclass a non-virtual function:Action::Status makeAction(const BattleField& battleField);. - Add to
Playerclass 2 virtual protected function (a template method):virtual Ship* chooseEnemyShip(const BattleField& battleField) const = 0;virtual std::unique_ptr<Action> chooseAction(const BattleField& battleField) const = 0;
- Implement some logic in method
makeActionbased on 2 template method:- To simplify, Player can only attack or defense
- Use class Command from directory
Battle
Exercise 2
- Implement class
RealUserwhich will inherit from classPlayer. Implement both template methods:- Don't make it too complex, just ask user about action and type of ammunition, then you can randomly choose a damage or if missed.
- To increase defense, you can use method
setArmorfromShipclass.
- Rewrite class
Enemyto inherit fromPlayeradd also implementation for both template methods - Uncomment code in main, check if you can perform a real battle!
Exercise 3
- Go into directory
Battleand implement classEscapewhich will inherit from classAction.- Roll a die (1 to 20), if value is bigger than
12a player successfully escaped.
- Roll a die (1 to 20), if value is bigger than
- Noticed that we shouldn't modify existing code, but we need to do this in two place, where?
- How would you refactor the code?