當前位置:首頁 » 編程語言 » c語言三國殺

c語言三國殺

發布時間: 2023-09-14 06:00:09

A. 求個用VC++C語言編寫的小游戲

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

熱點內容
滑板鞋腳本視頻 發布:2025-02-02 09:48:54 瀏覽:432
群暉怎麼玩安卓模擬器 發布:2025-02-02 09:45:23 瀏覽:557
三星安卓12彩蛋怎麼玩 發布:2025-02-02 09:44:39 瀏覽:743
電腦顯示連接伺服器錯誤 發布:2025-02-02 09:24:10 瀏覽:537
瑞芯微開發板編譯 發布:2025-02-02 09:22:54 瀏覽:146
linux虛擬機用gcc編譯時顯示錯誤 發布:2025-02-02 09:14:01 瀏覽:232
java駝峰 發布:2025-02-02 09:13:26 瀏覽:651
魔獸腳本怎麼用 發布:2025-02-02 09:10:28 瀏覽:532
linuxadobe 發布:2025-02-02 09:09:43 瀏覽:212
sql2000資料庫連接 發布:2025-02-02 09:09:43 瀏覽:726