求个用VC++C语言编写的小游戏
发布网友
发布时间:2022-04-26 10:54
我来回答
共2个回答
热心网友
时间:2022-06-27 14:25
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(void)
{
int random();
int mopai(int shan);
int yourchusha(int shan);
int i,xingcan=0,temp,choice;
int yoursha=0,yourshan=0;
int itssha=0,itsshan=0;
int yourhp=4,itshp=4;
printf("三国杀简易版:\n");
printf("开始游戏:\n");
srand( (unsigned)time( NULL ) );
for(i=1;i<=4;i++)
{
random();//random() 方法可返回介于 0 ~ 1 之间的一个随机数。
if(!random())
yourshan+=1;
else yoursha+=1;
}
for(i=1;i<=4;i++)
{
random();
if(!random())
itsshan+=1;
else itssha+=1;
}
printf("你的手牌:杀%d张,闪%d张\t",yoursha,yourshan);
printf("计算机的手牌:%d张\n",itssha+itsshan);
printf("你的体力:%d\t",yourhp);
printf("计算机的体力:%d\n",itshp);
while(yourhp&&itshp)
{
printf("\n你的行动开始:\n");
printf("\n摸牌阶段:\n");
temp=mopai(xingcan);
yourshan+=temp;
yoursha+=(2-temp);
xingcan=0;
printf("你的手牌:杀%d张,闪%d张\n",yoursha,yourshan);
printf("\n按任意键继续\n");
getch();
system("cls");
printf("你的手牌:杀%d张,闪%d张\t",yoursha,yourshan);
printf("计算机的手牌:%d张\n",itssha+itsshan);
printf("你的体力:%d\t",yourhp);
printf("计算机的体力:%d\n",itshp);
printf("\n出牌阶段:\n");
printf("请选择:\n");
printf("1.出杀 2.弃牌\n");
while(1)
{
scanf("%d",&choice);
if(choice!=1&&choice!=2)
printf("输入错误,请重新输入\n");
else break;
}
if(choice==1)
{
if(yoursha)
{
yoursha-=1;
if(yourchusha(itsshan))
itsshan-=1;
else
{
itshp-=1;
}
}
else printf("你没有杀,请弃牌\n");
}
if(!itshp)
break;
printf("\n按任意键继续\n");
getch();
system("cls");
printf("你的手牌:杀%d张,闪%d张\t",yoursha,yourshan);
printf("计算机的手牌:%d张\n",itssha+itsshan);
printf("你的体力:%d\t",yourhp);
printf("计算机的体力:%d\n",itshp);
printf("弃牌阶段:\n");
while(yoursha+yourshan-yourhp>0)
{
printf("你需要弃掉%d张卡牌,请逐张弃牌:\n",yoursha+yourshan-yourhp);
printf("1.弃一张杀 2.弃一张闪\n");
while(1)
{
scanf("%d",&choice);
if(choice!=1&&choice!=2)
printf("输入错误,请重新输入\n");
else break;
}
switch(choice)
{
case 1:
{
if(yoursha)
yoursha-=1;
else printf("你没有杀,请重新选择\n");
break;
}
case 2:
{
if(yourshan)
yourshan-=1;
else printf("你没有闪,请重新选择\n");
break;
}
}
}
printf("你的行动结束。\n");
printf("\n按任意键继续\n");
getch();
system("cls");
printf("你的手牌:杀%d张,闪%d张\t",yoursha,yourshan);
printf("计算机的手牌:%d张\n",itssha+itsshan);
printf("你的体力:%d\t",yourhp);
printf("计算机的体力:%d\n",itshp);
printf("计算机的行动开始:\n");
printf("摸牌阶段:\n");
temp=mopai(xingcan);
itsshan+=temp;
itssha+=(2-temp);
xingcan=0;
printf("计算机手牌数:%d张\n",itssha+itsshan);
printf("\n按任意键继续\n");
getch();
system("cls");
printf("你的手牌:杀%d张,闪%d张\t",yoursha,yourshan);
printf("计算机的手牌:%d张\n",itssha+itsshan);
printf("你的体力:%d\t",yourhp);
printf("计算机的体力:%d\n",itshp);
printf("出牌阶段:\n");
if(itssha)
{
itssha-=1;
printf("杀\n");
printf("计算机对你出了一张杀,请出一张闪\n");
printf("1.确定 2.取消\n");
while(1)
{
scanf("%d",&choice);
if(choice!=1&&choice!=2){
printf("输入错误,请重新输入\n");
system("cls");
printf("你的手牌:杀%d张,闪%d张\t",yoursha,yourshan);
printf("计算机的手牌:%d张\n",itssha+itsshan);
printf("你的体力:%d\t",yourhp);
printf("计算机的体力:%d\n",itshp);
}
else break;
}
switch(choice)
{
case 1:
{
if(yourshan)
{
yourshan-=1;
printf("闪\n");
break;
}
else printf("你没有闪\n");
}
case 2:
{
yourhp-=1;
printf("计算机对你造成一点伤害\n");
}
}
}
if(!yourhp)
break;
printf("计算机手牌数:%d张\n",itssha+itsshan);
printf("弃牌阶段:\n");
if(itssha+itsshan-itshp>0)
{
if(itshp>itsshan)
{
printf("计算机弃杀%d张\n",itssha+itsshan-itshp);
itssha-=(itssha+itsshan-itshp);
}
else
{
printf("计算机弃杀%d张,闪%d张\n",itssha,itsshan-itshp);
itssha=0;
itsshan=itshp;
}
}
printf("计算机的行动结束。\n");
printf("\n按任意键继续\n");
getch();
system("cls");
printf("你的手牌:杀%d张,闪%d张\t",yoursha,yourshan);
printf("计算机手牌数:%d张\n",itssha+itsshan);
printf("你的体力:%d\t",yourhp);
printf("计算机的体力:%d\n",itshp);
}
if(!yourhp)
printf("很遗憾,计算机击败了你\n");
else printf("恭喜你,你击败了计算机\n");
printf("游戏结束,欢迎下次再来!\n");
printf("\n按任意键退出。");
getch();
return 0;
}
int random()
{
return rand()%3;
}
int mopai(int shan)
{
int i;
srand( (unsigned)time( NULL ) );
for(i=1;i<=2;i++)
{
random();
if(!random())
shan+=1;
}
return shan;
}
int yourchusha(int shan)
{
printf("杀 ");
if(shan)
{
printf("闪\n");
return 1;
}
else
{
printf("您对计算机造成一点伤害\n");
return 0;
}
}
热心网友
时间:2022-06-27 14:25
#include <bits/stdc++.h>
#include <Windows.h>
#include <conio.h>
using namespace std;
long long side[21][42],x=20,y=10,ans,xue=10;char chInput;
int main(){srand((unsigned)time(NULL));
for(int i=1;i<21;i++)
for(int j=1;j<40;j++)side[i][j]=' ';
side[y][x]=side[y][x+1]=side[y][x+2]=side[y][x-1]=side[y][x-2]=side[y-1][x]=side[y-1][x+1]=side[y-1][x+2]=side[y-1][x-1]=side[y-1][x-2]=side[y+1][x]=side[y+1][x+1]=side[y+1][x+2]=side[y+1][x-1]=side[y+1][x-2]='9';
while(xue){
for(int i=1;i<21;i++){
for(int j=1;j<41;j++){
if(side[i][j+1]!='9'){ side[i][j]=side[i][j+1];
if(side[i][j]=='1'&&y-i<2&&y-i>-2&&x-j<3&&x-j>-3){
xue--;side[i][j]=' '; } }
else
side[i][j]=' ';}
side[i][39]=' ';
side[i][40]=' ';
side[i][41]=' ';}
ans++;side[y][x]=side[y][x+1]=side[y][x+2]=side[y][x-1]=side[y][x-2]=side[y-1][x]=side[y-1][x+1]=side[y-1][x+2]=side[y-1][x-1]=side[y-1][x-2]=side[y+1][x]=side[y+1][x+1]=side[y+1][x+2]=side[y+1][x-1]=side[y+1][x-2]='9';
if(rand()%10==5)
side[rand()%20+1][39]='1';
system("cls");
if(y==1)
side[20][x]=side[20][x+1]=side[20][x+2]=side[20][x-1]=side[20][x-2]='9';
if(y==20)
side[1][x]=side[1][x+1]=side[1][x+2]=side[1][x-1]=side[1][x-2]='9';
cout<<"你的血量 "<<xue<<endl;
for(int i=1;i<21;i++){for(int j=1;j<41;j++)
cout<<char(side[i][j]);
cout<<endl;}
if(kbhit()){chInput = getch();
if(chInput == 72){y--;
if(y==0)y=20; }
if(chInput == 80){y++;
if(y==21)y=1;}
if(chInput == 75){x--;
if(x==2)x=3;}
if(chInput == 77) { x++;
if(x==39)x=38;}}}
system("cls");
cout<<"你死了"<<endl;
cout<<"你支持的时间 "<<ans;
Sleep(10000);
return 0;
}