/
Board.hpp
71 lines (56 loc) · 1.65 KB
/
Board.hpp
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
//
// Board.hpp
// Reversi
//
// Created by YU CHAO on 2015/11/19.
// Copyright © 2015年 Darkness Left. All rights reserved.
//
#ifndef Board_hpp
#define Board_hpp
#include <SFML/Graphics.hpp>
#include <vector>
#include <map>
#include "Chess.hpp"
class Board : public sf::Drawable
{
public:
static const int SIZE = 8;
//Loop of Board
Board();
void recordPossibleMoves();
void clickBoard(float mouseX, float mouseY);
void hoverBoard(float mouseX, float mouseY);
bool cannotMove() const {return noPossibleMoves;};
~Board();
//getters
Chess::ChessColor getTurn() const {return this->turn;};
int getBlackScore() const {return this->blackScore;};
int getWhiteScore() const {return this->whiteScore;};
bool getNoPossibleMovesForBoth() const {return this->noPossibleMovesForBoth;};
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
//struct of slot
struct Slot
{
Chess* chess;
int side;
sf::RectangleShape gridRect;
//records possible moves of this slot. Map: {(x,y) directions -> length}
std::map<std::pair<int, int>, int> moves;
};
void nextTurn();
void countScore();
void checkPossibleMove(int i, int j, std::pair<int, int> dir);
//records current turn
Chess::ChessColor turn;
bool noPossibleMoves = false;
bool noPossibleMovesForBoth = false;
//score
int whiteScore = 2;
int blackScore = 2;
//hover chess
Chess* hoverChess;
//board in 2d vector
std::vector<std::vector<Slot>> matrix;
};
#endif /* Board_hpp */