为了账号安全,请及时绑定邮箱和手机立即绑定

作业社区

探索学习新天地,共享知识资源!

0 提交作业
0 布置作业
0 满分作业
得分 100
学习任务

别摸我的键盘 的学生作业:

Judge #ifndef __JUDGE_H_ #define __JUDGE_H_ #include #include "Player.hpp" #include "ChessBoard.hpp" using namespace std; class Judge { public: bool isWin(Player *player) { bool ok = false; if (player == nullptr) { return ok; } string color = player->getColor(); ok = isWinHorizontal(color); if (ok) { return true; } ok = isWinVertical(color); if (ok) { return true; } ok = isWinUpHill(color); if (ok) { return true; } ok = isWinDownHill(color); if (ok) { return true; } return ok; } bool isWinHorizontal(const string &color) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); int col = chessBoard->getCurrentCol(); int line = chessBoard->getCurrentLine(); bool ok = false; int count = 0; //left for (int i = 0; i < 5; i++) { ok = chessBoard->isSameChess(color, line, col + i); if (ok) { count++; } else { break; } } if (count >= 5) { return true; } count = 0; for (int i = 0; i < 5; i++) { ok = chessBoard->isSameChess(color, line, col - i); if (ok) { count++; } else { break; } } if (count >= 5) { return true; } else { return false; } } bool isWinVertical(const string &color) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); int col = chessBoard->getCurrentCol(); int line = chessBoard->getCurrentLine(); bool ok = false; int count = 0; //up for (int i = 0; i < 5; i++) { ok = chessBoard->isSameChess(color, line - i, col); if (ok) { count++; } else { break; } } if (count >= 5) { return true; } count = 0; //down for (int i = 0; i < 5; i++) { ok = chessBoard->isSameChess(color, line + i, col); if (ok) { count++; } else { break; } } if (count >= 5) { return true; } else { return false; } } bool isWinUpHill(const string &color) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); int col = chessBoard->getCurrentCol(); int line = chessBoard->getCurrentLine(); bool ok = false; int count = 0; //up for (int i = 0; i < 5; i++) { ok = chessBoard->isSameChess(color, line-i, col + i); if (ok) { count++; } else { break; } } if (count >= 5) { return true; } count = 0; //down for (int i = 0; i < 5; i++) { ok = chessBoard->isSameChess(color, line+i, col - i); if (ok) { count++; } else { break; } } if (count >= 5) { return true; } else { return false; } } bool isWinDownHill(const string &color) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); int col = chessBoard->getCurrentCol(); int line = chessBoard->getCurrentLine(); bool ok = false; int count = 0; //up for (int i = 0; i < 5; i++) { ok = chessBoard->isSameChess(color, line - i, col - i); if (ok) { count++; } else { break; } } if (count >= 5) { return true; } count = 0; //down for (int i = 0; i < 5; i++) { ok = chessBoard->isSameChess(color, line + i, col + i); if (ok) { count++; } else { break; } } if (count >= 5) { return true; } else { return false; } } }; #endif

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号