| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 574 人关注过本帖
标题:"chin a i t p oe er . co mugTTCrI "这个是干什么用的?
取消只看楼主 加入收藏
lianzerong
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2007-7-23
收藏
 问题点数:0 回复次数:0 
"chin a i t p oe er . co mugTTCrI "这个是干什么用的?
#include <mem.h>
#include <fcntl.h>
#include <conio.h>
#include <graphics.h>
#include <io.h>chin a i t p oe er . co mugTTCrI
#include <stdlib.h>
#include <stdio.h>
#include <bios.h>
#include <math.h>
#define N 50
#define Time 10000
int A[N][N];
int IE=6;chin a i t p oe er . co mugTTCrI
int SCORE=0;
char a[]="9999";
void *ball;
int maxx;
unsigned int size;chin a i t p oe er . co mugTTCrI
int head=1;/*0,1,2,3*/
int i=3,j=0,ii=0,jj=0;
int length=3;
int x,y;/*蛇头标志*/
int add=1;/*食物标志*/
int tii,tjj;/* 前蛇尾坐标 */
void start_image()
{
setlinestyle(SOLID_LINE,1,2);
setcolor(GREEN);
line(39,39,39,441);
line(39,441,441,441);
line(441,441,441,39);
line(441,39,39,39);chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI
}
void draw_image(int x,int y)
{
int i=x*400/N+40;
int j=y*400/N+40;
setfillstyle(1,4);
bar(j,i,j+400/N,i+400/N);
}
void eraser_image(int x,int y)
{
int i=x*400/N+40;
int j=y*400/N+40;
setfillstyle(1,0);
bar(j,i,j+400/N,i+400/N);
}chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI
void tu()
{/*tuxing jiemian*/
maxx=getmaxx();
size=imagesize(210,390,450,420);
ball=malloc(size);
setfillstyle(1,10);
bar(160,170,473,253);
setfillstyle(1,9);
bar(163,173,470,250);
setcolor(13);
outtextxy(200,200,"Welcome to Greedy Snake Game");
setcolor(14);
outtextxy(250,220,"Developer :Wu siyuan ");
outtextxy(290,240,"2003.5");
outtextxy(210,390,"Press any key to contunue...");
getimage(210,390,450,420,ball);chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI
while(!kbhit())
{/* 没有键盘击键 */
putimage(210,390,ball,XOR_PUT);
delay(30000);
}
cleardevice();
}
void print()/*输出*/
{ /*要将转化成图形模式*/
int a,b;
/*start_image(); */chin a i t p oe er . co mugTTCrI
for(a=0;a<N;a++)
{ for(b=0;b<N;b++)
{if(A[a][b]>1)draw_image(a,b);
if(A[a][b]==0)eraser_image(a,b); }chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI

}
}chin a i t p oe er . co mugTTCrI
void snake() /*begin*/
{
int a,b;
for(a=0;a<N;a++)
for(b=0;b<N;b++)
A[a][b]=0;chin a i t p oe er . co mugTTCrI
A[i][j]=5;A[i-1][j]=4;A[i-2][j]=3;A[i-3][j]=2;
}
void del_tail()/*蛇尾的操作*/
{
int number=A[ii][jj];
tii=ii;tjj=jj;/*记录前蛇尾*/chin a i t p oe er . co mugTTCrI
while(1)
{
if(A[ii][jj-1]==number+1||A[ii][jj-1]==2&&number==30)
{jj--;break;}chin a i t p oe er . co mugTTCrI
if(A[ii][jj+1]==number+1||A[ii][jj+1]==2&&number==30)
{jj++;break;}chin a i t p oe er . co mugTTCrI
if(A[ii-1][jj]==number+1||A[ii-1][jj]==2&&number==30)
{ii--;break;}chin a i t p oe er . co mugTTCrI
if(A[ii+1][jj]==number+1||A[ii+1][jj]==2&&number==30)
{ii++;break;}chin a i t p oe er . co mugTTCrI

}
}chin a i t p oe er . co mugTTCrI
void down()
{
head=1;
if(A[i+1][j]>1&&A[i+1][j]!=99)
{printf("I hit myself!");exit(1);}
i++;
if(IE>30)IE=2;
A[i][j]=IE;IE++;
del_tail();
A[tii][tjj]=0;chin a i t p oe er . co mugTTCrI

}
void up()
{
head=0;
if(A[i-1][j]>1&&A[i-1][j]!=99)
{printf("I hit myself!");exit(1);}
i--;
if(IE>30)IE=2;
A[i][j]=IE;IE++;
del_tail();
A[tii][tjj]=0;chin a i t p oe er . co mugTTCrI
}
void left()
{
head=2;
if(A[i][j-1]>1&&A[i][j-1]!=99)
{printf("I hit myself!");exit(1);}
j--;
if(IE>30)IE=2;
A[i][j]=IE;IE++;
del_tail();
A[tii][tjj]=0;chin a i t p oe er . co mugTTCrI
}
void right()
{
head=3;
if(A[i][j+1]>1&&A[i][j+1]!=99)
{printf("I hit myself!");exit(1);}
j++;
if(IE>30)IE=2;
A[i][j]=IE;IE++;
del_tail();
A[tii][tjj]=0;
}chin a i t p oe er . co mugTTCrI

void test()/*测试是否到达边界*/
{
if(i<0||i>N-1||j<0||j>N-1)
{
printf("出界! Game over.");
exit(1);
}
}
void move()/*当前移动*/
{
switch(head)
{
case 0:up();break;
case 1:down();break;
case 2:left();break;
case 3:right();break;
/*default:printf("方向出错!\\n");*/
}chin a i t p oe er . co mugTTCrI
}
int keyboard()
{
/*判断是否有键盘输入
// 有返回值0,1,2,3
// int k=keyboard;
//判断方向是否是有效方向
//无效则什么也不做
//若方向有效则改变head的值*/
int a,key,h;
for(a=0;a<2;a++)
if(bioskey(1))break;
key=bioskey(0);chin a i t p oe er . co mugTTCrI
switch (key)
{
/*up*/
case 18432:h=0;break;
/*down*/
case 20480:h=1;break;
/*left*/
case 19200:h=2;break;
/*right*/
case 19712:h=3;break;
/*Esc*/
case 283:printf("You press the Esc key!");exit(1);break;
/*default: h=999 ;*/chin a i t p oe er . co mugTTCrI
}
return h;
}
void add_point()/* 用于产生食物 */
{chin a i t p oe er . co mugTTCrI
while(1){
x=random(100)%N;
y=random(100)%N;
if(A[x][y]==0)break;
}
A[x][y]=99;/*食物的标志是5*/chin a i t p oe er . co mugTTCrI
add=0;/* 加食物标志清0*/chin a i t p oe er . co mugTTCrI
}
void score()
{chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI
setcolor(9);
settextstyle(3,0,4);
outtextxy(450,40,"Score:");chin a i t p oe er . co mugTTCrI
setcolor(RED);
outtextxy(450,200,"Speed:");chin a i t p oe er . co mugTTCrI
}
void number_char(int x)
{chin a i t p oe er . co mugTTCrI
int a0,a1,a2,a3;
if(x>9999){a[0]='9';a[1]='9';a[2]='9';a[3]='9';}
else {
a0=x/1000;
a[0]=a0+48;chin a i t p oe er . co mugTTCrI
a1=(x-a0*1000)/100;
a[1]=a1+48;chin a i t p oe er . co mugTTCrI
a2=(x-a0*1000-a1*100)/10;
a[2]=a2+48;chin a i t p oe er . co mugTTCrI
a3=(x-a0*1000-a1*100-a2*10);
a[3]=a3+48;
a[4]='\\0';chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI

}
}chin a i t p oe er . co mugTTCrI
void snake_get()/*吃到食物时*/
{
if(i==x&&j==y)
{
length++;chin a i t p oe er . co mugTTCrI
A[tii][tjj]=A[ii][jj]-1;/*蛇尾加长*/chin a i t p oe er . co mugTTCrI

ii=tii;jj=tjj;/*蛇尾重新定义*/
add=1;/*食物标志置1*/
setfillstyle(1,BLACK);
bar(520,100,650,140);/*clear score*/
setcolor(3);
number_char(SCORE+=100);
outtextxy(550,100,a);chin a i t p oe er . co mugTTCrI
}chin a i t p oe er . co mugTTCrI
}chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI

void main()
{
int get_head;/*定义键盘输入*/
int gd=DETECT,gm;
clrscr();chin a i t p oe er . co mugTTCrI
/*regibgiobjdriver(public name)*/
initgraph(&gd,&gm,"c:\\\\bgi");chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI

setbkcolor(BLACK);chin a i t p oe er . co mugTTCrI
tu();
snake();/*初始化*/
start_image();
score();/*定义分数界面*/chin a i t p oe er . co mugTTCrI
while(1)
{ while(bioskey(1)==0)/*是否有键盘输入*/
{chin a i t p oe er . co mugTTCrI
if(add)add_point();/*是否可以增加食物*/chin a i t p oe er . co mugTTCrI
print();
move();
snake_get();/* 是否吃到食物 (test)*/
test();
delay(Time);
}
get_head=keyboard();
/* choose */chin a i t p oe er . co mugTTCrI
while(1){/*判断得到的坐标是否合法*/
if(get_head==0&&head==1)break;
if(get_head==1&&head==0)break;
if(get_head==2&&head==3)break;
if(get_head==3&&head==2)break;
else {head=get_head;break;}/*合法给head赋值*/
}chin a i t p oe er . co mugTTCrI
}chin a i t p oe er . co mugTTCrI
chin a i t p oe er . co mugTTCrI
}chin a i t p oe er . co mugTTCrI
______________________________________________________________________________________
"chin a i t p oe er . co mugTTCrI "这个是干什么用的?最好能附带给我一些使用说明!!呵呵!!!学习嘛!!
请各位大虾多多帮忙!!!!!!!!
搜索更多相关主题的帖子: include 干什么 color 
2007-08-10 18:50
快速回复:"chin a i t p oe er . co mugTTCrI "这个是干什么用的?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032667 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved