blob: 5781f540deb370742b7ea4499dc92a1c04e0697d (
plain)
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
|
#include "Game.hpp"
//==================== Constructor and Destructor ====================
//Constructor
Game::Game() : Grid(), m_stats(){
}
//Destructor
Game::~Game(){
}
//==================== Helpers ====================
//Swipe action
bool Game::swipe(kbdh::Direction direction){
bool moveDone;
switch(direction){
case kbdh::Left:
moveDone=swipeLeft();
break;
case kbdh::Right:
moveDone=swipeRight();
break;
case kbdh::Up:
moveDone=swipeUp();
break;
case kbdh::Down:
moveDone=swipeDown();
break;
}
if(moveDone){
m_stats.incScore(m_lastMoveScore);
m_stats.incnbMove();
this->popRandomNumber();
}
return moveDone;
}
//Cout the grid
void Game::coutGrid(){
std::cout << this->description();
}
//Return true if the game is lost. False else.
//bool Game::isOver(){
//return m_grid.isOver();
//}
//Pop a random number on the grid
void Game::popRandomNumber(){
std::tuple<int, int> coord(Grid::getRandomEmptyCellCoord());
int percent=rand() % 100;
int number;
if(percent <= 10){
number=4;
}
else{
number=2;
}
Grid::setCell(coord, number);
}
//==================== Getters and Setter ====================
//Retrieve the Score
Stats Game::getStats(){
return m_stats;
}
//std::vector<std::vector<int> > Game::getGrid(){
//return m_grid.getGrid();
//}
//int Game::maxStrLenInGrid(){
//return m_grid.maxStrLenInGrid();
//}
|