-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackend.hpp
160 lines (94 loc) · 3.1 KB
/
backend.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef BACKEND_HPP
#define BACKEND_HPP
#include <include/GameManager.hpp>
#include <vector>
#include <QDebug>
#include <QObject>
#include <QPair>
#include <QString>
#include <QtQuick>
class BackEnd : public QObject
{
Q_OBJECT
private:
//ChessBoard
int previewsSrc = -1; //for showing movements
int srcIndex = -1;
int destIndex = -1;
bool _change = false;
bool _extraMove = false;
bool _touchedPiece = false;
bool _moved = false;
std::vector<std::string> _dirFiles;
std::vector<std::string> _filePlayersName;
short unsigned _canceler = 2;
void touchedPiece(GameManager::Turn);
std::unique_ptr<GameManager> manager = std::unique_ptr<GameManager>(GameManager::get("game"));
public:
std::pair<std::vector<Chessman::Index>, std::vector<Chessman::Index>> srcState;
enum SrcCellState { EMPTY, UNACCESSABLE, OK };
enum DestCellState { UNAVAILABLE, CANGO, CANHIT, SELECTED };
public slots:
//________________________________________________________ game
void setGame(QString gameName);
void startGame();
void restartGame();
void saveAndExit();
void endGame();
bool checkInput(QString name);
unsigned gameStatus();
//--------------------------------------------------------- files
void getFiles(); //load txt files from "SavedGames" folder
QString getFileInfo(unsigned index);
void loadGame(unsigned index);
unsigned filesCount();
void deleteFile(unsigned index);
//________________________________________________________ users
void setP1(QString P1Name);
void setP2(QString P2Name);
QString getP1Name();
QString getP2Name();
int getP1_PScore();
int getP1_NScore();
int getP2_PScore();
int getP2_NScore();
QString getGameName();
unsigned winner();
void checkRandomMove();
void setCanceler();
unsigned getCanceler();
//________________________________________________________ board
QString getIcon(unsigned index);
unsigned cellState(unsigned index);
bool isMoved(unsigned index);
unsigned getSrcI();
unsigned getSrcJ();
unsigned getDestI();
unsigned getDestJ();
unsigned getSrcIndex();
unsigned getDestIndex();
// QString getHitPiece();
//__________________________________________________________ movement
bool canHit(unsigned index, std::vector<std::pair<unsigned int, unsigned int>> bkndcanGo);
bool canGo(unsigned index, std::vector<std::pair<unsigned int, unsigned int>> bkndcanGo);
unsigned choose(unsigned index);
bool unchoosePiece(unsigned index);
QString getP1OutsIcon(unsigned index);
QString getP2OutsIcon(unsigned index);
bool move(unsigned index) noexcept;
void undo();
bool extraMove();
void randomMove();
void promote(unsigned type);
signals:
void choosen();
void moved();
void unchoosen();
void promotion();
void cancel();
void fileError();
void gameLoaded();
};
std::pair<unsigned, unsigned> indexToIJ(unsigned index);
unsigned IJToIndex(std::pair<unsigned int, unsigned int>);
#endif // BACKEND_HPP