修bug,允许重玩

This commit is contained in:
unlockable
2023-02-23 15:18:42 +08:00
parent 8255bee6a9
commit 200e21c1e9

View File

@@ -54,16 +54,13 @@ public:
} }
std::string show() { std::string show() {
if (this->isWinStatus) {
return "X";
}
if (this->color == BLACK) { if (this->color == BLACK) {
if (this->isWinStatus) {
return "X";
}
return ""; return "";
} }
else { else {
if (this->isWinStatus) {
return "X";
}
return ""; return "";
} }
} }
@@ -181,7 +178,7 @@ public:
} }
if (connetCount >= 5) { if (connetCount >= 5) {
for (; connetCount >= 0; connetCount--) { for (connetCount--; connetCount >= 0; connetCount--) {
this->ChessPieces[possiblePieces[connetCount][0]] this->ChessPieces[possiblePieces[connetCount][0]]
[possiblePieces[connetCount][1]] [possiblePieces[connetCount][1]]
.setWin(); .setWin();
@@ -221,7 +218,7 @@ public:
} }
if (connetCount >= 5) { if (connetCount >= 5) {
for (; connetCount >= 0; connetCount--) { for (connetCount--; connetCount >= 0; connetCount--) {
this->ChessPieces[possiblePieces[connetCount][0]] this->ChessPieces[possiblePieces[connetCount][0]]
[possiblePieces[connetCount][1]] [possiblePieces[connetCount][1]]
.setWin(); .setWin();
@@ -267,7 +264,7 @@ public:
} }
if (connetCount >= 5) { if (connetCount >= 5) {
for (; connetCount >= 0; connetCount--) { for (connetCount--; connetCount >= 0; connetCount--) {
this->ChessPieces[possiblePieces[connetCount][0]] this->ChessPieces[possiblePieces[connetCount][0]]
[possiblePieces[connetCount][1]] [possiblePieces[connetCount][1]]
.setWin(); .setWin();
@@ -313,7 +310,7 @@ public:
} }
if (connetCount >= 5) { if (connetCount >= 5) {
for (; connetCount >= 0; connetCount--) { for (connetCount--; connetCount >= 0; connetCount--) {
this->ChessPieces[possiblePieces[connetCount][0]] this->ChessPieces[possiblePieces[connetCount][0]]
[possiblePieces[connetCount][1]] [possiblePieces[connetCount][1]]
.setWin(); .setWin();
@@ -369,7 +366,9 @@ public:
return failed; return failed;
} }
if (this->board->checkWinner(rowCount, columnCount, this->chessType)) { if (this->board->checkWinner(rowCount, columnCount, this->chessType)) {
std::cout << this->playerName << " wins!" << std::endl; std::cout << "\n####################\n"
<< this->playerName << " wins!" << std::endl
<< "####################\n";
return win; return win;
} }
if (this->board->isFull()) { if (this->board->isFull()) {
@@ -411,7 +410,8 @@ int main() {
std::cout << "Row No. "; std::cout << "Row No. ";
std::cin >> row; std::cin >> row;
fflush(stdin); fflush(stdin);
while (!(('1' <= row && row <= '9') || ('A' <= row && row <= 'F') || ('a' <= row && row <= 'f'))) { while (!(('1' <= row && row <= '9') || ('A' <= row && row <= 'F') ||
('a' <= row && row <= 'f'))) {
std::cout << "Not a valid row number. Try again." << std::endl; std::cout << "Not a valid row number. Try again." << std::endl;
std::cout << "Row No. "; std::cout << "Row No. ";
std::cin >> row; std::cin >> row;
@@ -421,7 +421,8 @@ int main() {
std::cout << "Column No. "; std::cout << "Column No. ";
std::cin >> column; std::cin >> column;
fflush(stdin); fflush(stdin);
while (!(('1' <= row && row <= '9') || ('A' <= row) && (row <= 'F') || ('a' <= row && row <= 'f'))) { while (!(('1' <= row && row <= '9') || ('A' <= row) && (row <= 'F') ||
('a' <= row && row <= 'f'))) {
std::cout << "Not a valid column number. Try again." << std::endl; std::cout << "Not a valid column number. Try again." << std::endl;
std::cout << "Column No. "; std::cout << "Column No. ";
std::cin >> column; std::cin >> column;
@@ -438,7 +439,22 @@ int main() {
} }
else { else {
aBoard.show(); aBoard.show();
break; char input;
do {
std::cout << "Reset for another round? (y/n) ";
input = getchar();
fflush(stdin);
} while (input != 'y' && input != 'Y' && input != 'n' &&
input != 'N');
if (input == 'y' || input == 'Y') {
aBoard.reset();
aBoard.show();
continue;
}
else {
break;
}
} }
} while (true); } while (true);
return 0; return 0;