C语言猜数字游戏程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{ do { printf("*"); scanf("%d",&z1); i2[3]=z1%10;/*把玩家
输入的数分离成 4 个*/ i2[2]=z1/10%10; i2[1]=z1/100%10; i2[0]=z1/1000%10;
if(z1>9999||z1<1000| |i2[0]==i2[1]||i2[0]==i2[2]||i2[0]==i2[3]||i2[1]
printf("ans is *%d*\n",z); printf("***sorry you lose...***"); for(i=10;i>0;i--)
{ sound(100*i); delay(10000000); nosound();
} } else { printf("***GREAT!! You WIN!!***");
{ clrscr();/*清屏*/ goto chooes;
} else
{ if(strcmp('n',yesno)==0) { printf(" 88...\n"); printf(" press any
key to quit..."); }
else { shua(); printf(" sorry,inp
for(i=1;i<10;i++) { sound(100*i); delay(10000000); nosound(); }
} getch(); printf(" \n\nplay again?? y/n : ");/*是否重来*/ scanf("%s",&yesno); if(strcmp('y',yesno)==0)
{ if(i1[iindex]==i2[ii
ndex]) { ia++; }
} printf("-----\n");
printf("*%dA%dB\n\n",ia,ib); gotoxy(60,11-xianshi),printf("%2d. % d * %dA%dB",11-xianshi,z1,ia,ib);/*在右边显
==i2[2]||i2[1]==i2[3]||i2[2]==i2[3]||i2[0]==0)/*判断玩家输 入数字是否每一位不同,是则重新输入
*/{
shua();/*调用刷小屏涵数*/
printf("\n**erroy...\n please input again :\n\n");
continue;
i1[0]=z/1000%10; } while(z<1000||i1[0]==i1[1]||i1[0]==i1[2]||i1[0]==i1[ 3]||i1[1]==i1[2]||i1[1]==i1[3]||i1
[2]==i1[3]||i1[0]==0);/*判断每一位数是否相同,如果是则重新输 出*/
ex1=5;源自文库getc
h(); }
else { shua
();/*调用刷小屏涵数*/
prin tf("**erroy...\n please input again...\n 1 or 2:");
goto chooes;
} } } for(iindex=0;iindex<10;iindex++)/*为变量赋值*/ { i1[iindex]=0; i2[iindex]=0; } ia=0,ib=0,z=11; iindex=0; do/*随机选取 1-9999 的数,放弃 1-999 的数,选择 1000-9999 的数*/ { for(iindex=0;iindex {z=random(100)*random(100);}/*随机选数*/ i1[3]=z%10;/*把随即数分成 4 个*/ i1[2]=z/10%10; i1[1]=z/100%10;
}
{ iindex1=20;
} else
{ if(easy==2) { iindex1=10; } else { if(easy==520) { shua
();/*调用刷小屏涵数*/ prin
tf("wahahahaaaaa.......\nyou choose -=Crazy=- model!!!\n"); iind
ut again...\n y/n : "); }
} getch(); }
shua()/*刷小屏涵数*/ {
int i_1,i_2; for(i_1=0;i_1<40;i_1++)
{ for(i_2=0;i_2<25;i_2++)
tf(" ");
} gotoxy(1,1); }
{ gotoxy(i_1,i_2),prin
} else
{
break; 到 break*/ 个数(B)*/
} }while(1);/*设置非 0,使循环直
ib=0;/*开始判断:数字正确,位置错误的
if(i1[0]==i2[1])ib++; if(i1[0]==i2[2])ib++; if(i1[0]==i2[3])ib++; if(i1[1]==i2[0])ib++; if(i1[1]==i2[2])ib++; if(i1[1]==i2[3])ib++; if(i1[2]==i2[0])ib++; if(i1[2]==i2[1])ib++; if(i1[2]==i2[3])ib++; if(i1[3]==i2[0])ib++; if(i1[3]==i2[1])ib++; if(i1[3]==i2[2])ib++; for(ia=0,iindex=0;iindex<4;iindex++) /*开始判断位置正确,数字错误的数(A)*/
示出之前的输入*/ shua();/*调用刷小屏涵数*/ if(z==z1) { printf("\n"); break; } else { printf(" you have
last %d life...\n try again :\n\n",iindex1-1); continue;
} } if(iindex1==0)/*判断输赢*/ {
shua();/*调用刷小屏涵数*/ printf("Now!!you have %d lifes!!Game Star!!\n",iindex1);/*游戏开始*/ printf(" please input 4 numbers :\n\n"); for(xianshi=10;iindex1>0;iindex1-=1,xianshi-=1)/*iin dex1 决定尝试次数*/
int i1[5],i2[5]; char yesno; chooes:/*设置 GOTO 点*/ printf("please chooes :\n 1 for nomal\n 2 for hard\n please input 1 or 2 :");/*选择难度开始*/ scanf("%d",&easy); if(easy==1)
C 语言猜数字游戏程序
#include "stdio.h" #include "conio.h" #include "dos.h" #include "stdlib.h"
void main() {
int z,z1,ia,ib,iindex,iindex1,i,ag,i_1,i_2,easy,xianshi;/*定义 变量*/
输入的数分离成 4 个*/ i2[2]=z1/10%10; i2[1]=z1/100%10; i2[0]=z1/1000%10;
if(z1>9999||z1<1000| |i2[0]==i2[1]||i2[0]==i2[2]||i2[0]==i2[3]||i2[1]
printf("ans is *%d*\n",z); printf("***sorry you lose...***"); for(i=10;i>0;i--)
{ sound(100*i); delay(10000000); nosound();
} } else { printf("***GREAT!! You WIN!!***");
{ clrscr();/*清屏*/ goto chooes;
} else
{ if(strcmp('n',yesno)==0) { printf(" 88...\n"); printf(" press any
key to quit..."); }
else { shua(); printf(" sorry,inp
for(i=1;i<10;i++) { sound(100*i); delay(10000000); nosound(); }
} getch(); printf(" \n\nplay again?? y/n : ");/*是否重来*/ scanf("%s",&yesno); if(strcmp('y',yesno)==0)
{ if(i1[iindex]==i2[ii
ndex]) { ia++; }
} printf("-----\n");
printf("*%dA%dB\n\n",ia,ib); gotoxy(60,11-xianshi),printf("%2d. % d * %dA%dB",11-xianshi,z1,ia,ib);/*在右边显
==i2[2]||i2[1]==i2[3]||i2[2]==i2[3]||i2[0]==0)/*判断玩家输 入数字是否每一位不同,是则重新输入
*/{
shua();/*调用刷小屏涵数*/
printf("\n**erroy...\n please input again :\n\n");
continue;
i1[0]=z/1000%10; } while(z<1000||i1[0]==i1[1]||i1[0]==i1[2]||i1[0]==i1[ 3]||i1[1]==i1[2]||i1[1]==i1[3]||i1
[2]==i1[3]||i1[0]==0);/*判断每一位数是否相同,如果是则重新输 出*/
ex1=5;源自文库getc
h(); }
else { shua
();/*调用刷小屏涵数*/
prin tf("**erroy...\n please input again...\n 1 or 2:");
goto chooes;
} } } for(iindex=0;iindex<10;iindex++)/*为变量赋值*/ { i1[iindex]=0; i2[iindex]=0; } ia=0,ib=0,z=11; iindex=0; do/*随机选取 1-9999 的数,放弃 1-999 的数,选择 1000-9999 的数*/ { for(iindex=0;iindex {z=random(100)*random(100);}/*随机选数*/ i1[3]=z%10;/*把随即数分成 4 个*/ i1[2]=z/10%10; i1[1]=z/100%10;
}
{ iindex1=20;
} else
{ if(easy==2) { iindex1=10; } else { if(easy==520) { shua
();/*调用刷小屏涵数*/ prin
tf("wahahahaaaaa.......\nyou choose -=Crazy=- model!!!\n"); iind
ut again...\n y/n : "); }
} getch(); }
shua()/*刷小屏涵数*/ {
int i_1,i_2; for(i_1=0;i_1<40;i_1++)
{ for(i_2=0;i_2<25;i_2++)
tf(" ");
} gotoxy(1,1); }
{ gotoxy(i_1,i_2),prin
} else
{
break; 到 break*/ 个数(B)*/
} }while(1);/*设置非 0,使循环直
ib=0;/*开始判断:数字正确,位置错误的
if(i1[0]==i2[1])ib++; if(i1[0]==i2[2])ib++; if(i1[0]==i2[3])ib++; if(i1[1]==i2[0])ib++; if(i1[1]==i2[2])ib++; if(i1[1]==i2[3])ib++; if(i1[2]==i2[0])ib++; if(i1[2]==i2[1])ib++; if(i1[2]==i2[3])ib++; if(i1[3]==i2[0])ib++; if(i1[3]==i2[1])ib++; if(i1[3]==i2[2])ib++; for(ia=0,iindex=0;iindex<4;iindex++) /*开始判断位置正确,数字错误的数(A)*/
示出之前的输入*/ shua();/*调用刷小屏涵数*/ if(z==z1) { printf("\n"); break; } else { printf(" you have
last %d life...\n try again :\n\n",iindex1-1); continue;
} } if(iindex1==0)/*判断输赢*/ {
shua();/*调用刷小屏涵数*/ printf("Now!!you have %d lifes!!Game Star!!\n",iindex1);/*游戏开始*/ printf(" please input 4 numbers :\n\n"); for(xianshi=10;iindex1>0;iindex1-=1,xianshi-=1)/*iin dex1 决定尝试次数*/
int i1[5],i2[5]; char yesno; chooes:/*设置 GOTO 点*/ printf("please chooes :\n 1 for nomal\n 2 for hard\n please input 1 or 2 :");/*选择难度开始*/ scanf("%d",&easy); if(easy==1)
C 语言猜数字游戏程序
#include "stdio.h" #include "conio.h" #include "dos.h" #include "stdlib.h"
void main() {
int z,z1,ia,ib,iindex,iindex1,i,ag,i_1,i_2,easy,xianshi;/*定义 变量*/