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

作业社区

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

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; }

得分 100
学习任务

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

// // Created by linux on 2025/3/11. // #include #include using namespace std; class MiVt100 { public: MiVt100(int x, int y, int len) : x(x), y(y), len(len) {} ~MiVt100() = default; MiVt100(const MiVt100 &other) { *this = other; } void setPoint(int x, int y, int backVtColor, int fontVtColor) { fprintf(stderr, "\033[%d;%dH", y, x); fprintf(stderr, "\033[%d;%dm", backVtColor, fontVtColor); fprintf(stderr, "*\n"); } void show() { showHorizontal(); showVertical(); showTiltUp(); showTiltDown(); } void reset() { fprintf(stderr, "\033[0m\033[?25h"); fprintf(stderr, "\033[%d;%dH", y + 10, x - 10); } private: int x; int y; int len; //水平 void showHorizontal() { for (int i = 0; i < len; i++) { //left this->setPoint(x + i, y, 40, 30); //right this->setPoint(x - i, y, 40, 30); } } //垂直 void showVertical() { for (int i = 0; i < len; i++) { //up this->setPoint(x, y - i, 41, 31); //down this->setPoint(x, y + i, 41, 31); } } //斜上 void showTiltUp() { for (int i = 0; i < len; i++) { //up this->setPoint(x + i, y - i, 42, 32); //down this->setPoint(x - i, y + i, 42, 32); } } //斜下 void showTiltDown() { for (int i = 0; i < len; i++) { //up this->setPoint(x + i, y + i, 43, 33); //down this->setPoint(x - i, y - i, 43, 33); } } }; int main(int argc, const char *argv[]) { MiVt100 *mi = new MiVt100(10, 10, 5); mi->show(); mi->reset(); return 0; }

微信客服

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

帮助反馈 APP下载

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

公众号

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