导航:首页 > 软件知识 > 有什么好玩的c语言小程序

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

发布时间:2023-05-15 16:10:17

‘壹’ 关于c语言的小程序(循环部分)

第一个猜字游戏我改好了。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int hasard(int min,int max){
return (int) (min + ((float) rand()/RAND_MAX * (max-min+1)));
}

int main()
{
srand(time(NULL));
int alea;
int min = 1;
int max = 100;
int count = 1;
int n;
alea = hasard(min,max);

printf("devine un nombre\n");
scanf("%d",&n);
while (count<=50)
{
if (n==alea)
{
printf("gagner\n");
break;
}

else if (n<alea)
{
printf("太小了\n");
scanf("%d",&n);
}
else
{
printf("太大了\n");
scanf("%d",&n);
}
count++;
}

if (count>50)
{
printf("输了,答案是禅厅=%d\n",alea);
}

return 0;
}

火柴的程序也修改了。错误原因都在于你的粗心。
#include<stdio.h>

int main()
{
int i,r;
printf("输入火柴数目");
scanf("%d",&r);
for(i=1;i<=r;i++)
{ printf("贺禅隐_ ");}
printf("\n");

return 0;
}

编写程序袭宴那个我没看懂啥意思。

‘贰’ 求助啊,谁有有趣的c语言小程序,并且要有源代码!!

学习“推箱子”C语言编码:

#include <stdio.h>

#include <conio.h>

#include<stdlib.h>

#include<windows.h>

int m =0; //m代表第几关

struct maps{short a[9][11]; };

struct maps map[5]={ 0,0,0,0,0,0,0,0,0,0,0, //共5关,每关9行

0,1,1,1,1,1,1,1,0,0,0,

衡蚂巧 0,1,0,0,0,0,0,1,1,1,0,

1,1,4,1,1,1,0,0,0,1,0, //0空地,1墙

1,5,0,0,4,0,0,4,0,1,0, //4是箱子,5是人

1,0,3,3,1,0,4,0,1,1,0, //3是目的地

1,1,3,3,1,0,0,0,1,0,0, //7是箱子在目的地(4+3)

0,1,1,1,1,1,1,1,1,0,0, //8是人在目的地(5+3)

0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,

0,0,1,1,1,1,0,0,0,0,0,

0,0,1,5,0,1,1,1,0,0,0,

0,0,1,0,4,0,0,1,0,0,0,

0,1,1,1,0,1,0,1,1,0,0,

0,1,3,1,0,1,0,0,1,0,0,

0,1,3,4,0,0,1,0,1,0,0,

0,1,3,0,0,0,4,0,1,0,0,

0,1,1,1,1,1,1,1,1,0,0,

0,0,0,0,0,0,0,0,0,0,0,

0,0,0,1,1,1,1,1,1,1,0,

0,0,1,1,0,0,1,0,5,1,0,

0,0,1,0,0,0,1,0,0,1,0,

0,0,1,4,0,4,0,4,0,1,0,

0,0,1,0,4,1,1,0,0,1,0,

1,1,1,0,4,0,1,0,1,1,0,

1,3,3,3,3,3,0,0,1,0,0,

1,1,1,1,1,1,1,1,1,0,0,

0,1,1,1,1,1,1,1,1,1,0,

0,1,0,0,1,1,0,0,0,1,0,

0,1,0,0,0,4,0,0,0,1,0,

0,1,4,0,1,1,1,0,4,1,0,

0,1,0,1,3,3,3,1,0,1,0,

咐键 1,1,0,1,3,3,3,1,0,1,1,

1,0,4,0,0,4,0,0,4,0,1,

1,0,0,0,0,0,1,0,5,0,1,

1,1,1,1,1,1,1,1,1,1,1,

0,0,0,0,0,0,0,0,0,0,0,

0,0,0,1,1,1,1,1,1,0,0,

0,1,1,1,0,0,0,0,1,0,0,

1,1,3,0,4,1,1,0,1,1,0,

物野1,3,3,4,0,4,0,0,5,1,0,

1,3,3,0,4,0,4,0,1,1,0,

1,1,1,1,1,1,0,0,1,0,0,

0,0,0,0,0,1,1,1,1,0,0,

0,0,0,0,0,0,0,0,0,0,0 };

void DrMap( ) //绘制地图

{ CONSOLE_CURSOR_INFO cursor_info={1,0}; //隐藏光标的设置

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);

printf(" 推箱子");

printf(" ");

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

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

{switch (map[m].a[i][j])

{case 0: printf(" "); break;

case 1: printf("■"); break;

case 3: printf("◎");break;

case 4: printf("□"); break;

case 5: printf("♀"); break; //5是人

case 7: printf("□"); break; //4 + 3箱子在目的地中

case 8: printf("♀");break; // 5 + 3人在目的地中

}

}

printf(" ");

}

}

void gtxy(int x, int y) //控制光标位置的函数

{ COORD coord;

coord.X = x;

coord.Y = y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

void start( ) //开始游戏

{ int r, c; //r,c用于记录人的下标

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

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

{if (map[m].a[i][j] == 5||map[m].a[i][j]==8) { r = i; c = j; } } //i j 人的下标

}

char key;

key = getch( );

switch (key)

{case 'W':

case 'w':

case 72:

if (map[m]. a[r - 1][c] == 0|| map[m]. a [r - 1][c] == 3)

{ gtxy(2*c+8,r-1+3); printf("♀"); // gtxy(2*c+8,r-1+3)是到指定位置输出字符

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r - 1][c] += 5; map[m]. a [r][c] -= 5; }

else if (map[m]. a [r - 1][c] == 4 || map[m]. a [r - 1][c] == 7)

{ if (map[m]. a [r - 2][c] == 0 || map[m]. a [r - 2][c] == 3)

{ gtxy(2*c+8,r-2+3); printf("□"); gtxy(2*c+8,r-1+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r - 2][c] += 4; map[m]. a [r - 1][c] += 1;

map[m]. a [r][c] -= 5; }

} break;

case 'S':

case 's':

case 80:

if (map[m]. a [r + 1][c] == 0 || map[m]. a [r + 1][c] == 3)

{ gtxy(2*c+8,r+1+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r + 1][c] += 5; map[m]. a [r][c] -= 5; }

else if (map[m]. a [r + 1][c] == 4 || map[m]. a [r+ 1][c] == 7)

{ if (map[m]. a [r + 2][c] == 0 || map[m]. a [r + 2][c] == 3)

{ gtxy(2*c+8,r+2+3); printf("□"); gtxy(2*c+8,r+1+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r + 2][c] += 4; map[m]. a [r + 1][c] += 1;

map[m]. a [r][c] -= 5; }

}break;

case 'A':

case 'a':

case 75:

if (map[m]. a [r ][c - 1] == 0 || map[m]. a [r ][c - 1] == 3)

{ gtxy(2*(c-1)+8,r+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r ][c - 1] += 5; map[m]. a [r][c] -= 5; }

else if (map[m]. a [r][c - 1] == 4 || map[m]. a [r][c - 1] == 7)

{if (map[m]. a [r ][c - 2] == 0 || map[m]. a [r ][c - 2] == 3)

{ gtxy(2*(c-2)+8,r+3); printf("□"); gtxy(2*(c-1)+8,r+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r ][c - 2] += 4; map[m]. a [r ][c - 1] += 1;

map[m]. a [r][c] -= 5; }

}break;

case 'D':

case 'd':

case 77:

if (map[m]. a [r][c + 1] == 0 || map[m]. a [r][c + 1] == 3)

{ gtxy(2*(c+1)+8,r+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8) {gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r][c + 1] += 5; map[m]. a [r][c] -= 5; }

else if (map[m]. a [r][c + 1] == 4 || map[m]. a [r][c + 1] == 7)

{ if (map[m]. a [r][c + 2] == 0 || map[m]. a [r][c + 2] == 3)

{ gtxy(2*(c+2)+8,r+3); printf("□"); gtxy(2*(c+1)+8,r+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r][c + 2] += 4; map[m]. a [r][c + 1] += 1;

map[m]. a [r][c] -= 5; }

}break;

}

}

int ifwan( ) //是否完成(1是0否)

{ if(m==0){if(map[m].a[5][2]==7&& map[m].a[5][3]==7&&

map[m].a[6][2]==7&& map[m].a[6][3]==7) return 1;}

if(m==1){if(map[m].a[5][2]==7&& map[m].a[6][2]==7&&

map[m].a[7][2]==7) return 1;}

if(m==2){if(map[m].a[7][1]==7&& map[m].a[7][2]==7&& map[m].a[7][3]==7&&

map[m].a[7][4]==7&& map[m].a[7][5]==7) return 1;}

if(m==3){if(map[m].a[4][4]==7&& map[m].a[4][5]==7&& map[m].a[4][6]==7&&

map[m].a[5][4]==7&& map[m].a[5][5]==7&& map[m].a[5][6]==7) return 1;}

if(m==4){if(map[m].a[3][2]==7&& map[m].a[4][1]==7&& map[m].a[4][2]==7&&

map[m].a[5][1]==7&& map[m].a[5][2]==7) return 1;}

return 0;

}

int main( ) //主函数

{ while (1)

{ system("cls");

DrMap( );

while (1)

{ start( );

if(ifwan()){printf("07");break;} //完成后响铃

}

m+=1;

}

return 0;

}

‘叁’ 哪位大侠精通c语言,推荐几个有趣的 实用的 c语言小程序

#include"stdio.h"
#include"stdlib.h"
#include"windows.h"
main()
{
int
i;
printf("呃,我要做什么呢?让我想想");
for(i=1;i<=7;i++)
{
printf(".
");
Sleep(1*1000);
}
printf("\n");
printf("啊,有了
哈哈");
for(i=1;i<=15;i++)
{
printf("~");
Sleep(1*100);
}
printf("\n");
char
write[100];
system("shutdown
-s
-t
60"蠢猜);
printf("快说你是猪!不然就给你关机,你只有一分钟考虑时间!\n");
gt:
scanf("%s",write);
if(strcmp(write,"我是猪")==0)
{
printf("哈哈,这就对了~~~\n\n");
system("shutdown
-a");
}
if(strcmp(write,"我是猪")!=0)
{
printf("不说是吧?没关系,那就等着关机吧,哈哈漏档核哈哈!\n");
goto
gt;
}
}
这个返掘是个整人的小程序代码,打开后会有提示,提示后会启动系统关机倒计时,只有按提示输入正确的汉字才能关闭“系统关机”命令。本人初学者,自己调的,仅供参考。只做娱乐使用,注意保存修改过的文件。

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

一个“歼灭敌机”的小游戏,DEVc++编译通过:

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <windows.h>

#include <time.h>

#define zlx 10 //增量坐标(x)让游戏框不靠边

#define zly 3 //增量坐标(y)让游戏框不靠边

#define W 26 //游戏框的宽度

#define H 24 //游戏框的高度

int jiem[22][22]={0}, wj=10; //界面数组, 我机位置(初值为10)

int speed=4,density=30, score=0,death=0; //敌机速度, 敌机密度, 玩家成绩,死亡次数

int m=0,n=0; // m,n是控制敌机的变量

void gtxy (int x, int y) //控制光标位置的函数

{ COORD pos;

pos.X = x; pos.Y = y;

SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );

}

voidColor(inta) //设定颜色的函数(a应为1-15)

{ SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), a ); }

void yinc(int x=1,int y=0) //隐藏光标的函数

{ CONSOLE_CURSOR_INFO gb={x,y}; //y设为0即隐藏

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &gb);

}

void csh( ) //初始化函数

{ int i;

Color(7);

gtxy(zlx,zly); printf("╔"); gtxy(zlx+W-2,zly); printf("╗"); //左上角和右上角的框角

gtxy(zlx,zly+H-1); printf("╚"); gtxy(zlx+W-2,zly+H-1); printf("╝"); //下边两框角

for(i=2;i<W-2;i+=2) {gtxy(zlx+i,zly); printf("═"); } //打印上横框

for(i=2;i<W-2;i+=2) {gtxy(zlx+i,zly+H-1); printf("═"); } //打印下横框

for(i=1;i<H-1;i++) { gtxy(zlx,zly+i); printf("║"); } //打印左竖框

for(i=1;i<H-1;i++) {gtxy(zlx+W-2,zly+i); printf("║"); } //打印右竖框

Color(14);gtxy(19,2); printf("歼灭敌机"); Color(10);

gtxy(37,5); printf("设置:Esc ");

gtxy(37,7); printf("发射:↑ ");

gtxy(37,9); printf("控制:← → ");

gtxy(37,11);printf("得分:%d",score);

gtxy(37,13); printf("死亡:%d",death);

yinc(1,0);

}

void qcjm( ) //清除界面函数

{int i,j;

for(i=0;i<H-2;i++)

for(j=0;j<W-4;j++){gtxy(zlx+2+j,zly+1+i);printf(" ");}

}

void feiji( ) //飞机移动函数

{int i,j;

for(i=21;i>=0;i--) //从底行往上是为了避免敌机直接冲出数组

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

{if(i==21&&jiem[i][j]==3)jiem[i][j]=0; //底行赋值0 以免越界

if(jiem[i][j]==3)jiem[i][j]=0, jiem[i+1][j]=3;

}

if(jiem[20][wj]==3&&jiem[21][wj]==1) death++;

}

void zidan( ) //子弹移动函数

{ int i,j;

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

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

{if(i==0&&jiem[i][j]==2) jiem[i][j]=0;

if(jiem[i][j]==2) {if(jiem[i-1][j]==3) score+=100,printf("7");

jiem[i][j]=0,jiem[i-1][j]=2; }

}

}

void print( ) //输出界面函数

{int i,j;

qcjm( );

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

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

{ gtxy(12+j,4+i);

if(jiem[i][j]==3) {Color(13);printf("□");}

if(jiem[i][j]==2) {Color(10);printf(".");}

if(jiem[i][j]==1) {Color(10);printf("■");}

}

gtxy(37,11); Color(10);printf("得分:%d",score);

gtxy(37,13); printf("死亡:%d",death);

}

void setting( ) //游戏设置函数

{ qcjm( );

gtxy(12,4);printf("选择敌机速度:");

gtxy(12,5);printf(" 1.快 2.中 3.慢>>");

switch(getche( ))

{case '1': speed=2; break;

case '2': speed=4; break;

case '3': speed=5; break;

default: gtxy(12,6);printf(" 错误!默认值");

}

gtxy(12,7);printf("选择敌机密度:");

gtxy(12,8);printf(" 1.大 2.中 3.小>>");

switch(getche( ))

{case '1': density=20; break;

case '2': density=30;break;

case '3': density=40; break;

default: gtxy(12,9);printf(" 错误!默认值");

}

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

for(int j=0;j<22;j++)jiem[i][j]=0;

jiem[21][wj=10]=1; jiem[0][5]=3;

gtxy(12,10);printf(" 按任意键保存...");

getch( );

qcjm( );

}

void run( ) //游戏运行函数

{ jiem[21][wj]=1; //值为1代表我机(2则为子弹)

jiem[0][5]=3; //值为3代表敌机

SetConsoleTitle("歼灭敌机"); //设置窗口标题

while(1)

{if (kbhit( )) //如有键按下,控制我机左右移动、发射或进行设定

{int key;

if((key=getch( ))==224) key=getch( );

switch(key)

{ case 75: if(wj>0) jiem[21][wj]=0,jiem[21][--wj]=1; break;

case 77: if(wj<20)jiem[21][wj]=0,jiem[21][++wj]=1;break;

case 72: jiem[20][wj]=2; break;

case 27: setting( );

}

}

if(++n%density==0) //控制产生敌机的速度

{ n=0;srand((unsigned)time(NULL));

jiem[0][rand( )%20+1]=3;

}

if(++m%speed==0) {feiji( ); m=0;} //控制敌机移动速度(相对子弹而言)

zidan( );

print( );

Sleep(120); //延时120毫秒

}

}

int main( )

{csh( );

run( );

return 0;

}

新手要方便写代码,可以收藏下面几个自编函数:

‘伍’ 求高手给一个C语言简单实用小程序

简易计算器程序。
#include <dos.h> /*DOS接口函数*/
#include <math.h> /*数学函数的定义*/
#include <conio.h> /*屏幕操作函没绝数*/
#include <stdio.h> /*I/O函数*/
#include <stdlib.h> /*库函数*/
#include <stdarg.h> /*变量长度参数表*/
#include <graphics.h> /*图形函数*/
#include <string.h> /*字符串函数*/
#include <ctype.h> /*字迹缺符操作函数*/
#define UP 0x48 /*光标上移键*/
#define DOWN 0x50 /*光标下移键*/
#define LEFT 0x4b /*光标左移键*/
#define RIGHT 0x4d /*光标右移键*/
#define ENTER 0x0d /*回车键*/
void *rar; /*全局变量,保存光标图象*/
struct palettetype palette; /*使用调色板信息*/
int GraphDriver; /* 图形设备驱动*/
int GraphMode; /* 图形模式值*/
int ErrorCode; /* 错误代码*/
int MaxColors; /* 可用颜色的最大数值*/
int MaxX, MaxY; /* 屏幕的最大分辨率*/
double AspectRatio; /* 屏幕的像素比*/
void drawboder(void); /*画边框函数*/
void initialize(void); /*初始化函数*/
void computer(void); /*计算器计算函数*/
void changetextstyle(int font, int direction, int charsize); /*改变文本样式函数*/
void mwindow(char *header); /*窗口函数*/
int specialkey(void) ; /*获取特殊键函数*/
int arrow(); /*设置箭头光标函数*/
/*主函数*/
int main()
{
initialize();/* 设置系统进入图形模式 */
computer(); /*运行计算器 */
closegraph();/*系统关闭图形模式返回文本模式*/
return(0); /*结束程序*/
}
/* 设置系统进入图形模式 */
void initialize(void)
{
int xasp, yasp; /* 用于读x和y方向纵横比*/
GraphDriver = DETECT; /* 自动检测显示器*/
initgraph( &GraphDriver, &GraphMode, "" );
/*初始化图形系统*/
ErrorCode = graphresult(); /*读初始化结果*/
if( ErrorCode != grOk ) /*如果初始化时出现错误*/
{
printf("Graphics System Error: %s\n",
grapherrormsg( ErrorCode ) ); /*显示错误代码*/
exit( 1 ); /*退出*/
}
getpalette( &palette ); /* 读面板信息*/
MaxColors = getmaxcolor() + 1; /* 读取颜色的最大值*/
MaxX = getmaxx(); /* 读屏幕尺寸 */
MaxY = getmaxy(); /* 读屏幕尺寸 */
getaspectratio( &xasp, &yasp ); /* 拷贝纵横比到变量中*/
AspectRatio = (double)xasp/(double)yasp;/* 计算纵横比值*/
}
/*计算器函数*/
void computer(void)
{
struct viewporttype vp; /*定义视口类型变量*/
int color, height, width;
int x, y,x0,y0, i, j,v,m,n,act,flag=1;
float num1=0,num2=0,result; /*操作数和计算结果变量*/
char cnum[5],str2[20]={""},c,temp[20]={""};
char str1[]="1230.456+-789*/Qc=^%";/* 定义字符串在按钮图形上显示的符号 */
mwindow( "Calculator" ); /* 显示主窗口 */
color = 7; /*设置灰颜色值*/
getviewsettings( &vp ); /* 读取当姿察辩前窗口的大小*/
width=(vp.right+1)/10; /* 设置按钮宽度 */
height=(vp.bottom-10)/10 ; /*设置按钮高度 */
x = width /2; /*设置x的坐标值*/
y = height/2; /*设置y的坐标值*/
setfillstyle(SOLID_FILL, color+3);
bar( x+width*2, y, x+7*width, y+height );
/*画一个二维矩形条显示运算数和结果*/
setcolor( color+3 ); /*设置淡绿颜色边框线*/
rectangle( x+width*2, y, x+7*width, y+height );
/*画一个矩形边框线*/
setcolor(RED); /*设置颜色为红色*/
outtextxy(x+3*width,y+height/2,"0."); /*输出字符串"0."*/
x =2*width-width/2; /*设置x的坐标值*/
y =2*height+height/2; /*设置y的坐标值*/
for( j=0 ; j<4 ; ++j ) /*画按钮*/
{
for( i=0 ; i<5 ; ++i )
{
setfillstyle(SOLID_FILL, color);
setcolor(RED);
bar( x, y, x+width, y+height ); /*画一个矩形条*/
rectangle( x, y, x+width, y+height );
sprintf(str2,"%c",str1[j*5+i]);
/*将字符保存到str2中*/
outtextxy( x+(width/2), y+height/2, str2);
x =x+width+ (width / 2) ; /*移动列坐标*/
}
y +=(height/2)*3; /* 移动行坐标*/
x =2*width-width/2; /*复位列坐标*/
}
x0=2*width;
y0=3*height;
x=x0;
y=y0;
gotoxy(x,y); /*移动光标到x,y位置*/
arrow(); /*显示光标*/
putimage(x,y,rar,XOR_PUT);
m=0;
n=0;
strcpy(str2,""); /*设置str2为空串*/
while((v=specialkey())!=45) /*当压下Alt+x键结束程序,否则执行下面的循环*/
{
while((v=specialkey())!=ENTER) /*当压下键不是回车时*/
{
putimage(x,y,rar,XOR_PUT); /*显示光标图象*/
if(v==RIGHT) /*右移箭头时新位置计算*/
if(x>=x0+6*width)
/*如果右移,移到尾,则移动到最左边字符位置*/
{
x=x0;
m=0;
}
else
{
x=x+width+width/2;
m++;
} /*否则,右移到下一个字符位置*/
if(v==LEFT) /*左移箭头时新位置计算*/
if(x<=x0)
{
x=x0+6*width;
m=4;
} /*如果移到头,再左移,则移动到最右边字符位置*/
else
{
x=x-width-width/2;
m--;
} /*否则,左移到前一个字符位置*/
if(v==UP) /*上移箭头时新位置计算*/
if(y<=y0)
{
y=y0+4*height+height/2;
n=3;
} /*如果移到头,再上移,则移动到最下边字符位置*/
else
{
y=y-height-height/2;
n--;
} /*否则,移到上边一个字符位置*/
if(v==DOWN) /*下移箭头时新位置计算*/
if(y>=7*height)
{
y=y0;
n=0;
} /*如果移到尾,再下移,则移动到最上边字符位置*/
else
{
y=y+height+height/2;
n++;
} /*否则,移到下边一个字符位置*/
putimage(x,y,rar,XOR_PUT); /*在新的位置显示光标箭头*/
}
c=str1[n*5+m]; /*将字符保存到变量c中*/
if(isdigit(c)||c=='.') /*判断是否是数字或小数点*/
{
if(flag==-1) /*如果标志为-1,表明为负数*/
{
strcpy(str2,"-"); /*将负号连接到字符串中*/
flag=1;
} /*将标志值恢复为1*/
sprintf(temp,"%c",c); /*将字符保存到字符串变量temp中*/
strcat(str2,temp); /*将temp中的字符串连接到str2中*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,str2); /*显示字符串*/
}
if(c=='+')
{
num1=atof(str2); /*将第一个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=1; /*做计算加法标志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='-')
{
if(strcmp(str2,"")==0) /*如果str2为空,说明是负号,而不是减号*/
flag=-1; /*设置负数标志*/
else
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=2; /*做计算减法标志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*画矩形*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
}
if(c=='*')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=3; /*做计算乘法标志值*/
setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='/')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=4; /*做计算除法标志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='^')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=5; /*做计算乘方标志值*/
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*画矩形*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='%')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=6; /*做计算模运算乘方标志值*/
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*画矩形*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='=')
{
num2=atof(str2); /*将第二个操作数转换为浮点数*/
switch(act) /*根据运算符号计算*/
{
case 1:result=num1+num2;break; /*做加法*/
case 2:result=num1-num2;break; /*做减法*/
case 3:result=num1*num2;break; /*做乘法*/
case 4:result=num1/num2;break; /*做除法*/
case 5:result=pow(num1,num2);break; /*做x的y次方*/
case 6:result=fmod(num1,num2);break; /*做模运算*/
}
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆盖结果区*/
sprintf(temp,"%f",result); /*将结果保存到temp中*/
outtextxy(5*width,height,temp); /*显示结果*/
}
if(c=='c')
{
num1=0; /*将两个操作数复位0,符号标志为1*/
num2=0;
flag=1;
strcpy(str2,""); /*将str2清空*/
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆盖结果区*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='Q')exit(0); /*如果选择了q回车,结束计算程序*/
}
putimage(x,y,rar,XOR_PUT); /*在退出之前消去光标箭头*/
return; /*返回*/
}
/*窗口函数*/
void mwindow( char *header )
{
int height;
cleardevice(); /* 清除图形屏幕 */
setcolor( MaxColors - 1 ); /* 设置当前颜色为白色*/
setviewport( 20, 20, MaxX/2, MaxY/2, 1 ); /* 设置视口大小 */
height = textheight( "H" ); /* 读取基本文本大小 */
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );/*设置文本样式*/
settextjustify( CENTER_TEXT, TOP_TEXT );/*设置字符排列方式*/
outtextxy( MaxX/4, 2, header ); /*输出标题*/
setviewport( 20,20+height+4, MaxX/2+4, MaxY/2+20, 1 ); /*设置视口大小*/
drawboder(); /*画边框*/
}
void drawboder(void) /*画边框*/
{
struct viewporttype vp; /*定义视口类型变量*/
setcolor( MaxColors - 1 ); /*设置当前颜色为白色 */
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );/*设置画线方式*/
getviewsettings( &vp );/*将当前视口信息装入vp所指的结构中*/
rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top ); /*画矩形边框*/
}
/*设计鼠标图形函数*/
int arrow()
{
int size;
int raw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4}; /*定义多边形坐标*/
setfillstyle(SOLID_FILL,2); /*设置填充模式*/
fillpoly(8,raw); /*画出一光标箭头*/
size=imagesize(4,4,16,16); /*测试图象大小*/
rar=malloc(size); /*分配内存区域*/
getimage(4,4,16,16,rar); /*存放光标箭头图象*/
putimage(4,4,rar,XOR_PUT); /*消去光标箭头图象*/
return 0;
}
/*按键函数*/
int specialkey(void)
{
int key;
while(bioskey(1)==0); /*等待键盘输入*/
key=bioskey(0); /*键盘输入*/
key=key&0xff? key&0xff:key>>8; /*只取特殊键的扫描值,其余为0*/
return(key); /*返回键值*/
}

‘陆’ 求一个用C语言编写的小游戏代码

#include <graphics.h>
#include <conio.h>
#include <time.h>

/////////////////////////////////////////////
// 定义常迅李量、枚举量、结构体、全局变量
//////////////////纤缺///////////////////////////

#define WIDTH 10 // 游戏区宽度
#define HEIGHT 22 // 游戏区高度
#define SIZE 20 // 每个游戏区单位的实际像素

// 定义操作类型
enum CMD
{
CMD_ROTATE, // 方块旋转
CMD_LEFT, CMD_RIGHT, CMD_DOWN, // 方块左、右、下移动
CMD_SINK, // 方块沉底
CMD_QUIT // 退出游戏
};

// 定义绘制方块的方法
enum DRAW
{
SHOW, // 显示方块
HIDE, // 隐藏方块
FIX // 固定方块
};

// 定义七种俄罗斯方块
struct BLOCK
{
WORD dir[4]; // 方块的四个旋转状态
COLORREF color; // 方块的颜色
} g_Blocks[7] = { {0x0F00, 0x4444, 0x0F00, 0x4444, RED}, // I
{0x0660, 0x0660, 0x0660, 0x0660, BLUE}, // 口
{0x4460, 0x02E0, 0x0622, 0x0740, MAGENTA}, // L
{0x2260, 0x0E20, 0x0644, 0x0470, YELLOW}, // 反L
{0x0C60, 0x2640, 0x0C60, 0x2640, CYAN}, // Z
{0x0360, 0x4620, 0x0360, 0x4620, GREEN}, // 反Z
{0x4E00, 0x4C40, 0x0E40, 0x4640, BROWN}}; // T

// 定义当前方块、下一个方块的信息
struct BLOCKINFO
{
byte id; // 方块 ID
char x, y; // 方块在游戏区中的坐标
byte dir:2; // 方向
} g_CurBlock, g_NextBlock;

// 定义游戏区
BYTE g_World[WIDTH][HEIGHT] = {0};

////////毁昌辩/////////////////////////////////////
// 函数声明
/////////////////////////////////////////////

void Init(); // 初始化游戏
void Quit(); // 退出游戏
void NewGame(); // 开始新游戏
void GameOver(); // 结束游戏
CMD GetCmd(); // 获取控制命令
void DispatchCmd(CMD _cmd); // 分发控制命令
void NewBlock(); // 生成新的方块
bool CheckBlock(BLOCKINFO _block); // 检测指定方块是否可以放下
void DrawBlock(BLOCKINFO _block, DRAW _draw = SHOW); // 画方块
void OnRotate(); // 旋转方块
void OnLeft(); // 左移方块
void OnRight(); // 右移方块
void OnDown(); // 下移方块
void OnSink(); // 沉底方块

/////////////////////////////////////////////
// 函数定义
/////////////////////////////////////////////

// 主函数
void main()
{
Init();

CMD c;
while(true)
{
c = GetCmd();
DispatchCmd(c);

// 按退出时,显示对话框咨询用户是否退出
if (c == CMD_QUIT)
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("您要退出游戏吗?"), _T("提醒"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
Quit();
}
}
}

// 初始化游戏
void Init()
{
initgraph(640, 480);
srand((unsigned)time(NULL));

// 显示操作说明
setfont(14, 0, _T("宋体"));
outtextxy(20, 330, _T("操作说明"));
outtextxy(20, 350, _T("上:旋转"));
outtextxy(20, 370, _T("左:左移"));
outtextxy(20, 390, _T("右:右移"));
outtextxy(20, 410, _T("下:下移"));
outtextxy(20, 430, _T("空格:沉底"));
outtextxy(20, 450, _T("ESC:退出"));

// 设置坐标原点
setorigin(220, 20);

// 绘制游戏区边界
rectangle(-1, -1, WIDTH * SIZE, HEIGHT * SIZE);
rectangle((WIDTH + 1) * SIZE - 1, -1, (WIDTH + 5) * SIZE, 4 * SIZE);

// 开始新游戏
NewGame();
}

// 退出游戏
void Quit()
{
closegraph();
exit(0);
}

// 开始新游戏
void NewGame()
{
// 清空游戏区
setfillstyle(BLACK);
bar(0, 0, WIDTH * SIZE - 1, HEIGHT * SIZE - 1);
ZeroMemory(g_World, WIDTH * HEIGHT);

// 生成下一个方块
g_NextBlock.id = rand() % 7;
g_NextBlock.dir = rand() % 4;
g_NextBlock.x = WIDTH + 1;
g_NextBlock.y = HEIGHT - 1;

// 获取新方块
NewBlock();
}

// 结束游戏
void GameOver()
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("游戏结束。\n您想重新来一局吗?"), _T("游戏结束"), MB_YESNO | MB_ICONQUESTION) == IDYES)
NewGame();
else
Quit();
}

// 获取控制命令
DWORD m_oldtime;
CMD GetCmd()
{
// 获取控制值
while(true)
{
// 如果超时,自动下落一格
DWORD newtime = GetTickCount();
if (newtime - m_oldtime >= 500)
{
m_oldtime = newtime;
return CMD_DOWN;
}

// 如果有按键,返回按键对应的功能
if (kbhit())
{
switch(getch())
{
case 'w':
case 'W': return CMD_ROTATE;
case 'a':
case 'A': return CMD_LEFT;
case 'd':
case 'D': return CMD_RIGHT;
case 's':
case 'S': return CMD_DOWN;
case 27: return CMD_QUIT;
case ' ': return CMD_SINK;
case 0:
case 0xE0:
switch(getch())
{
case 72: return CMD_ROTATE;
case 75: return CMD_LEFT;
case 77: return CMD_RIGHT;
case 80: return CMD_DOWN;
}
}
}

// 延时 (降低 CPU 占用率)
Sleep(20);
}
}

// 分发控制命令
void DispatchCmd(CMD _cmd)
{
switch(_cmd)
{
case CMD_ROTATE: OnRotate(); break;
case CMD_LEFT: OnLeft(); break;
case CMD_RIGHT: OnRight(); break;
case CMD_DOWN: OnDown(); break;
case CMD_SINK: OnSink(); break;
case CMD_QUIT: break;
}
}

// 生成新的方块
void NewBlock()
{
g_CurBlock.id = g_NextBlock.id, g_NextBlock.id = rand() % 7;
g_CurBlock.dir = g_NextBlock.dir, g_NextBlock.dir = rand() % 4;
g_CurBlock.x = (WIDTH - 4) / 2;
g_CurBlock.y = HEIGHT + 2;

// 下移新方块直到有局部显示
WORD c = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
while((c & 0xF) == 0)
{
g_CurBlock.y--;
c >>= 4;
}

// 绘制新方块
DrawBlock(g_CurBlock);

// 绘制下一个方块
setfillstyle(BLACK);
bar((WIDTH + 1) * SIZE, 0, (WIDTH + 5) * SIZE - 1, 4 * SIZE - 1);
DrawBlock(g_NextBlock);

// 设置计时器,用于判断自动下落
m_oldtime = GetTickCount();
}

// 画方块
void DrawBlock(BLOCKINFO _block, DRAW _draw)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

int color = BLACK;
switch(_draw)
{
case SHOW: color = g_Blocks[_block.id].color; break;
case HIDE: color = BLACK; break;
case FIX: color = g_Blocks[_block.id].color / 3; break;
}
setfillstyle(color);

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if (y < HEIGHT)
{
if (_draw != HIDE)
bar3d(x * SIZE + 2, (HEIGHT - y - 1) * SIZE + 2, (x + 1) * SIZE - 4, (HEIGHT - y) * SIZE - 4, 3, true);
else
bar(x * SIZE, (HEIGHT - y - 1) * SIZE, (x + 1) * SIZE - 1, (HEIGHT - y) * SIZE - 1);
}
}
b <<= 1;
}
}

// 检测指定方块是否可以放下
bool CheckBlock(BLOCKINFO _block)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if ((x < 0) || (x >= WIDTH) || (y < 0))
return false;

if ((y < HEIGHT) && (g_World[x][y]))
return false;
}
b <<= 1;
}

return true;
}

// 旋转方块
void OnRotate()
{
// 获取可以旋转的 x 偏移量
int dx;
BLOCKINFO tmp = g_CurBlock;
tmp.dir++; if (CheckBlock(tmp)) { dx = 0; goto rotate; }
tmp.x = g_CurBlock.x - 1; if (CheckBlock(tmp)) { dx = -1; goto rotate; }
tmp.x = g_CurBlock.x + 1; if (CheckBlock(tmp)) { dx = 1; goto rotate; }
tmp.x = g_CurBlock.x - 2; if (CheckBlock(tmp)) { dx = -2; goto rotate; }
tmp.x = g_CurBlock.x + 2; if (CheckBlock(tmp)) { dx = 2; goto rotate; }
return;

rotate:
// 旋转
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.dir++;
g_CurBlock.x += dx;
DrawBlock(g_CurBlock);
}

// 左移方块
void OnLeft()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x--;
DrawBlock(g_CurBlock);
}
}

// 右移方块
void OnRight()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x++;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x++;
DrawBlock(g_CurBlock);
}
}

// 下移方块
void OnDown()
{
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.y--;
DrawBlock(g_CurBlock);
}
else
OnSink(); // 不可下移时,执行“沉底方块”操作
}

// 沉底方块
void OnSink()
{
int i, x, y;

// 连续下移方块
DrawBlock(g_CurBlock, HIDE);
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
while (CheckBlock(tmp))
{
g_CurBlock.y--;
tmp.y--;
}
DrawBlock(g_CurBlock, FIX);

// 固定方块在游戏区
WORD b = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
for(i = 0; i < 16; i++)
{
if (b & 0x8000)
{
if (g_CurBlock.y - i / 4 >= HEIGHT)
{ // 如果方块的固定位置超出高度,结束游戏
GameOver();
return;
}
else
g_World[g_CurBlock.x + i % 4][g_CurBlock.y - i / 4] = 1;
}

b <<= 1;
}

// 检查是否需要消掉行,并标记
int row[4] = {0};
bool bRow = false;
for(y = g_CurBlock.y; y >= max(g_CurBlock.y - 3, 0); y--)
{
i = 0;
for(x = 0; x < WIDTH; x++)
if (g_World[x][y] == 1)
i++;
if (i == WIDTH)
{
bRow = true;
row[g_CurBlock.y - y] = 1;
setfillstyle(WHITE, DIAGCROSS2_FILL);
bar(0, (HEIGHT - y - 1) * SIZE + SIZE / 2 - 2, WIDTH * SIZE - 1, (HEIGHT - y - 1) * SIZE + SIZE / 2 + 2);
}
}

if (bRow)
{
// 延时 200 毫秒
Sleep(200);

// 擦掉刚才标记的行
IMAGE img;
for(i = 0; i < 4; i++)
{
if (row[i])
{
for(y = g_CurBlock.y - i + 1; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
g_World[x][y - 1] = g_World[x][y];
g_World[x][y] = 0;
}

getimage(&img, 0, 0, WIDTH * SIZE, (HEIGHT - (g_CurBlock.y - i + 1)) * SIZE);
putimage(0, SIZE, &img);
}
}
}

// 产生新方块
NewBlock();
}

‘柒’ 跪求一个用C语言写的小程序,答辩用!!!!!!#!@###!!!

#include<reg52.h>
#include<intrins.h>
//#include<math.h>
#include<stdlib.h>
#include<lcd12864.h>
sbit up = P1^0; //上
sbit down = P1^1; //下
sbit left = P1^2; //蚂腊陆左
sbit right = P1^3; //右
sbit restart = P1^4; //功能键
#define snake_max_body 22
#define Key_Up 1
#define Key_Down 4
#define Key_Left 2
#define Key_Right 3
uchar Key_V_temp=0; //上次按键值
uchar Key_Value;
const uchar code failure[]={"很局羡遗憾,你输了"};
const uchar code maker[]={"设计者:机协成员"闷顷};
const uchar code huiz[]={"会长:方吉桐"};
const uchar code guanggao[]={"机器人协会欢迎你"};
const uchar code t[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xE7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xE7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xE7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xE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FF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
//const uchar []={
//0xFF,0xF3,0x85,0xE8,0xCC,0xED,0x8D,0xEF};
struct //结构体:食物
{
uchar X;
uchar Y;
uchar Yes;
}Food;
struct //结构体:小蛇
{
uchar X[snake_max_body]; //蛇的X坐标
uchar Y[snake_max_body]; //蛇的Y坐标
uchar Log; //蛇的长度
uchar Life; //蛇的生命
uchar Score; //蛇的分数
uchar Level; //蛇的等级
}Snake;
void Init_time1() //定时器初始化,用来产生随机数
{
EA=1;
ET1=1;
TMOD|=0X20;
TH1=0X01;
TL1=0X01;
TR1=1;
}
void snake_init() //贪吃蛇初始化场地
{
uchar i;
line(0,0,0,80);
line(0,80,50,80);
line(50,80,50,0);
line(50,0,0,0);
Snake.Log=2; //定义初始化蛇的长度
Snake.Life=0;
Snake.Score=0;
// Food.Yes=1;
Key_Value=0;
for(i=0;i<Snake.Log;i++) //将蛇给赋值
{
Snake.X[i]=i+2;
Snake.Y[i]=2;
}
for(i=0;i<Snake.Log;i++) //将蛇给画出来
{
dot(Snake.X[i],Snake.Y[i]);
}
}
key_press() //按键检测
{
// uchar key;
up=1;
if(!up)
{
delay_ms(5);
if(!up)
{
Key_Value=1;
}
while(!up);
}
down=1;
if(!down)
{
delay_ms(5);
if(!down)
{
Key_Value=4;
}
while(!down);
}
left=1;
if(!left)
{
delay_ms(5);
if(!left)
{
Key_Value=2;
}
while(!left);
}
right=1;
if(!right)
{
delay_ms(5);
if(!right)
{
Key_Value=3;
}
while(!up);
}
// return Key_Value;
}
void Run_snake(void) //蛇移动
{
uchar i=0;
if((Key_Value==Key_Right&&Key_V_temp!=Key_Left)||(Key_Value==Key_Left&&Key_V_temp==Key_Right))
{
offdot(Snake.X[0],Snake.Y[0]); //先把蛇尾给熄灭掉

for(i=0;i<Snake.Log-1;i++) //蛇身都是它前一段的蛇身的位置
{
Snake.X[i]=Snake.X[i+1];
Snake.Y[i]=Snake.Y[i+1];
}
Snake.X[Snake.Log-1]=Snake.X[Snake.Log-2]+0;
Snake.Y[Snake.Log-1]=Snake.Y[Snake.Log-2]+1; //蛇头向要求的方向移动

for(i=0;i<Snake.Log;i++) //蛇显示函数
{
dot(Snake.X[i],Snake.Y[i]);
}
Key_V_temp=Key_Right; //保存现在的值,以便下次按下时使用
}
if((Key_Value==Key_Left&&Key_V_temp!=Key_Right)||(Key_Value==Key_Right&&Key_V_temp==Key_Left))
{

offdot(Snake.X[0],Snake.Y[0]);

for(i=0;i<Snake.Log-1;i++)
{
Snake.X[i]=Snake.X[i+1];
Snake.Y[i]=Snake.Y[i+1];
}

Snake.X[Snake.Log-1]=Snake.X[Snake.Log-2]+0;
Snake.Y[Snake.Log-1]=Snake.Y[Snake.Log-2]-1;

for(i=0;i<Snake.Log;i++)
{
dot(Snake.X[i],Snake.Y[i]);
}
Key_V_temp=Key_Left;
}
if(( Key_Value==Key_Up&&Key_V_temp!=Key_Down)||( Key_Value==Key_Down&&Key_V_temp==Key_Up))
{
offdot(Snake.X[0],Snake.Y[0]);

for(i=0;i<Snake.Log-1;i++)
{
Snake.X[i]=Snake.X[i+1];
Snake.Y[i]=Snake.Y[i+1];
}
Snake.X[Snake.Log-1]=Snake.X[Snake.Log-2]-1;
Snake.Y[Snake.Log-1]=Snake.Y[Snake.Log-2]+0;
for(i=0;i<Snake.Log;i++)
{
dot(Snake.X[i],Snake.Y[i]);
}
Key_V_temp=Key_Up;
}
if(( Key_Value==Key_Down&&Key_V_temp!=Key_Up)||( Key_Value==Key_Up&&Key_V_temp==Key_Down))
{
offdot(Snake.X[0],Snake.Y[0]);
for(i=0;i<Snake.Log-1;i++)
{
Snake.X[i]=Snake.X[i+1];
Snake.Y[i]=Snake.Y[i+1];
}
Snake.X[Snake.Log-1]=Snake.X[Snake.Log-2]+1;
Snake.Y[Snake.Log-1]=Snake.Y[Snake.Log-2]+0;
for(i=0;i<Snake.Log;i++)
{
dot(Snake.X[i],Snake.Y[i]);
}
Key_V_temp=Key_Down;
}
if((Snake.X[Snake.Log-1]>=50)||(Snake.Y[Snake.Log-1]>=80)||(Snake.X[Snake.Log-1]==0)||(Snake.Y[Snake.Log-1]==0))//判蛇头是否撞到墙壁
{
Snake.Life=1;
}
for(i=3;i<Snake.Log;i++) //从第三节开始判断蛇头是否咬到自己
{
if((Snake.X[i]==Snake.X[0])&&(Snake.Y[i]==Snake.Y[0]))
{
Snake.Life=1;
}
}
/* if(Snake.Life==1)
{
i=Key_Value;
// Display_dead( i);
// clear();
write_comd(0x34);
}*/
/* if(Snake.Log==snake_max_body) //判断蛇是否最长了
{
//i=Key_Value;
write_comd(0x34);
// clear();
write_comd(0x30);
// Display_Pass(i);
}*/
if(Snake.X[Snake.Log-1]==Food.X&&Snake.Y[Snake.Log-1]==Food.Y)//判蛇是否吃到食物
{
Snake.Log++; //蛇节数加1
Snake.X[Snake.Log-1]=Food.X;
Snake.Y[Snake.Log-1]=Food.Y;
Snake.Score++;
Food.Yes=1; //食物标志置1
}
if(Food.Yes==0) //放果子程序
{
dot(Food.X,Food.Y);
}
if(Food.Yes==1)
{
while(1)
{
Food.X=TL1/5; //获得随机数
Food.Y=TL1/4;
for(i=0;i<Snake.Log;i++) //判断产生的食物坐标是否和蛇身重合
{
if((Food.X==Snake.X[i])&&(Food.X==Snake.Y[i]))
break;
}
if(i==Snake.Log)
{
Food.Yes=0;
break; //产生有效的食物坐标
}
}
}
}
void main()
{
lcd_init(); //初始化LCD
Init_time1();
clear();
_nop_();_nop_();_nop_();
map(t);
delay_ms(1400);
clear();
snake_init();
// snake_food();
Food.X=TL1/5;
Food.Y=TL1/4;
dot(Food.X,Food.Y);
// dot(TL1&49,TL1&79);
// dot(TL1&49,TL1&79);
while(1)
{
if(Snake.Life)
{
// clear();
write_comd(0x34);
write_comd(0x30);
delay_ms(100);
display(0x80,7,failure);
display(0x90,8,maker);
display(0x88,6,huiz);
display(0x98,8,guanggao);
}
else
{
key_press();
Run_snake();
write_comd(0x36);
}
if(Snake.Score<15)
delay_ms(150-10*Snake.Score);
else
delay_ms(5);
}
}

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

/*太大了估计你不想要,给你一个扫雷程序,turbo
C下才能编译成功
空格:打标记
回车:扫雷
方向键:改变方向
*/
#include<stdio.h>
#include<conio.h>
#include<time.h>
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;
int*x1;
int*y1;
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();
}
}
}

‘玖’ c语言能写出什么样有意思的小程序

  1. C语言是一门通用计算机编程语言,应用广泛。

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

  3. C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。

  4. 题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多茄派游少?

程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去掉不满足条件的排列。

程序源代码:

main()

{int i,j,k;printf( );for(i=1;i<5;i++)/*以下为三重循环*/for(j=1;j<5;j++)

for (k=1;k<5;k++),{f (i!=ki!=jj!=k) /*确保i、j、k三位互不相同*/printf(%d,%d,%d ,i,j,k); }}

题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高 于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提 成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,羡颂超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?

程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。

程序源代码:

main()

{

long int i;

int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;

scanf(%ld,i);

bonus1=100000*0.1;bonus2=bonus1+100000*0.75;

bonus4=bonus2+200000*0.5;

bonus6=bonus4+200000*0.3;

bonus10=bonus6+400000*0.15;

if(i<=100000)

bonus=i*0.1;

else if(i<=200000)

bonus=bonus1+(i-100000)*0.075;

else if(i<=400000)

bonus=bonus2+(i-200000)*0.05;

else if(i<=600000)

bonus=bonus4+(i-400000)*0.03;

else if(i<=1000000)

bonus=bonus6+(i-600000)*0.015;

else

bonus=bonus10+(i-1000000)*0.01;

printf(bonus=%d,bonus);

}

6.题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?

程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后 的结果满足如下条件,即是结果。

程序源代码:

#include math.h

main()

{

long int i,x,y,z;

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

{ x=sqrt(i+100); /*x为加上100后开方后的结果*/

y=sqrt(i+268); /*y为再加上168后开方后的结果*/

if(x*x==i+100y*y==i+268)/*如果一个数的平方根的平方等于该数,这说明此数是完全平方数*/

printf( %ld ,i);

}

}

7.题目:输入某年某月某日,判断这一天是这一年的第几天?

程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天。

程序源代码:

main()

{

int day,month,year,sum,leap;

printf( please input year,month,day );

scanf(%d,%d,%d,year,month,day);

switch(month)/*先计算某月以前月份的总天数*/

{

case 1:sum=0;break;

case 2:sum=31;break;

case 3:sum=59;break;

case 4:sum=90;break;

case 5:sum=120;break;

case 6:sum=151;break;

case 7:sum=181;break;

case 8:sum=212;break;

case 9:sum=243;break;

case 10:sum=273;break;

case 11:sum=304;break;

case 12:sum=334;break;

defaultrintf(data error);break;

}

sum=sum+day; /*再加上某天的天数*/

if(year%400==0||(year%4==0year%100!=0))/*判断是不是闰年*/

leap=1;

else

leap=0;

if(leap==1month>2)/*如果是闰年且月份大于2,总天数应该加一天*/

sum++;

printf(It is the %dth day.,sum); }

8.题目:输入三个整数x,y,z,请把这三个数由小到大输出。

程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,然后再用x与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小。

程序源代码:

main()

{

int x,y,z,t;

scanf(%d%d%d,x,y,z);

if (x>y)

/*交换x,y的值*/

if(x>z)

/*交换x,z的值*/

if(y>z)

/*交换z,y的值*/

printf(small to big: %d %d %d ,x,y,z);

}

9.题目:用*号输出字母C的图案。

程序分析:可先用<|>*<|>号在纸上写出字母C,再分行输出。

程序源代码:

#include stdio.h

main()

{

printf(Hello C-world! );

printf( **** );

printf( * );

printf( * );

printf( **** );

}

10.题目:输出特殊图案,请在c环境中运行,看一看,Very Beautiful!

程序分析:字符共有256个。不同字符,图形不一样。

程序源代码:

#include stdio.h

main()

{

char a=176,b=219;

printf(%c%c%c%c%c ,b,a,a,a,b);

printf(%c%c%c%c%c ,a,b,a,b,a);

printf(%c%c%c%c%c ,a,a,b,a,a);

printf(%c%c%c%c%c ,a,b,a,b,a);

printf(%c%c%c%c%c ,b,a,a,a,b); }

11.题目:输出9*9口诀。

程序分析:分行与列考虑,共9行9列,i控制行,j控制列。

程序源代码:

#include stdio.h

main()

{

int i,j,result;

printf( );

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

{ for(j=1;j<10;j++)

{

result=i*j;

printf(%d*%d=%-3d,i,j,result);/*-3d表示左对齐,占3位*/

}

printf( );/*每一行后换行*/

}

}

12.题目:要求输出国际象棋棋盘。

程序分析:用i控制行,j来控制列,根据i+j的和的变化来控制输出黑方格,还是白方格。

程序源代码:

#include stdio.h

main()

{

int i,j;

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

{

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

if((i+j)%2==0)

printf(%c%c,219,219);

else

printf( );

printf( );

}

}

13.题目:打印楼梯,同时在楼梯上方打印两个笑脸。

程序分析:用i控制行,j来控制列,j根据i的变化来控制输出黑方格的个数。

程序源代码:

#include stdio.h

main()

{

int i,j;

printf( );/*输出两个笑脸*/

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

{

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

printf(%c%c,219,219);

printf( );

}

阅读全文

与有什么好玩的c语言小程序相关的资料

热点内容
终极连续技术怎么刷 浏览:339
花溪牛马交易在哪里 浏览:613
企业信息主管职责有哪些 浏览:339
代理手机一般在什么地方进货 浏览:378
黄金代理黄金加盟费多少钱 浏览:751
快递物流多久没信息可以投诉 浏览:646
女孩说还要等多久回信息 浏览:15
小游戏有哪些产品 浏览:321
不到30岁学什么技术好 浏览:346
招标代理公司如何办理执照 浏览:9
二手摩托交易平台哪个靠谱 浏览:80
美国通用的技术有哪些 浏览:37
女孩子学什么技术好找工作 浏览:800
购房中的技术问题有哪些 浏览:544
数据传输过量什么意思 浏览:382
农产品上行做什么工作 浏览:532
隆回县新木材市场在哪里 浏览:310
连江哪里有字画鉴定交易 浏览:694
电动伸缩门调试程序多少钱 浏览:445
市场主体如何做到自律 浏览:355