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

作业社区

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

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

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

Player #ifndef __PLAYER_H_ #define __PLAYER_H_ #include using namespace std; class Player { public: Player(const string &name, const string &color) { this->name = name; this->color = color; } string getColor() const { return color; } string getName() const { return name; } virtual bool placeChess(int x, int y) = 0; private: string name; string color; }; #endif WhitePlayer #ifndef __WHITEPLAYER_H_ #define __WHITEPLAYER_H_ #include #include "Player.hpp" #include "ChessBoard.hpp" #include "WhiteChess.hpp" using namespace std; class WhitePlayer : public Player { public: WhitePlayer(const string &name) : Player(name, "white") {} bool placeChess(int x, int y) override { ChessBoard *chessBoard = ChessBoard::getChessBoard(); bool valid = chessBoard->isValidPosition(x, y); if (valid) { chessBoard->putChess(new WhiteChess(x, y)); } return valid; } }; #endif BlackPlayer #ifndef __BLACKPLAYER_H_ #define __BLACKPLAYER_H_ #include #include "Player.hpp" #include "ChessBoard.hpp" #include "BlackChess.hpp" using namespace std; class BlackPlayer : public Player { public: BlackPlayer(const string &name) : Player(name, "black") {} bool placeChess(int x, int y) override { ChessBoard *chessBoard = ChessBoard::getChessBoard(); bool valid = chessBoard->isValidPosition(x, y); if (valid) { chessBoard->putChess(new BlackChess(x, y)); } return valid; } }; #endif main // // Created by linux on 2025/3/11. // #include "BlackChess.hpp" #include "WhiteChess.hpp" #include "ChessBoard.hpp" #include "BlackPlayer.hpp" #include "WhitePlayer.hpp" int main(int argc, const char *argv[]) { //test show ChessBoard *chessBoard = ChessBoard::getChessBoard(); chessBoard->show(); #if 0 //test putChess BlackChess *blackChess = new BlackChess(12, 10); chessBoard->putChess(blackChess); WhiteChess *whiteChess = new WhiteChess(12, 12); chessBoard->putChess(whiteChess); //test isValidPosition BlackChess *blk1 = new BlackChess(12, 12); if(chessBoard->isValidPosition(blk1->getX(), blk1->getY())){ chessBoard->putChess(blk1); } #endif WhitePlayer *whitePlayer = new WhitePlayer("liming"); whitePlayer->placeChess(16, 10); BlackPlayer *blackPlayer = new BlackPlayer("Ami"); blackPlayer->placeChess(16, 12); return 0; }

微信客服

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

帮助反馈 APP下载

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

公众号

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