在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
最近的工作和学习相对来说比较累,没有时间去研究比较深的原理性的专业知识,但是为了将我多年修炼的编程内功继续保持下去,我总会去写一些很有趣的东西,昨天休息在家我就用一天的时间完成了C++版的三国杀,虽然很搓,但还是想开源,希望刚学习C++的新手有所帮助。。。高手的话可以忽略我的存在。。。呵呵。。。
View Code
1 #include<iostream> 2 #include<time.h> 3 #include<stdio.h> 4 #include <stdlib.h> 5 using namespace std; 6 struct pai 7 { 8 int paifu; 9 int huase; 10 int yanse; 11 int dianshu; 12 int leixing; 13 int changdu; 14 void Kanpai() 15 { 16 if(paifu==0||paifu==1); 17 else 18 printf("牌副参数错误!\n"); 19 switch(huase) 20 { 21 case 0:cout<<"黑桃";break; 22 case 1:cout<<"红桃";break; 23 case 2:cout<<"草花";break; 24 case 3:cout<<"方片";break; 25 case -1:cout<<"无色";break; 26 default:printf("花色错误!\n");break; 27 } 28 switch(dianshu) 29 { 30 case 0:cout<<"A ";break; 31 case 1:cout<<"2 ";break; 32 case 2:cout<<"3 ";break; 33 case 3:cout<<"4 ";break; 34 case 4:cout<<"5 ";break; 35 case 5:cout<<"6 ";break; 36 case 6:cout<<"7 ";break; 37 case 7:cout<<"8 ";break; 38 case 8:cout<<"9 ";break; 39 case 9:cout<<"10 ";break; 40 case 10:cout<<"J ";break; 41 case 11:cout<<"Q ";break; 42 case 12:cout<<"K ";break; 43 case -1:cout<<"无点数";break; 44 default:printf("点数错误!\n");break; 45 } 46 switch(leixing) 47 { 48 case 101:cout<<"【杀】"<<endl;break; 49 case 102:cout<<"【闪】"<<endl;break; 50 case 103:cout<<"【桃】"<<endl;break; 51 case 201:cout<<"【过河拆桥】"<<endl;break; 52 case 202:cout<<"【顺手牵羊】"<<endl;break; 53 case 203:cout<<"【无中生有】"<<endl;break; 54 case 204:cout<<"【决斗】"<<endl;break; 55 case 205:cout<<"【借刀杀人】"<<endl;break; 56 case 206:cout<<"【桃园结义】"<<endl;break; 57 case 207:cout<<"【五谷丰登】"<<endl;break; 58 case 208:cout<<"【南蛮入侵】"<<endl;break; 59 case 209:cout<<"【万箭齐发】"<<endl;break; 60 case 210:cout<<"【无懈可击】"<<endl;break; 61 case 251:cout<<"【乐不思蜀】"<<endl;break; 62 case 252:cout<<"【闪电】"<<endl;break; 63 case 301:cout<<"【诸葛连弩(1)】"<<endl;break; 64 case 302:cout<<"【雌雄双股剑(2)】"<<endl;break; 65 case 303:cout<<"【青釭剑(2)】"<<endl;break; 66 case 304:cout<<"【青龙偃月刀(3)】"<<endl;break; 67 case 305:cout<<"【丈八蛇矛(3)】"<<endl;break; 68 case 306:cout<<"【贯石斧(3)】"<<endl;break; 69 case 307:cout<<"【方天画戟(4)】"<<endl;break; 70 case 308:cout<<"【麒麟弓(5)】"<<endl;break; 71 case 331:cout<<"【八卦阵】"<<endl;break; 72 case 361:cout<<"【赤兔(-1)】"<<endl;break; 73 case 362:cout<<"【大宛(-1)】"<<endl;break; 74 case 363:cout<<"【紫辛(-1)】"<<endl;break; 75 case 381:cout<<"【爪黄飞电(+1)】"<<endl;break; 76 case 382:cout<<"【的卢(+1)】"<<endl;break; 77 case 383:cout<<"【绝影(+1)】"<<endl;break; 78 default:printf("类型参数错误!");break; 79 } 80 } 81 }; 82 void Qishixipai(pai A[2][4][13],pai paidui[104]) 83 { 84 int i,m,x,y,z,a[104]={0}; 85 srand((unsigned)time(NULL)); 86 for(i=1;i<=104;i++) 87 { 88 while(a[m=rand()%104]); 89 a[m]=i; 90 } 91 for(i=0;i<=103;i++) 92 { 93 x=(a[i]-1)/52; 94 y=((a[i]-1)-52*x)/13; 95 z=(a[i]-1)%13; 96 paidui[i]=A[x][y][z]; 97 } 98 } 99 void Xipai(pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu) 100 { 101 int i,m,a[104]={0}; 102 srand((unsigned)time(NULL)); 103 for(i=1;i<=(*qipaishu);i++) 104 { 105 while(a[m=rand()%(*qipaishu)]); 106 a[m]=i; 107 } 108 for(i=0;i<=((*qipaishu)-1);i++) 109 { 110 paidui[i]=qipaidui[a[i]]; 111 qipaidui[a[i]].leixing=-1; 112 (*paiduishu)++; 113 (*qipaishu)--; 114 } 115 for(i=(*paiduishu);i<=103;i++)paidui[i].leixing=-1; 116 } 117 pai Mo1pai(pai A[104],int *x,pai B[104],int*y,int *b) 118 { 119 pai p; 120 if((*x)==0)Xipai(A,x,B,y); 121 else if((*x)<0)printf("摸牌参数错误!"); 122 else; 123 p=A[104-(*x)]; 124 (*x)--; 125 (*b)++; 126 return(p); 127 } 128 struct wujiang 129 { 130 char name; 131 int tili; 132 int tilishangxian; 133 int shoupaishangxian; 134 int huihekaishi; 135 int panding; 136 int mopai; 137 int chupai; 138 int qipai; 139 int huihejieshu; 140 int juese; 141 pai shoupai[20]; 142 int shoupaishu; 143 pai zhuangbei[4]; 144 int zhuangbeishu; 145 pai pandingpai[3]; 146 int pandingshu; 147 int juli[1]; 148 void Kanshoupai() 149 { 150 printf("玩家当前手牌:\n"); 151 if(shoupaishu) 152 { 153 int m; 154 for(m=0;m<=(shoupaishu-1);m++) 155 { 156 printf("%d ",m); 157 (shoupai[m]).Kanpai(); 158 } 159 } 160 else printf("空城!\n"); 161 printf("\n"); 162 } 163 void Kanzhuangbei() 164 { 165 if(juese)printf("玩家"); 166 else printf("电脑"); 167 printf("当前装备:\n"); 168 printf("0 武器: "); 169 if((zhuangbei[0]).leixing==-1)printf("空\n"); 170 else (zhuangbei[0]).Kanpai(); 171 printf("1 防具: "); 172 if((zhuangbei[1]).leixing==-1)printf("空\n"); 173 else (zhuangbei[1]).Kanpai(); 174 printf("2 进攻马: "); 175 if((zhuangbei[2]).leixing==-1)printf("空\n"); 176 else (zhuangbei[2]).Kanpai(); 177 printf("3 防御马: "); 178 if((zhuangbei[3]).leixing==-1)printf("空\n"); 179 else (zhuangbei[3]).Kanpai(); 180 printf("\n"); 181 } 182 void Kanpandingpai() 183 { 184 if(juese)printf("玩家"); 185 else printf("电脑"); 186 printf("当前判定区:\n"); 187 if((pandingpai[0]).leixing==-1)printf("空\n"); 188 else 189 { 190 printf("0 "); 191 (pandingpai[0]).Kanpai(); 192 if((pandingpai[1]).leixing==-1); 193 else 194 { 195 printf("1 "); 196 (pandingpai[1]).Kanpai(); 197 if((pandingpai[2]).leixing==-1); 198 else 199 { 200 printf("2 "); 201 (pandingpai[2]).Kanpai(); 202 } 203 } 204 } 205 } 206 }; 207 void Mopai(int*shoupaishu,pai shoupai[20],pai A[104],int *x,pai B[104],int*y,int juese) 208 { 209 if(juese)printf("玩家从牌堆摸2张牌\n"); 210 else printf("电脑从牌堆摸2张牌\n"); 211 pai p; 212 p=Mo1pai(A,x,B,y,shoupaishu); 213 shoupai[*shoupaishu-1]=p; 214 pai q; 215 q=Mo1pai(A,x,B,y,shoupaishu); 216 shoupai[*shoupaishu-1]=q; 217 int m; 218 if(juese) 219 { 220 printf("玩家当前手牌:\n"); 221 for(m=0;m<=(*shoupaishu-1);m++) 222 { 223 printf("%d ",m); 224 (shoupai[m]).Kanpai(); 225 } 226 } 227 printf("牌堆还剩%d张牌!\n\n",*x); 228 } 229 void Qishishoupai(wujiang *w,pai A[104],int *x,pai B[104],int*y) 230 { 231 pai a; 232 a=Mo1pai(A,x,B,y,&((*w).shoupaishu)); 233 (*w).shoupai[(*w).shoupaishu-1]=a; 234 pai b; 235 b=Mo1pai(A,x,B,y,&((*w).shoupaishu)); 236 (*w).shoupai[(*w).shoupaishu-1]=b; 237 pai c; 238 c=Mo1pai(A,x,B,y,&((*w).shoupaishu)); 239 (*w).shoupai[(*w).shoupaishu-1]=c; 240 pai d; 241 d=Mo1pai(A,x,B,y,&((*w).shoupaishu)); 242 (*w).shoupai[(*w).shoupaishu-1]=d; 243 int m; 244 if((*w).juese)printf("玩家从牌堆摸4张牌\n"); 245 else printf("电脑从牌堆摸4张牌\n"); 246 if((*w).juese) 247 { 248 printf("玩家当前手牌:\n"); 249 for(m=0;m<=((*w).shoupaishu-1);m++) 250 { 251 printf("%d ",m); 252 ((*w).shoupai[m]).Kanpai(); 253 } 254 } 255 printf("牌堆还剩%d张牌!\n\n",*x); 256 } 257 void Panding(pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu) 258 { 259 paidui[*paiduishu].Kanpai(); 260 qipaidui[*qipaishu]=paidui[*paiduishu]; 261 (*paiduishu)--; 262 (*qipaishu)++; 263 } 264 pai Zhangba(wujiang*w,pai qipaidui[104],int*qipaishu) 265 { 266 int x,y; 267 pai p; 268 for(;;) 269 { 270 int i,j; 271 printf("请输入任意两张手牌之前的编号,以空格隔开,以回车结束!\n"); 272 scanf("%d",&x); 273 scanf("%d",&y); 274 if((x>=0)&&(x<(*w).shoupaishu)&&(y>=0)&&(y<(*w).shoupaishu-1)) 275 { 276 switch((((*w).shoupai[x].huase)%2)+(((*w).shoupai[y].huase)%2)) 277 { 278 case 0:p.yanse=0;break; 279 case 2:p.yanse=1;break; 280 case 1:p.yanse=2;break; 281 default:printf("【丈八蛇矛】函数参数错误!\n"); 282 } 283 qipaidui[*qipaishu]=(*w).shoupai[x]; 284 (*w).shoupai[x].leixing=-1; 285 ((*w).shoupaishu)--; 286 (*qipaishu)++ 全部评论
专题导读
热门推荐
热门话题
阅读排行榜
|
请发表评论