-
Notifications
You must be signed in to change notification settings - Fork 321
Expand file tree
/
Copy pathgame.hpp
More file actions
101 lines (89 loc) · 2.27 KB
/
game.hpp
File metadata and controls
101 lines (89 loc) · 2.27 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef GAME_H
#define GAME_H
#include "color.hpp"
#include "global.hpp"
#include "scores.hpp"
#include "statistics.hpp"
#include "themes.hpp"
#include <chrono>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <random>
#include <sstream>
#include <string>
#include <vector>
enum Directions { UP, DOWN, RIGHT, LEFT };
class Tile {
public:
Tile() : value(0), blocked(false) {}
ull value;
bool blocked;
Color::Modifier tileColor(ull);
};
class RandInt {
public:
using clock = std::chrono::system_clock;
RandInt() : dist{0, std::numeric_limits<int>::max()} {
seed(clock::now().time_since_epoch().count());
}
RandInt(const int low, const int high) : dist{low, high} {
seed(clock::now().time_since_epoch().count());
}
int operator()() { return dist(re); }
void seed(const unsigned int s) { re.seed(s); }
private:
std::minstd_rand re;
std::uniform_int_distribution<> dist;
};
class Game {
private:
bool moved;
bool win;
bool boardFull;
bool rexit;
ull score;
ull bestScore;
ull largestTile;
long long moveCount;
double duration;
ull gameBoardPlaySize;
std::vector<std::vector<Tile>> board;
RandInt randInt;
bool stateSaved;
bool noSave;
Theme theme;
ThemeController themeController;
enum ContinueStatus { STATUS_END_GAME = 0, STATUS_CONTINUE = 1 };
enum KeyInputErrorStatus { STATUS_INPUT_VALID = 0, STATUS_INPUT_ERROR = 1 };
enum { COMPETITION_GAME_BOARD_PLAY_SIZE = 4 };
void initialiseBoardArray();
void initialiseContinueBoardArray();
bool addTile();
void collectFreeTiles(std::vector<std::vector<int>> &freeTiles);
void drawBoard();
void drawScoreBoard(std::ostream &out_stream);
void input(KeyInputErrorStatus err = STATUS_INPUT_VALID);
bool canMove();
bool testAdd(int, int, ull);
void unblockTiles();
void decideMove(Directions);
void move(int, int, int, int);
void statistics();
void saveStats();
void saveScore();
void saveState();
void playGame(ContinueStatus);
void setBoardSize();
public:
Game()
: win(false), moved(true), boardFull(false), rexit(false), score(0),
bestScore(0), moveCount(-2), largestTile(2), stateSaved(false),
noSave(false) {}
void startGame();
void continueGame();
};
#endif