拆分多个文件。

This commit is contained in:
unlockable
2023-03-01 17:06:16 +08:00
parent b86ed536c4
commit 6070fbfd57
5 changed files with 439 additions and 395 deletions

55
OOP/FiveInARow/player.cpp Normal file
View File

@@ -0,0 +1,55 @@
#include "fiveInARow.h"
int Player::toInt(char input) {
if ('1' <= input && input <= '9') {
return input - '1';
}
else if ('A' <= input && input <= 'F') {
return input - 'A' + 9;
}
else if ('a' <= input && input <= 'f') {
return input - 'a' + 9;
}
else {
return -1;
}
}
Player::Player(std::string name, bool type, ChessBoard *chessBoard) {
this->playerName = name;
this->chessType = type;
this->board = chessBoard;
}
Player::~Player() {
}
std::string Player::getName() {
return this->playerName;
}
bool Player::getColor() {
return this->chessType;
}
putChessPieceResult Player::setChess(char row, char column) {
int rowCount, columnCount;
rowCount = toInt(row);
columnCount = toInt(column);
if (!this->board->setChess(chessType, rowCount, columnCount)) {
return failed;
}
if (this->board->checkWinner(rowCount, columnCount, this->chessType)) {
std::cout << "\n####################\n"
<< this->playerName << " wins!" << std::endl
<< "####################\n";
return win;
}
if (this->board->isFull()) {
std::cout << "Board is full. Tie!" << std::endl;
return fullBoard;
}
else {
return success;
}
}