rts_game_backend/src/game/unit/unit.hpp

96 lines
2.1 KiB
C++
Raw Normal View History

2021-03-22 19:37:34 +03:00
#include <vector>
2021-03-24 20:31:44 +03:00
#include "../game_map.hpp"
2021-04-12 01:51:12 +03:00
#include "../game_events.hpp"
2021-03-22 19:37:34 +03:00
#include "unit_module.hpp"
2021-04-12 01:51:12 +03:00
#include "../map_entities/unit_obj.hpp"
2021-03-22 19:37:34 +03:00
2021-03-24 20:31:44 +03:00
#pragma once
2021-03-22 19:37:34 +03:00
namespace unit {
2021-05-18 17:43:03 +03:00
class UnitFactory;
2021-03-22 19:37:34 +03:00
class Unit {
private:
2021-05-18 17:43:03 +03:00
friend class UnitFactory;
2021-04-12 01:51:12 +03:00
2021-05-18 17:43:03 +03:00
int basicStrength;
int strength;
int shield;
int speed;
int player;
int cellType;
2021-04-12 01:51:12 +03:00
map::UnitObj unitObj;
2021-04-11 12:45:39 +03:00
2021-05-18 17:43:03 +03:00
map::GameMap* gameMap = nullptr;
2021-04-12 01:51:12 +03:00
2021-05-18 17:43:03 +03:00
events::EventCenter* eventCenter = nullptr;
void setCellType(int newCellType) {
cellType = newCellType;
unitObj.setCellType(cellType);
}
2021-03-22 19:37:34 +03:00
public:
2021-05-18 17:43:03 +03:00
Unit() = default;
Unit(map::GameMap* gameMap, events::EventCenter* eventCenter);
2021-04-12 01:51:12 +03:00
void step();
2021-05-18 17:43:03 +03:00
void damage(int damage, int power);
bool isDestroyed() {
return strength <= 0;
}
void setPlayer(int newPlayer) {
player = newPlayer;
unitObj.setPlayer(player);
}
};
class UnitFactory {
private:
Unit unit;
public:
UnitFactory() = default;
UnitFactory& setBasicStrength(int basicStrength) {
unit.basicStrength = basicStrength;
unit.strength = basicStrength;
return *this;
}
UnitFactory& setShield(int shield) {
unit.shield = shield;
return *this;
}
UnitFactory& setSpeed(int speed) {
unit.speed = speed;
return *this;
}
UnitFactory& setCellType(int cellType) {
unit.setCellType(cellType);
return *this;
}
UnitFactory& setEventCenter(events::EventCenter* eventCenter) {
unit.eventCenter = eventCenter;
return *this;
}
2021-04-12 01:51:12 +03:00
2021-05-18 17:43:03 +03:00
UnitFactory& setGameMap(map::GameMap* gameMap) {
unit.gameMap = gameMap;
return *this;
}
2021-03-24 20:31:44 +03:00
2021-05-18 17:43:03 +03:00
Unit build(int player) {
Unit cp = unit;
cp.setPlayer(player);
return cp;
}
2021-03-22 19:37:34 +03:00
};
2021-04-11 12:45:39 +03:00
}