由棋子自身负责自身形象。

This commit is contained in:
unlockable
2023-02-22 22:26:29 +08:00
parent 60c67610b3
commit 5af9ee4316

View File

@@ -27,10 +27,13 @@ class ChessPiece {
private:
bool color;
bool isEmptyStatus;
bool isWinStatus;
public:
void init() {
this->isEmptyStatus = true;
this->isWinStatus = false;
this->color = BLACK;
}
void setColor(bool newColor) {
@@ -38,6 +41,10 @@ public:
this->color = newColor;
}
void setWin() {
this->isWinStatus = true;
}
bool isEmpty() {
return this->isEmptyStatus;
}
@@ -45,12 +52,29 @@ public:
bool getColor() {
return this->color;
}
std::string show() {
if (this->color == BLACK) {
if (this->isWinStatus) {
return "";
}
return "";
}
else {
if (this->isWinStatus) {
return "";
}
return "";
}
}
};
class ChessBoard {
private:
ChessPiece ChessPieces[15][15];
int chessCount;
char toHex(int num) {
if (num < 10) {
return num + '0';
@@ -67,6 +91,7 @@ public:
this->ChessPieces[i][j].init();
}
}
this->chessCount = 0;
}
void show() {
@@ -89,12 +114,7 @@ public:
std::cout << (*emptyLineRef)[j * 2];
}
else {
if (this->ChessPieces[i][j].getColor() == BLACK) {
std::cout << "";
}
else {
std::cout << "";
}
std::cout << this->ChessPieces[i][j].show();
}
if (j < 14) {
std::cout << (*emptyLineRef)[j * 2 + 1];
@@ -115,6 +135,7 @@ public:
return false;
}
this->ChessPieces[row][column].setColor(color);
this->chessCount++;
return true;
}