-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.h
54 lines (45 loc) · 1.76 KB
/
board.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
#ifndef BOARD_H
#define BOARD_H
#include "tile.h"
#include <QVector>
#include <QString>
#include <QDebug>
using namespace std;
class Tile;
enum Direction {UP, DOWN, LEFT, RIGHT};
class Board
{
public:
Board(int rowCount, int colCount, double valueThr = 0.3);
Board(const Board& otherBoard);
~Board();
// Public methods accessed by Game class
void resetBoard(); // Reset board to beginning game state
int getRowCount() {return rows;}
int getColCount() {return cols;}
Tile* getTile(int row, int col);
QString getTileValue(int tileIndex); // Return tile value by index, under form of a QString
int getTileValueForColor(int tileIndex);
void move(Direction dir); // Perform move in given direction
bool isFull() const; // Check if the board is full
int getPointsScoredLastMove() const {return pointsScoredLastMove;}
bool getTileCollisionLastMove() const {return tileCollisionLastMove;}
bool canMove() const;
private:
int rows;
int cols;
double valueThr; // Probability of spawning a 4 instead of a 2
QVector<QVector<Tile*>> tileBoard;
int pointsScoredLastMove;
bool tileCollisionLastMove;
// Private internal methods that change board state
void initRandomTile();
void initBoard(); // Create empty board
bool onBoard(int row, int col); // Checks if given coordinates are within the board's limits
void moveVertically(int row, int col, Direction dir);
void moveHorizontally(int row, int col, Direction dir);
void handleCollision(int collRow, int collCol); // Handle collision of two tiles
bool changedState(Board& otherBoard) const; // Check if board is different from the argument board
void endCurrentMove(); // Reset some parameters before the next move
};
#endif // BOARD_H