1. 首页 > 科技 >

c 好玩的代码(c好玩的代码)

简单好玩的编程代码有哪些?

好玩功能性强的编程代码:

c  好玩的代码(c好玩的代码)c 好玩的代码(c好玩的代码)


c 好玩的代码(c好玩的代码)


如msgbox "系统检测到WINDOWS更新中捆绑有不明插件

SXS.exe,是否对其扫描?"

msgbox "文件名 SXS.exe"+CHR(13)+"发行者 田间的菜鸟 "+chr(13)+"安全评级 高危"+chr(13)+"建议 直接删除"+chr(13)+"类型:木马",,"windows扫描附件"

msgbox "是否阻止其安装?",vbyesno

wscript.sleep 3000msgbox "阻止失败!请检查防火墙是否开启!

学少儿编程可以提高孩子逻辑思维、专注力

代码就是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。代码设计的原则包括确定性、标准化和通用性、可扩充性与稳定性、便于识别与记忆、力求短小与格式统一以及容易修改等。 源代码是代码的分支,某种意义上来说,源代码相当于代码。现代程序语言中,源代码可以书籍或磁带形式出现,但为常用格式是文本文件,这种典型格式的目的是为了编译出计算机程序。

如果对编程还有什么问题的话,可以咨询童程童美,该机构是达内教育旗下少儿编程培训品牌,19年编程科技素质教育,130000+学员的选择,打造出适合3-18岁孩子的科技素质教育解决方案,为培养孩子的信息素养,全面推动科技素质教育发展。。目前童程童美有少儿编程体验课,点击可免费报名试听

用C语言编写的小游戏代码是什么?

/也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++6.0、turbo????)上都能运行,你还可以进一步改进。这是一个类似贪吃蛇的小游戏。祝你好运/\x0d\x0a/贪吃蛇/\x0d\x0a#include\x0d\x0a#include\x0d\x0a#include\x0d\x0a#include\x0d\x0aint head=3 ,tail=0;\x0d\x0aint main()\x0d\x0a{\x0d\x0aint i,j,k=0;\x0d\x0aint zuobiao[2][80];\x0d\x0along start;\x0d\x0aint direction=77;\x0d\x0aint speed;\x0d\x0aint timeover;\x0d\x0aint change(char qipan[20][80],int zuobiao[2][80],char direction);\x0d\x0azuobiao[0][tail]=1;zuobiao[1][tail]=1;zuobiao[0][1]=1;zuobiao[1][1]=2;zuobiao[0][2]=1;zuobiao[1][2]=3;zuobiao[0][head]=1;zuobiao[1][head]=4;\x0d\x0a/处理棋盘/\x0d\x0achar qipan[20][80];//定义棋盘\x0d\x0afor(i=0;i<20;i++)\x0d\x0a for(j=0;j<80;j++)\x0d\x0aqipan[i][j]=' ';//初始化棋盘\x0d\x0afor(i=0;i<80;i++)\x0d\x0aqipan[0][i]='_';\x0d\x0afor(i=0;i<20;i++)\x0d\x0aqipan[i][0]='|';\x0d\x0afor(i=0;i<20;i++)\x0d\x0aqipan[i][79]='|';\x0d\x0afor(i=0;i<80;i++)\x0d\x0aqipan[19][i]='_';\x0d\x0aqipan[1][1]=qipan[1][2]=qipan[1][3]='';//初始化蛇的位置\x0d\x0aqipan[1][4]='#';\x0d\x0aprintf("This is a of a SNAKE.\nGOOD LUCK TO YOU !\n");\x0d\x0aprintf("Input your speed,please.(e.g.300)\n");\x0d\x0ascanf("%d",&speed);\x0d\x0a\x0d\x0awhile(direction!='q')\x0d\x0a{\x0d\x0a("cls");\x0d\x0afor(i=0;i<20;i++)//打印出棋盘\x0d\x0afor(j=0;j<80;j++)\x0d\x0aprintf("%c",qipan[i][j]);\x0d\x0atimeover=1;\x0d\x0astart=clock();\x0d\x0awhile(!kbhit()&&(timeover=clock()-start<=speed));\x0d\x0aif(timeover)\x0d\x0a{\x0d\x0agetch();\x0d\x0adirection=getch();\x0d\x0a}\x0d\x0aelse\x0d\x0adirection=direction;\x0d\x0aif(!(direction==72||direction==80||direction==75||direction==77))\x0d\x0a{\x0d\x0areturn 0;\x0d\x0a("cls");\x0d\x0aprintf("GAME OVER!\n");\x0d\x0a}\x0d\x0aif(!change(qipan,zuobiao,direction))\x0d\x0a{\x0d\x0adirection='q';\x0d\x0a("cls");\x0d\x0aprintf("GAME OVER!\n");\x0d\x0a}\x0d\x0a}\x0d\x0areturn 0;\x0d\x0a}\x0d\x0aint change(char qipan[20][80],int zuobiao[2][80],char direction)\x0d\x0a{\x0d\x0aint x,y;\x0d\x0aif(direction==72)\x0d\x0ax=zuobiao[0][head]-1;y=zuobiao[1][head];\x0d\x0aif(direction==80)\x0d\x0ax=zuobiao[0][head]+1;y=zuobiao[1][head];\x0d\x0aif(direction==75)\x0d\x0ax=zuobiao[0][head];y=zuobiao[0][head]-1;\x0d\x0aif(direction==77)\x0d\x0ax=zuobiao[0][head];y=zuobiao[1][head]+1;\x0d\x0aif(x==0||x==18||y==78||y==0)\x0d\x0areturn 0;\x0d\x0aif(qipan[x][y]!=' ')\x0d\x0areturn 0;\x0d\x0aqipan[zuobiao[0][tail]][zuobiao[1][tail]]=' ';\x0d\x0atail=(tail+1)%80;\x0d\x0aqipan[zuobiao[0][head]][zuobiao[1][head]]='';\x0d\x0ahead=(head+1)%80;\x0d\x0azuobiao[0][head]=x;\x0d\x0azuobiao[1][head]=y;\x0d\x0aqipan[zuobiao[0][head]][zuobiao[1][head]]='#';\x0d\x0areturn 1;\x0d\x0a}

c 好玩的代码(c好玩的代码)


谁有c语言一些运行起来结果很好玩的程序的代码..

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

C下才能编译成功

空格:打标记

回车:扫雷

方向键:改变方向

/

#include

#include

#include

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=&xy1=&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();

}

}

}

用C语言编写的小游戏代码是什么?

/贪吃蛇/

#include

#include

#include

#include

inthead=3,tail=0;

intmain()

{

inti,j,k=0;

intzuobiao[2][80];

longstart;

intdirection=77;

intspeed;

inttimeover;

intchange(charqipan[20][80],

intzuobiao[2][80],

chardirection);

zuobiao[0][tail]=1;

zuobiao[1][tail]=1;

zuobiao[0][1]=1;

zuobiao[1][1]=2;zuobiao[0

[2]=1;

zuobiao[1][2]=3;

zuobiao[0][head]=1;

zuobiao[1][head]=4;

/处理棋盘/

charqipan[20][80];

//定义棋盘

for(i=0;i<20;i++)

for(j=0;j<80;j++)

qipan[i][j]='';//初始化棋盘

for(i=0;i<80;i++)

qipan[0][i]='_';

for(i=0;i<20;i++)

qipan[i][0]='|';

for(i=0;i<20;i++)

qipan[i][79]='|';

for(i=0;i<80;i++)

C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。

有什么好玩的C语言小程序

觉的这个怎么样啊?

/a finger-guessing /

#include

#include

main()

{

char ch;

char artificial;

int random;

while (1)/如果不退出,则永远玩游戏/

{

srand(time(NULL));/使rand随机而不重复/

printf("Please input one case you want to put:\n(A/a:stone;B/b:cloth;C/c:forfex;Q/q:quit)\n");

artificial=getch();

if(artificial=='q'||artificial=='Q')

exit(0);/游戏循环出口/

if(artificial!='A'&&artificial!='B'&&artificial!='C'&&artificial!='a'&&artificial!='b'&&artificial!='c')

continue;/其他字母全部跳过/

if(artificial=='A'||artificial=='a')

printf("You put out stone.\n");

if(artificial=='B'||artificial=='b')

printf("You put out cloth.\n");

if(artificial=='C'||artificial=='c')

printf("You put out forfex.\n");

random=rand()%3+1;

switch(random)

{

case 1:/这是电脑出石头的情况/

printf("I put out stone.\n");

if(artificial=='A'||artificial=='a')

{

printf("Ah,We are the same.\n");/如果一样,继续/

continue;

}

if(artificial=='B'||artificial=='b')

{

printf("Oh,you are perfect!You he won!");

printf("\nDo you want to play again?y/n\n");/判断是否继续游戏/

ch=getch();

if(ch=='y')

continue;

else exit(0);

}

if(artificial=='C'||artificial=='c')

{

printf("Ah,ha!I won!");

printf("\nDo you want to play again?y/n\n");

ch=getch();

if(ch=='y')

continue;

else exit(0);

}

case 2:/电脑出布的情况处理/

printf("I put out cloth.\n");

if(artificial=='B'||artificial=='b')

{

printf("Ah,We are the same.\n");

continue;

}

if(artificial=='C'||artificial=='c')

{

printf("Oh,you are perfect!You he won!");

printf("\nDo you want to play again?y/n\n");

ch=getch();

if(ch=='y')

continue;

else exit(0);

}

if(artificial=='A'||artificial=='a')

{

printf("Ah,ha!I won!");

printf("\nDo you want to play again?y/n\n");

ch=getch();

if(ch=='y')

continue;

else exit(0);

}

case 3:/电脑出剪刀的情况处理/

printf("I put out forfex.\n");

if(artificial=='C'||artificial=='c')

{

printf("Ah,We are the same.\n");

continue;

}

if(artificial=='B'||artificial=='b')

{

printf("Ah,ha!I won!");

printf("\nDo you want to play again?y/n\n");

ch=getch();

if(ch=='y')

continue;

else exit(0);

}

if(artificial=='A'||artificial=='a')

{

printf("Oh,you are perfect!You he won!");

printf("\nDo you want to play again?y/n\n");

ch=getch();

if(ch=='y')

continue;

else exit(0);

}

}

}

getch();

}

希望可以帮到你,谢谢!

用C语言编写的小游戏代码是什么?

/也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++6.0、turbo…………)上都能运行,你还可以进一步改进。这是一个类似贪吃蛇的小游戏。祝你好运/

/贪吃蛇/

#include

#include

#include

#include

int head=3 ,tail=0;

int main()

{

int i,j,k=0;

int zuobiao[2][80];

long start;

int direction=77;

int speed;

int timeover;

int change(char qipan[20][80],int zuobiao[2][80],char direction);

zuobiao[0][tail]=1;zuobiao[1][tail]=1;zuobiao[0][1]=1;zuobiao[1][1]=2;zuobiao[0][2]=1;zuobiao[1][2]=3;zuobiao[0][head]=1;zuobiao[1][head]=4;

/处理棋盘/

char qipan[20][80];//定义棋盘

for(i=0;i<20;i++)

for(j=0;j<80;j++)

qipan[i][j]=' ';//初始化棋盘

for(i=0;i<80;i++)

qipan[0][i]='_';

for(i=0;i<20;i++)

qipan[i][0]='|';

for(i=0;i<20;i++)

qipan[i][79]='|';

for(i=0;i<80;i++)

qipan[19][i]='_';

qipan[1][1]=qipan[1][2]=qipan[1][3]='';//初始化蛇的位置

qipan[1][4]='#';

printf("This is a of a SNAKE.\nGOOD LUCK TO YOU !\n");

printf("Input your speed,please.(e.g.300)\n");

scanf("%d",&speed);

while(direction!='q')

{

("cls");

for(i=0;i<20;i++)//打印出棋盘

for(j=0;j<80;j++)

printf("%c",qipan[i][j]);

timeover=1;

start=clock();

while(!kbhit()&&(timeover=clock()-start<=speed));

if(timeover)

{

getch();

direction=getch();

}

else

direction=direction;

if(!(direction==72||direction==80||direction==75||direction==77))

{

return 0;

("cls");

printf("GAME OVER!\n");

}

if(!change(qipan,zuobiao,direction))

{

direction='q';

("cls");

printf("GAME OVER!\n");

}

}

return 0;

}

int change(char qipan[20][80],int zuobiao[2][80],char direction)

{

int x,y;

if(direction==72)

x=zuobiao[0][head]-1;y=zuobiao[1][head];

if(direction==80)

x=zuobiao[0][head]+1;y=zuobiao[1][head];

if(direction==75)

x=zuobiao[0][head];y=zuobiao[0][head]-1;

if(direction==77)

x=zuobiao[0][head];y=zuobiao[1][head]+1;

if(x==0||x==18||y==78||y==0)

return 0;

if(qipan[x][y]!=' ')

return 0;

qipan[zuobiao[0][tail]][zuobiao[1][tail]]=' ';

tail=(tail+1)%80;

qipan[zuobiao[0][head]][zuobiao[1][head]]='';

head=(head+1)%80;

zuobiao[0][head]=x;

zuobiao[1][head]=y;

qipan[zuobiao[0][head]][zuobiao[1][head]]='#';

return 1;

}

求几C语言个小游戏代码,简单的,要注释、、谢谢了、

// Calcu24.cpp : Defines the entry point for the console application.

//

/

6-6

24点游戏

/

#include "conio.h"

#include "stdlib.h"

#include "time.h"

#include "math.h"

#include "string.h"/

从一副扑克牌中,任取4张。

2-10 按其点数计算(为了表示方便10用T表示),J,Q,K,A 统一按 1 计算

要求通过加减乘除四则运算得到数字 24。

本程序可以随机抽取纸牌,并用试探法求解。

/void GivePuzzle(char buf)

{

char card[] = {'A','2','3','4','5','6','7','8','9','T','J','Q','K'}; for(int i=0; i<4; i++){

buf[i] = card[rand() % 13];

}

}

void shuffle(char buf)

{

for(int i=0; i<5; i++){

int k = rand() % 4;

char t = buf[k];

buf[k] = buf[0];

buf[0] = t;

}

}

int GetCardValue(int c)

{

if(c=='T') return 10;

if(c>='0' && c<='9') return c - '0';

return 1;

}

char GetOper(int n)

{

switch(n)

{

case 0:

return '+';

case 1:

return '-';

case 2:

return '';

case 3:

return '/';

} return ' ';

}double MyCalcu(double op1, double op2, int oper)

{

switch(oper)

{

case 0:

return op1 + op2;

case 1:

return op1 - op2;

case 2:

return op1 op2;

case 3:

if(fabs(op2)>0.0001)

return op1 / op2;

else

return 100000;

} return 0;

}

void MakeAnswer(char answer, int type, char question, int oper)

{

char p[4][3];

for(int i=0; i<4; i++)

{

if( question[i] == 'T' )

strcpy(p[i], "10");

else

sprintf(p[i], "%c", question[i]);

}

switch(type)

{

case 0:

sprintf(answer, "%s %c (%s %c (%s %c %s))",

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

case 1:

sprintf(answer, "%s %c ((%s %c %s) %c %s)",

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

case 2:

sprintf(answer, "(%s %c %s) %c (%s %c %s)",

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

case 3:

sprintf(answer, "((%s %c %s) %c %s) %c %s",

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

case 4:

sprintf(answer, "(%s %c (%s %c %s)) %c %s",

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

}

}

bool TestResolve(char question, int oper, char answer)

{

// 等待考生完成

int type[5]={0,1,2,3,4};//计算类型

double p[4];

double sum=0;

//

for(int i=0; i<4; i++) //循环取得点数

{

p[i]=GetCardValue(int(question[i]));

} for(i=0;i<5;i++)

{

MakeAnswer(answer,type[i],question,oper); //获取可能的

switch(type[i])

{

case 0:

sum=MyCalcu(p[0],MyCalcu( p[1],MyCalcu(p[2], p[3], oper[2]),oper[1]),oper[0]); //A(B(cD))

break;

case 1:

sum=MyCalcu(p[0],MyCalcu(MyCalcu(p[1], p[2], oper[1]),p[3],oper[2]),oper[0]); //A((BC)D)

break;

case 2:

sum=MyCalcu(MyCalcu(p[0], p[1], oper[0]),MyCalcu(p[2], p[3], oper[2]),oper[1]); // (AB)(CD)

break;

case 3:

sum=MyCalcu(MyCalcu(MyCalcu(p[0], p[1], oper[0]),p[2],oper[1]),p[3],oper[2]); //((AB)C)D

break;

case 4:

sum=MyCalcu(MyCalcu(p[0],MyCalcu(p[1], p[2], oper[1]),oper[0]),p[3],oper[2]); //(A(BC))D

break;

}

if(sum==24) return true;

}

return false;

}

/

采用随机试探法:就是通过随机数字产生 加减乘除的 组合,通过大量的测试来命中的解法

提示:

1. 需要考虑用括号控制计算次序的问题 比如:( 10 - 4 ) ( 3 + A ), 实际上计算次序的数目是有限的:

A(B(cD))

A((BC)D)

(AB)(CD)

((AB)C)D

(A(BC))D

2. 需要考虑计算结果为分数的情况:( 3 + (3 / 7) ) 7

3. 题目中牌的位置可以任意交换

/

bool TryResolve(char question, char answer)

{

int oper[3]; // 存储运算符,0:加法 1:减法 2:乘法 3:除法

for(int i=0; i<1000 1000; i++)

{

// 打乱纸牌顺序

shuffle(question);

// 随机产生运算符

for(int j=0; j<3; j++)

oper[j] = rand() % 4; if( TestResolve(question, oper, answer) ) return true;

} return false;

}

int main(int argc, char argv[])

{

// 初始化随机种子

srand( (unsigned)time( NULL ) ); char buf1[4]; // 题目

char buf2[30]; // 解答

printf("\n");

printf("计算24\n");

printf("A J Q K 均按1计算,其它按牌点计算\n");

printf("目标是:通过四则运算组合出结果:24\n");

printf("\n\n");

for(;;)

{

GivePuzzle(buf1); // 出题

printf("题目:");

for(int j=0; j<4; j++){

if( buf1[j] == 'T' )

printf("10 ");

else

printf("%c ", buf1[j]);

} printf("\n按任意键参...\n");

getch(); if( TryResolve(buf1, buf2) ) // 解题

printf("参考:%s\n", buf2);

else

printf("可能是无解...\n"); printf("按任意键出下一题目,x 键退出...\n");

if( getch() == 'x' ) break;

} return 0;

}

一段女生写的C语言代码(搞笑)

#include "stdio.h"

#include "stdlib.h"

result love(boy, girl)

{

if ( boy.有房() and boy.有车() )

 {

boy.set(nothing);

return girl.嫁给(boy);

}

if ( girl.愿意等() )

{

 while( ! (boy.赚钱 > 100,000 and girl.感情 > 8 ) )

 {

for ( day=1; day <=365; day++)

{

 if ( day == 情人节 )

 if ( boy.givegirl(玫瑰) )

girl.感情++;

else

 girl.感情--;

  if( day == girl.生日)

 if ( boy.givegirl(玫瑰) )

girl.感情++;

else

girl.感情--;

boy.拼命赚钱();

  }

}

if ( boy.有房() and boy.有车() )

 {

boy.set(nothing);

 return girl.嫁给(boy);

 }

 年龄++;

 girl.感情--;

}

return girl.goto( another_boy); }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 12345678@qq.com 举报,一经查实,本站将立刻删除。

联系我们

工作日:9:30-18:30,节假日休息