当前位置: 首页 > news >正文

享元模式实验围棋软件

image

include

include

using namespace std;
class Location {

private: string x;
string y;
public: Location(string x, string y) {
// TODO Auto-generated constructor stub
this->x = x;
this->y = y;
}
string getX() {
return x;
}
string getY() {
return y;
}
void setX(string x) {
this->x = x;
}
void setY(string y) {
this->y = y;
}

};

class Piece {

public: virtual string getColor()=0;
void locate(Location *lo) {

     cout<<this->getColor() << " " <<lo->getX() << "," <<lo->getY()<<endl;
}

};
class WhitePiece:public Piece{
public: string getColor() {
// TODO Auto-generated method stub
return "白棋";
}

};
class BlackPiece :public Piece{
public: string getColor() {
// TODO Auto-generated method stub
return "黑棋";
}

};

class PieceFatory {

private: //PieceFatory *instance;
Piece *wp=new WhitePiece() ;
Piece *bp=new BlackPiece() ;
public:
PieceFatory *getInstance() {
// cout << " dsv1 " << endl;
return new PieceFatory();
}

     Piece *getPiece(char *color) {if (strcmp("白棋",color)==0) {//cout << 1;return wp;}else {return bp;}
}

};
int main() {
Piece *b1, *b2, *w1, *w2;
//cout << " dsv " << endl;
PieceFatory *pf = new PieceFatory();
//cout << " dsv1 " << endl;
b1 = pf->getPiece("黑棋");
//cout << " dsv1 " << endl;
b2 = pf->getPiece("黑棋");
//cout << " dsv1 " << endl;
cout<<"判断两颗黑棋是否相同:" <<(b1 == b2)<<endl;

    w1 = pf->getPiece("白棋");w2 = pf->getPiece("白棋");cout<<"判断两颗白棋是否相同:" <<(w1 == w2)<<endl;b1->locate(new Location("1", "2"));b2->locate(new Location("3", "2"));//cout << 1;w1->locate(new Location("10", "2"));w2->locate(new Location("1", "21"));
http://www.zskr.cn/news/51691.html

相关文章:

  • The 4th Universal Cup. Stage 5: Grand Prix of Nanjing 做题笔记
  • 上述
  • 解密Prompt系列64. Anthropic Skils的延伸思考
  • 悟空来路与关山:AI元人文的终极眺望
  • nssm管理redis服务
  • pyslam(3) 开发语义建图 - MKT
  • Java 字节流与字符流
  • 精读GitHub - swift-markdown-ui
  • Bash的快捷键
  • Linux系统编程初步——冯诺依曼体系结构的理解
  • 2. 使用Gin处理HTTP请求
  • C++之复合类型(四) - Invinc
  • 物流管理,必须掌握的10个要点 - 智慧园区
  • 工程行业中-使用AI报价得可行性-一般(属于能应付但不精确,未测试在数据库全得情况下得效果,总体欠调教)
  • 每日反思(2025_11_16)
  • libvte, xfce4-terminal和gnome-terminal,干货满满
  • 寄卖业务质检1
  • [学习记录整理] ---IP地址,网关,掩码,DNS等
  • 2025 年 11 月不锈钢管件厂家权威推荐榜:欧标卡压管件,国标/薄壁/沟槽不锈钢管件,90/45弯头管件源头厂家精选
  • 2025.11.16总结
  • LeeCode_2 两数相加
  • 2025 年 11 月 CNC 高压清洗机厂家推荐排行榜,CNC全自动高压清洗机,CNC高压去毛刺清洗机,卧式/双工位CNC高压清洗机,数控高压清洗去毛刺机公司推荐
  • 2025 年 11 月 Q355B/Q345B/16Mn 冷拔扁钢厂家推荐排行榜,优质冷拔扁钢,高强度扁钢,精密扁钢公司精选
  • 2025 年 11 月 Q355B/Q345B/16Mn 冷拔圆钢厂家推荐排行榜,优质冷拔圆钢,高强度圆钢,合金结构钢圆钢公司精选
  • 图像算法处理-OpenCV图像翻转SSE版(ippicv)复现
  • 2025 年 11 月西服定制厂家推荐排行榜,兰州西服定制,婚纱/结婚/职业/男士/女士/团体/职场/新郎/定做/西装/礼服/工作服/职业装/公务员西服定制公司推荐
  • 2025 年 11 月防水网厂家推荐排行榜,防水网,味头防水网,专业防水网源头厂家实力解析与选购指南
  • 2025 年 11 月中医师承确有专长权威推荐榜:师承教育、专长医师资格考核与合法执业路径深度解析
  • 2025 年 11 月 Q355B/Q345B/16Mn 冷拉圆钢厂家推荐排行榜,高强度结构钢,低合金圆钢,精密冷拉钢材公司精选
  • 基于Tcl命令的HyperView截图