mirror of
https://github.com/ProgramSnail/rts_game_backend.git
synced 2025-12-07 02:08:43 +00:00
added elements in unit, map, game
This commit is contained in:
parent
220dd71d8f
commit
733bcbd99d
10 changed files with 116 additions and 16 deletions
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,5 @@
|
|||
#include "game.hpp"
|
||||
#include "game_map.hpp"
|
||||
|
||||
Game::Game(size_t playersNum, std::pair<size_t, size_t> sz) :
|
||||
playersNum(playersNum), gameMap(sz) {}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#include <vector>
|
||||
#include "game_events.hpp"
|
||||
#include "game_map.hpp"
|
||||
#include "unit/unit.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
class Game {
|
||||
private:
|
||||
size_t playersNum;
|
||||
map::GameMap gameMap;
|
||||
std::vector<unit::Unit> units;
|
||||
events::EventCenter eventCenter;
|
||||
// vector<player data>
|
||||
// vector<input> // for players
|
||||
public:
|
||||
// may be more than one map sizes ??
|
||||
Game(size_t playersNum, std::pair<size_t, size_t> sz);
|
||||
};
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#include "game_map.hpp"
|
||||
|
||||
namespace map {
|
||||
GameMap::GameMap(std::pair<size_t, size_t> sz) :
|
||||
cells(sz.first, std::vector<Cell>(sz.second)) {}
|
||||
|
||||
size_t GameMap::addAction(const Action& action) {
|
||||
if (freeActionsId.size() == 0) {
|
||||
actions.push_back(action);
|
||||
return actions.size() - 1;
|
||||
}
|
||||
else {
|
||||
size_t id = freeActionsId.back();
|
||||
actions[id] = action;
|
||||
actions.pop_back();
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
void GameMap::removeAction(size_t id) {
|
||||
actions[id] = Action(); // empty action;
|
||||
freeActionsId.push_back(id);
|
||||
}
|
||||
|
||||
const Cell& GameMap::getCell(std::pair<size_t, size_t> pos) {
|
||||
return cells[pos.first][pos.second];
|
||||
}
|
||||
|
||||
void GameMap::setCell(std::pair<size_t, size_t> pos,
|
||||
const Cell& cell) {
|
||||
cells[pos.first][pos.second] = cell;
|
||||
}
|
||||
|
||||
std::vector<std::pair<size_t, size_t>> GameMap::getWay(
|
||||
std::pair<size_t, size_t> start,
|
||||
std::pair<size_t, size_t> end) {
|
||||
// now only easiest realisation, then may be A*
|
||||
std::vector<std::pair<size_t, size_t>> way;
|
||||
for (size_t i = start.first; i < end.first;
|
||||
start.first < end.first ? ++i : --i) {
|
||||
for (size_t j = start.second; i < end.second;
|
||||
start.second < end.second ? ++i : --i) {
|
||||
way.push_back({i, j});
|
||||
}
|
||||
}
|
||||
return way;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
#include <vector>
|
||||
#include "map_entities/cell.hpp"
|
||||
#include "map_entities/action.hpp"
|
||||
#include "map_entities/unit_obj.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -9,11 +8,23 @@ namespace map {
|
|||
class GameMap {
|
||||
private:
|
||||
std::vector<std::vector<Cell> > cells;
|
||||
std::vector<Action*> actions;
|
||||
std::vector<UnitObj> units;
|
||||
std::vector<Action> actions;
|
||||
std::vector<size_t> freeActionsId;
|
||||
public:
|
||||
GameMap() {
|
||||
GameMap(std::pair<size_t, size_t> sz);
|
||||
|
||||
size_t addAction(const Action& action);
|
||||
|
||||
void removeAction(size_t id);
|
||||
|
||||
const Cell& getCell(std::pair<size_t, size_t> pos);
|
||||
|
||||
void setCell(std::pair<size_t, size_t> pos,
|
||||
const Cell& cell);
|
||||
|
||||
std::vector<std::pair<size_t, size_t>> getWay(
|
||||
std::pair<size_t, size_t> start,
|
||||
std::pair<size_t, size_t> end);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
namespace map {
|
||||
enum class CellType { // needed to choose final types
|
||||
enum class CellType {
|
||||
ctNone,
|
||||
ctUnit,
|
||||
ctWeapon,
|
||||
|
|
@ -18,7 +18,7 @@ namespace map {
|
|||
};
|
||||
|
||||
struct Cell {
|
||||
CellType type;
|
||||
// int ??speed??; // speed when move inside
|
||||
CellType type = CellType::ctNone;
|
||||
CellPlayer player = CellPlayer::cpNone;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <utility>
|
||||
#include <cstdint>
|
||||
#include "cell.hpp"
|
||||
#include "../game_map.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -12,10 +13,10 @@ namespace map {
|
|||
Coord size;
|
||||
CellType cellType;
|
||||
public:
|
||||
UnitObj(const Coord& pos, const Coord& size, const CellType& cellType) :
|
||||
pos(pos), size(size), cellType(cellType) {
|
||||
|
||||
}
|
||||
UnitObj() {}
|
||||
UnitObj(const Coord& pos, const Coord& size,
|
||||
const CellType& cellType, map::GameMap* map) :
|
||||
pos(pos), size(size), cellType(cellType) {}
|
||||
void updateAll() {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "unit.hpp"
|
||||
|
||||
namespace unit {
|
||||
Unit::Unit(map::GameMap* map, events::EventCenter* events) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +1,36 @@
|
|||
#include <vector>
|
||||
#include "../game_map.hpp"
|
||||
#include "../game_events.hpp"
|
||||
#include "unit_module.hpp"
|
||||
#include "../map_entities/unit_obj.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace unit {
|
||||
class Unit {
|
||||
private:
|
||||
const size_t MEMORY_SIZE = 100;
|
||||
|
||||
// parts of unit, that do something
|
||||
std::vector<Module> modules;
|
||||
|
||||
// memory, help modules communicate and handle events
|
||||
std::vector<int> memory;
|
||||
|
||||
map::GameMap* map;
|
||||
public:
|
||||
Unit();
|
||||
map::UnitObj unitObj;
|
||||
|
||||
void update();
|
||||
map::GameMap* map;
|
||||
|
||||
events::EventCenter* eventCenter;
|
||||
public:
|
||||
Unit(map::GameMap* map, events::EventCenter* eventCenter);
|
||||
|
||||
void step();
|
||||
|
||||
size_t addModule(Module module);
|
||||
|
||||
void removeModule(size_t id);
|
||||
|
||||
void damage();
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue