-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cc
More file actions
71 lines (62 loc) · 1.87 KB
/
game.cc
File metadata and controls
71 lines (62 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <cstddef>
#include <ncurses.h>
#include <memory>
#include "game.h"
#include "gameObject.h"
#include "character.h"
#include "rectangle.h"
#include "bitmap.h"
#include "gameDisplay.h"
#include "borderDisplay.h"
#include "border.h"
#include "statusDisplay.h"
#include <ncurses.h>
#include <iostream>
using namespace std;
Game::Game() {}
Game::~Game() {}
void Game::position() {}
void Game::go() {}
void Game::addGameObject(shared_ptr<GameObject> obj) {
objects.push_back(obj);
}
void Game::removeGameObject(shared_ptr<GameObject> obj) {
for (int i = 0; i < objects.size(); i++) {
if (obj == objects[i]) {
objects.erase(objects.begin() + i);
}
}
}
vector<shared_ptr<GameObject>> Game::getObjects() {
return objects;
}
bool Game::isEmpty(int x, int y) {
shared_ptr<Border> border = make_shared<Border>();
if(border->onBorder(y, x)) {
return false;
}
for (int i = 0; i < objects.size(); i++) {
if (dynamic_cast<Character *>(objects[i].get())) {
if (objects[i]->getYPos() == y && objects[i]->getXPos() == x) {
return false;
}
}
else if (dynamic_cast<Rectangle *>(objects[i].get())) {
Rectangle rect = static_cast<Rectangle &>(*objects[i]);
if (rect.getXPos() <= x && x < rect.getXPos() + rect.getLength()
&& rect.getYPos() <= y && y < rect.getYPos() + rect.getWidth()) {
return false;
}
}
else if (dynamic_cast<Bitmap *>(objects[i].get())) {
Bitmap bits = static_cast<Bitmap &>(*objects[i]);
vector<tuple<int, int, char>> map = bits.getMap();
for (int j = 0; j < map.size(); j++) {
if (get<0>(map[j]) == x && get<1>(map[j]) == y) {
return false;
}
}
}
}
return true;
}