c++游戏编程三国杀

三国杀

这是我华丽的分界线

//====================================//

源代码:

#include<iostream>
#include<time.h>
#include<stdio.h>
#include <stdlib.h>
using namespace std;
struct pai
{
int paifu;
int huase;
int yanse;
int dianshu;
int leixing;
int changdu;
void Kanpai()
{
if(paifu==0||paifu==1);
else
printf("牌副参数错误!\n");
switch(huase)
{
case 0:cout<<"黑桃";break;
case 1:cout<<"红桃";break;
case 2:cout<<"草花";break;
case 3:cout<<"方片";break;
case -1:cout<<"无色";break;
default:printf("花色错误!\n");break;
}
switch(dianshu)
{
case 0:cout<<"A ";break;
case 1:cout<<"2 ";break;
case 2:cout<<"3 ";break;
case 3:cout<<"4 ";break;
case 4:cout<<"5 ";break;
case 5:cout<<"6 ";break;
case 6:cout<<"7 ";break;
case 7:cout<<"8 ";break;
case 8:cout<<"9 ";break;
case 9:cout<<"10 ";break;
case 10:cout<<"J ";break;
case 11:cout<<"Q ";break;
case 12:cout<<"K ";break;
case -1:cout<<"无点数";break;
default:printf("点数错误!\n");break;
}
switch(leixing)
{
case 101:cout<<"【杀】"<<endl;break;
case 102:cout<<"【闪】"<<endl;break;
case 103:cout<<"【桃】"<<endl;break;
case 201:cout<<"【过河拆桥】"<<endl;break;
case 202:cout<<"【顺手牵羊】"<<endl;break;
case 203:cout<<"【无中生有】"<<endl;break;
case 204:cout<<"【决斗】"<<endl;break;
case 205:cout<<"【借刀杀人】"<<endl;break;
case 206:cout<<"【桃园结义】"<<endl;break;
case 207:cout<<"【五谷丰登】"<<endl;break;
case 208:cout<<"【南蛮入侵】"<<endl;break;
case 209:cout<<"【万箭齐发】"<<endl;break;
case 210:cout<<"【无懈可击】"<<endl;break;
case 251:cout<<"【乐不思蜀】"<<endl;break;
case 252:cout<<"【闪电】"<<endl;break;
case 301:cout<<"【诸葛连弩(1)】"<<endl;break;
case 302:cout<<"【雌雄双股剑(2)】"<<endl;break;
case 303:cout<<"【青釭剑(2)】"<<endl;break;
case 304:cout<<"【青龙偃月刀(3)】"<<endl;break;
case 305:cout<<"【丈八蛇矛(3)】"<<endl;break;
case 306:cout<<"【贯石斧(3)】"<<endl;break;
case 307:cout<<"【方天画戟(4)】"<<endl;break;
case 308:cout<<"【麒麟弓(5)】"<<endl;break;
case 331:cout<<"【八卦阵】"<<endl;break;
case 361:cout<<"【赤兔(-1)】"<<endl;break;
case 362:cout<<"【大宛(-1)】"<<endl;break;
case 363:cout<<"【紫辛(-1)】"<<endl;break;
case 381:cout<<"【爪黄飞电(+1)】"<<endl;break;
case 382:cout<<"【的卢(+1)】"<<endl;break;
case 383:cout<<"【绝影(+1)】"<<endl;break;
default:printf("类型参数错误!");break;
}
}
};
void Qishixipai(pai A[2][4][13],pai paidui[104])
{
int i,m,x,y,z,a[104]={0};
srand((unsigned)time(NULL));
for(i=1;i<=104;i++)
{
while(a[m=rand()%104]);
a[m]=i;
}
for(i=0;i<=103;i++)
{
x=(a[i]-1)/52;
y=((a[i]-1)-52*x)/13;
z=(a[i]-1)%13;
paidui[i]=A[x][y][z];
}
}
void Xipai(pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
{
int i,m,a[104]={0};
srand((unsigned)time(NULL));
for(i=1;i<=(*qipaishu);i++)
{
while(a[m=rand()%(*qipaishu)]);
a[m]=i;
}
for(i=0;i<=((*qipaishu)-1);i++)
{
paidui[i]=qipaidui[a[i]];
qipaidui[a[i]].leixing=-1;
(*paiduishu)++;
(*qipaishu)--;
}
for(i=(*paiduishu);i<=103;i++)paidui[i].leixing=-1;
}
pai Mo1pai(pai A[104],int *x,pai B[104],int*y,int *b)
{
pai p;
if((*x)==0)Xipai(A,x,B,y);
else if((*x)<0)printf("摸牌参数错误!");
else;
p=A[104-(*x)];
(*x)--;
(*b)++;
return(p);
}
struct wujiang
{
char name;
int tili;
int tilishangxian;
int shoupaishangxian;
int huihekaishi;
int panding;
int mopai;
int chupai;
int qipai;
int huihejieshu;
int juese;
pai shoupai[20];
int shoupaishu;
pai zhuangbei[4];
int zhuangbeishu;
pai pandingpai[3];
int pandingshu;
int juli[1];
void Kanshoupai()
{
printf("玩家当前手牌:\n");
if(shoupaishu)
{
int m;
for(m=0;m<=(shoupaishu-1);m++)
{
printf("%d ",m);
(shoupai[m]).Kanpai();
}
}
else printf("空城!\n");
printf("\n");
}
void Kanzhuangbei()
{
if(juese)printf("玩家");
else printf("电脑");
printf("当前装备:\n");
printf("0 武器: ");
if((zhuangbei[0]).leixing==-1)printf("空\n");
else (zhuangbei[0]).Kanpai();
printf("1 防具: ");
if((zhuangbei[1]).leixing==-1)printf("空\n");
else (zhuangbei[1]).Kanpai();
printf("2 进攻马: ");
if((zhuangbei[2]).leixing==-1)printf("空\n");
else (zhuangbei[2]).Kanpai();
printf("3 防御马: ");
if((zhuangbei[3]).leixing==-1)printf("空\n");
else (zhuangbei[3]).Kanpai();
printf("\n");
}
void Kanpandingpai()
{
if(juese)printf("玩家");
else printf("电脑");
printf("当前判定区:\n");
if((pandingpai[0]).leixing==-1)printf("空\n");
else
{
printf("0 ");
(pandingpai[0]).Kanpai();
if((pandingpai[1]).leixing==-1);
else
{
printf("1 ");
(pandingpai[1]).Kanpai();
if((pandingpai[2]).leixing==-1);
else
{
printf("2 ");
(pandingpai[2]).Kanpai();
}
}
}
}
};
void Mopai(int*shoupaishu,pai shoupai[20],pai A[104],int *x,pai B[104],int*y,int juese)
{
if(juese)printf("玩家从牌堆摸2张牌\n");
else printf("电脑从牌堆摸2张牌\n");
pai p;
p=Mo1pai(A,x,B,y,shoupaishu);
shoupai[*shoupaishu-1]=p;
pai q;
q=Mo1pai(A,x,B,y,shoupaishu);
shoupai[*shoupaishu-1]=q;
int m;
if(juese)
{
printf("玩家当前手牌:\n");
for(m=0;m<=(*shoupaishu-1);m++)
{
printf("%d ",m);
(shoupai[m]).Kanpai();
}
}
printf("牌堆还剩%d张牌!\n\n",*x);
}
void Qishishoupai(wujiang *w,pai A[104],int *x,pai B[104],int*y)
{
pai a;
a=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=a;
pai b;
b=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=b;
pai c;
c=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=c;
pai d;
d=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=d;
int m;
if((*w).juese)printf("玩家从牌堆摸4张牌\n");
else printf("电脑从牌堆摸4张牌\n");
if((*w).juese)
{
printf("玩家当前手牌:\n");
for(m=0;m<=((*w).shoupaishu-1);m++)
{
printf("%d ",m);
((*w).shoupai[m]).Kanpai();
}
}
printf("牌堆还剩%d张牌!\n\n",*x);
}
void Panding(pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
{
paidui[*paiduishu].Kanpai();
qipaidui[*qipaishu]=paidui[*paiduishu];
(*paiduishu)--;
(*qipaishu)++;
}
pai Zhangba(wujiang*w,pai qipaidui[104],int*qipaishu)
{
int x,y;
pai p;
for(;;)
{
int i,j;
printf("请输入任意两张手牌之前的编号,以空格隔开,以回车结束!\n");
scanf("%d",&x);
scanf("%d",&y);
if((x>=0)&&(x<(*w).shoupaishu)&&(y>=0)&&(y<(*w).shoupaishu-1))
{
switch((((*w).shoupai[x].huase)%2)+(((*w).shoupai[y].huase)%2))
{
case 0:p.yanse=0;break;
case 2:p.yanse=1;break;
case 1:p.yanse=2;break;
default:printf("【丈八蛇矛】函数参数错误!\n");
}
qipaidui[*qipaishu]=(*w).shoupai[x];
(*w).shoupai[x].leixing=-1;
((*w).shoupaishu)--;
(*qipaishu)++;
qipaidui[*qipaishu]=(*w).shoupai[y];
(*w).shoupai[y].leixing=-1;
((*w).shoupaishu)--;
(*qipaishu)++; printf("弃牌数:%d",*qipaishu);
for(i=0;i<=(((*w).shoupaishu)+1);i++)
{
if((*w).shoupai[i].leixing==-1)
{
for(j=i+1;j<=(((*w).shoupaishu)+2);j++)
(*w).shoupai[j-1]=(*w).shoupai[j];
i--;
}
}
printf("玩家把:\n");
qipaidui[(*qipaishu)-2].Kanpai();
qipaidui[(*qipaishu)-1].Kanpai();
printf("当作一张");
switch(p.yanse)
{
case 0:printf("黑色");break;
case 2:printf("红色");break;
case 1:printf("无色");break;
default:printf("绿色");break;
}
printf("无点数的【杀】");
p.dianshu=-1;
p.leixing=101;
return p;
break;
}
printf("你将两张空气当作一张空气属性的【杀】使用或打出!\n");
}
}
int Xuanpai(wujiang*w,int t)
{
int x;
if((*w).juese)
{
for(;;)
{
printf("出牌请输入手牌之前的编号,以回车结束!\n如果你想结束出牌阶段,请输入“-1”,以回车结束!\n");
scanf("%d",&x);
if((x>=-1&&x<((*w).shoupaishu))||((x==100)&&((*w).zhuangbei[0].leixing==305)))
{
return x;
break;
}
printf("你打出了一张空气!\n");
}
}
else return t;
}
pai Panpai(wujiang*w1,int*sha,int y,pai qipaidui[104],int*qipaishu)
{
pai p,q;
p.leixing=0;
q.leixing=-1;
if(y==-1)return q;
else
{
if(y==100)
{
if((*sha)>0)
{
q=Zhangba(w1,qipaidui,qipaishu);
printf("使用!\n");
return q;
}
else
{
printf("当前回合使用【杀】的次数已用尽,你也不能使用【丈八蛇矛】效果!\n");
return p;
}
}
switch((*w1).shoupai[y].leixing)
{
case 101:
if(((*sha)>0)||((*w1).zhuangbei[0].leixing==301))
{
if(((*w1).zhuangbei[0].leixing==301))printf("武器【诸葛连弩】效果被触发!\n");
return (*w1).shoupai[y];
break;
}
else
{
if((*w1).juese)printf("当前回合使用【杀】的次数已用尽,你不能使用【杀】!\n");
return p;break;
}
case 102:
if((*w1).juese)
printf("当前不需要响应任何操作,你不能主动打出【闪】!\n");
return p;break;
case 103:
if(((*w1).tili)<((*w1).tilishangxian))
{
return (*w1).shoupai[y];
break;
}
else
{
if((*w1).juese)
printf("你并未受伤,不能对自己使用【桃】!\n");
}
return p;break;
case 210:
if((*w1).juese)
printf("当前不需要响应任何锦囊,你不能主动打出【无懈可击】!\n");
return p;break;
case 201:
case 202:
case 203:
case 204:
case 205:
case 206:
case 207:
case 208:
case 209:
case 251:
case 252:
case 301:
case 302:
case 303:
case 304:
case 305:
case 306:
case 307:
case 308:
case 331:
case 361:
case 362:
case 363:
case 381:
case 382:
case 383:return (*w1).shoupai[y];break;
default:printf("手牌类型参数错误!\n");return p;break;
}
}
}
int Mubiao(pai p,wujiang *w1,wujiang *w2,int*sha)
{
int x;
switch(p.leixing)
{
case 101:
if((*w1).juese)
{
printf("请选择【杀】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
{
if((*w1).zhuangbei[0].changdu>=(*w1).juli[0])
{
(*sha)--;
return((*w2).juese);
}
else
{
printf("武器长度不够!\n");
return -2;
}
}
else
{
printf("目标错误!\n");
return -2;
}
}
else
{
if((*w1).zhuangbei[0].changdu>=(*w1).juli[0])
{
(*sha)--;
return((*w2).juese);
}
else return -2;
}
break;
case 103:return((*w1).juese);break;
case 201:
if((*w1).juese)
{
printf("请选择【过河拆桥】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
{
if((*w2).shoupaishu||(*w2).zhuangbeishu||(*w2).pandingshu)return((*w2).juese);
else
{
printf("目标没有牌!\n");
return -2;
}
}
else
{
printf("目标错误!\n");
return -2;
}
}
else return((*w2).juese);
break;
case 202:
if((*w1).juese)
{
printf("请选择【顺手牵羊】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
{
if(((*w2).shoupaishu||(*w2).zhuangbeishu||(*w2).pandingshu)&&((*w1).juli[0]<=1))return((*w2).juese);
else
{
printf("目标没有牌!\n");
return -2;
}
}
else
{
printf("目标错误!\n");
return -2;
}
}
else
{
if((*w1).juli[0]<=1)return((*w2).juese);
else return -2;
}
break;
case 203:
return((*w1).juese);break;
case 204:
if((*w1).juese)
{
printf("请选择【决斗】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
s
  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
多人三国杀游戏代码是指用计算机编程语言编写的,用于实现多人同时进行三国杀游戏的程序代码。 多人三国杀游戏是基于经典桌面游戏三国杀的电子化延伸,可以通过网络连接使多名玩家在不同的地理位置共同参与游戏。通过编写代码,可以实现游戏的各种功能和规则,例如角色选择、卡牌发放、游戏逻辑判断、玩家互动等等。 编写多人三国杀游戏代码可以有多种方式,常用的有使用面向对象的编程语言如Java或C#,也可以使用脚本语言如Python进行开发。编写代码前需要设定好游戏规则和功能需求,然后通过编程语言提供的语法和函数来编写程序。 在代码中,可以使用类和对象的概念来建立玩家、角色、卡牌等各种实体的数据结构和行为。可以利用条件语句和循环语句来实现游戏逻辑的判断和流程控制。还可以使用网络编程相关的技术来实现玩家之间的通信和互动。 编写代码时需要考虑到游戏的性能和用户体验,要尽可能地优化程序的执行效率和响应速度,确保游戏可以在不同的设备上流畅运行。同时,也要考虑到游戏的可扩展性,方便后续对游戏进行功能扩展和更新。 总之,多人三国杀游戏代码是用于实现多人同时进行三国杀游戏的程序代码,需要通过编程语言和相关技术来实现游戏的各种功能和规则,以提供优秀的游戏体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值