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

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