35 lines
No EOL
1.7 KiB
Markdown
35 lines
No EOL
1.7 KiB
Markdown
## 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 `Player` class a non-virtual function: `Action::Status makeAction(const BattleField& battleField);`.
|
|
* Add to `Player` class 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 `makeAction` based on 2 template method:
|
|
* To simplify, Player can only attack or defense
|
|
* Use class Command from directory `Battle`
|
|
|
|
## Exercise 2
|
|
|
|
* Implement class `RealUser` which will inherit from class `Player`. 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 `setArmor` from `Ship` class.
|
|
* Rewrite class `Enemy` to inherit from `Player` add also implementation for both template methods
|
|
* Uncomment code in main, check if you can perform a real battle!
|
|
|
|
## Exercise 3
|
|
|
|
* Go into directory `Battle` and implement class `Escape` which will inherit from class `Action`.
|
|
* Roll a die (1 to 20), if value is bigger than `12` a player successfully escaped.
|
|
* Noticed that we shouldn't modify existing code, but we need to do this in two place, where?
|
|
* How would you refactor the code? |