-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.h
55 lines (45 loc) · 954 Bytes
/
Grid.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
#ifndef SNAKEGAME_GRID_H
#define SNAKEGAME_GRID_H
#include <iostream>
#include <thread>
#include <chrono>
#include <vector>
#include <mutex>
#include <cstdio>
#include "Consts.h"
enum class CellType {
Empty,
Snake1,
Snake2,
Fruit,
Head1,
Head2
};
struct Cell {
CellType cellType;
int x;
int y;
};
class Grid {
private:
std::vector <std::vector<Cell>> cells;
int width;
int height;
std::mutex &mutex;
std::string final_text;
bool gameOver;
public:
Grid(int width, int height, std::mutex &mutex);
~Grid();
Cell& operator()(int x, int y);
const Cell& operator()(int x, int y) const;
void clear();
std::string draw();
int getWidth() const;
int getHeight() const;
const std::string &getFinalText() const;
void setFinalText(const std::string &finalText);
bool isGameOver() const;
void setGameOver(bool gameOver);
};
#endif //SNAKEGAME_GRID_H