用C语言编写一个有趣的猜拳游戏

用C语言编写一个有趣的猜拳游戏,第1张

#include<stdioh>

#include<stringh>

#include<stdlibh>

#include<timeh>

#define maxn 10001

char p1[]="rock";

char p2[]="scissors";

char p3[]="cloth";

char h[4];

void init(void)

{

h[1]=p1;

h[2]=p2;

h[3]=p3;

}

void begin(void)

{

char your[maxn];

long com;

char p[maxn];

srand(time(NULL));

for(;;)

{

printf("input your order ( 1:rock 2:scissors 3:cloth )\n");

scanf("%s",your);

com=strlen(your);

if( your[0]>'3' || your[0]<'1' || com!=1)

{

printf("wrong order! please choose in(1~3);\n");

getchar();

continue;

}

printf("your order is %s!\n",h[your[0]-'0']);

getchar();

getchar();

com=rand()%3+1;

printf("The computer's order is %s!\n",h[com]);

getchar();

switch(com-your[0]+'0')

{

case 0:printf("draw game!\n");break;

case 1:

case -2:

printf("You wins!\n");break;

case -1:

case 2:

printf("The computer wins!\n");break;

}

com=1;

for(;com==1;)

{

printf("continue(Y/N)\n");

scanf("%s",p);

com=0;

switch(p[0])

{

case 'Y':break;

case 'N':

printf("press any key to continue\n");getchar();getchar();return ;

default:

printf("wrong order!\n");com=1;break;

}

}

}

}

main(void)

{

init();

begin();

return 0;

}

/太大了估计你不想要,给你一个扫雷程序,turbo

C下才能编译成功

空格:打标记

回车:扫雷

方向键:改变方向

/

#include<stdioh>

#include<conioh>

#include<timeh>

void

adjust(int,int);

int

a[23][23],c[22][22],mm,nn;

int

roundmine(int,int);

void

spread();

main()

{

int

i,j,b[22][22],minenum,mine;

int

x,y,yy,s;

char

g,h,z;

intx1;

inty1;

time_t

t;

again:srand((unsigned)

time(&t));

textcolor(LIGHTGREEN);

for(i=2;i<=21;i++)

for(j=2;j<=21;j++)

{

gotoxy(i,j);

putch(219);

b[i][j]=1;

c[i][j]=1;

}

minenum=0;

for(i=1;i<=22;i++)

for(j=1;j<=22;j++)

{

a[i][j]=0;

if(i>1&&i<22&j>1&&j<22)

{if((s=rand()%10)>0)

a[i][j]=0;

else

if(s==0)

a[i][j]=1;

}

if(a[i][j])

minenum++;

}

gotoxy(50,2);

puts("dirction");

gotoxy(50,3);

puts("SPACE:mark");

gotoxy(50,4);

puts("ENTER:dig");

gotoxy(50,8);

printf("mine

num:%4d",minenum);

gotoxy(50,5);

printf("ESC:exit");

gotoxy(30,15);

puts("

");

gotoxy(30,20);

puts("

");

mine=minenum;

gotoxy(2,2);

x=2;y=2;

while(mine)

{

h=getch();

if(h=='H')

gotoxy(x,--y);

else

if(h=='P')

gotoxy(x,++y);

else

if(h=='K')

gotoxy(--x,y);

else

if(h=='M')

gotoxy(++x,y);

x1=&x;y1=&y;

adjust(x1,y1);

if(h=='

')

{

if(c[wherex()][wherey()])

if(b[wherex()][wherey()])

{

textcolor(LIGHTRED);

putch(16);

mine--;

gotoxy(59,8);

printf("%4d",mine);

gotoxy(x,y);

b[wherex()][wherey()]=0;

}

else

{

textcolor(LIGHTGREEN);

putch(219);

mine++;

gotoxy(59,8);

printf("%4d",mine);

gotoxy(x,y);

b[wherex()][wherey()]=1;

}

}

if(h=='\015')

{

mm=wherex();nn=wherey();

c[wherex()][wherey()]=0;

if(a[wherex()][wherey()])

{

for(i=2;i<=21;i++)

for(j=2;j<=21;j++)

{gotoxy(i,j);

if(a[i][j])

{textcolor(LIGHTRED);

putch(017);

}

}

break;

}

else

{spread();gotoxy(mm,nn);}

}

if(h=='\033')

exit(0);

}

yy=1;

for(i=2;i<=21;i++)

for(j=2;j<=21;j++)

if

(a[i][j]==1&&b[i][j]==1)

{gotoxy(30,15);

cprintf("You

lose!!");

yy=0;

}

if(yy)

{gotoxy(30,15);

cprintf("You

win!!");

}

gotoxy(30,20);

cprintf("Once

again(y/n)");

z=getch();

if(z=='y')

goto

again;

}

void

adjust(int

x,int

y)

{

if(x<2)

gotoxy(x+=20,y);

else

if(x>21)

gotoxy(x-=20,y);

else

if(y<2)

gotoxy(x,y+=20);

else

if(y>21)

gotoxy(x,y-=20);

}

int

roundmine(int

x,int

y)

{

int

i,j,r=0;

for(i=x-1;i<=x+1;i++)

for(j=y-1;j<=y+1;j++)

if(a[i][j])

r++;

return

r;

}

void

spread()

{

int

r,i,j,x,y;

x=wherex();

y=wherey();

r=roundmine(x,y);

if(r)

{printf("%d",r);c[x][y]=0;}

else

if(r==0&&x>1&&x<22&&y>1&&y<22)

{

putchar('

');c[x][y]=0;

for(i=x-1;i<=x+1;i++)

for(j=y-1;j<=y+1;j++)

if(x>1&&x<22&&y>1&&y<22&&c[i][j])

{gotoxy(i,j);

spread();

}

}

}

好,给你一个有趣的程序,下面程序的作用是,输入一个4位数,之后将这个数分解成4个数字,并将这4个数字组合成一个最大数和一个最小数,并将两者相减,结果作为新的4位数,重复前面的步骤,最后的结果是什么?自己测试一下。

#include <stdioh>

void mysort(int a, int size)

{

int i, j, k, t;

for (i = 0; i < size - 1; ++i)

{

k = i;

for (j = i; j < size; ++j)

{

if (a[k] > a[j])

k = j;

}

if (k != i)

{

t = a[i];

a[i] = a[k];

a[k] = t;

}

}

}

void main()

{

int num, a[4], max, min;

do

{

scanf("%d", &num); / 输入最初的4位数 /

} while (num < 1000 || num > 9999);

while (num)

{

/ 将4位数分解成4个独立的数字,并保存在a数组中 /

a[0] = num % 10;

num /= 10;

a[1] = num % 10;

num /= 10;

a[2] = num % 10;

num /= 10;

a[3] = num;

/ 排序数组元素 /

mysort(a, 4);

/ 从数组的4个元素中产生最大数字和最小数字 /

max = a[3] 1000 + a[2] 100 + a[1] 10 + a[0];

min = a[0] 1000 + a[1] 100 + a[2] 10 + a[3];

/ 产生新的4位数 /

num = max - min;

printf("%d\n", num);

if (num == 6174)

break;

}

printf("The magic number is: %d\n", num);

}

以上就是关于用C语言编写一个有趣的猜拳游戏全部的内容,包括:用C语言编写一个有趣的猜拳游戏、谁有c语言一些运行起来结果很好玩的程序的代码..、给我一个较复杂的C语言程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/10135243.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存