-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakeMap.h
73 lines (65 loc) · 1.37 KB
/
SnakeMap.h
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
72
73
#ifndef __SNAKE_MAP__
#define __SNAKE_MAP__
#include <ncurses.h>
class Point
{
public:
Point(): row(0), col(0) {}
Point(int row, int col): row(row), col(col) {}
Point(const Point& p) {
row = p.row;
col = p.col;
}
virtual ~Point() {}
Point &operator =(const Point p) {
row = p.row;
col = p.col;
return *this;
}
bool operator ==(const Point p) const {
return row == p.row && col == p.col;
}
bool operator !=(const Point p) {
return !(*this == p);
}
int row;
int col;
};
class Item: public Point
{
public:
int lifespan;
Item(int i, Point p): lifespan(i), Point::Point(p) {}
Item(const Item& item): Point::Point(item.row, item.col) {
lifespan = item.lifespan;
}
Item(): lifespan(0) {}
Item &operator =(const Point p) {
Point::operator=(p);
return *this;
}
bool operator ==(const Point p) {
return Point::operator==(p);
}
bool operator !=(const Point p) {
return !(*this == p);
}
};
class SnakeMap
{
public:
SnakeMap(int row, int col, WINDOW *scr);
~SnakeMap();
void gameEnding();
void eraseAll();
void makeEdge();
void draw();
int &operator [](Point p) {
return mat[p.row][p.col];
}
int **mat;
const int row;
const int col;
WINDOW *mainWindow;
};
#endif