| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 812 人关注过本帖
标题:大家好 能帮帮小妹吗
只看楼主 加入收藏
intin
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-3-1
收藏
得分:0 
好的程序并不是有多复杂,而是大家都一看就明白.当然啦,也不是人人都想的到.
不过,6楼说得不错,注释绝对不能少.

2006-03-02 11:18
梦想中国
Rank: 2
等 级:新手上路
威 望:5
帖 子:539
专家分:0
注 册:2006-2-26
收藏
得分:0 

这是我学3天编出来的:请你发贴时把时间去掉,OK?
#include<graphics.h>
#include<dos.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
struct menu{
int left,top,right,bottom;
};
struct menu guest[100];
struct menu food;
int index=5;
void draw_guest(struct menu t[100]);
void process_program(void);
void move_guest(struct menu t[100]);
void delete_last_element(struct menu t[100]);
void conversion_array_element(struct menu t[100]);
void set_top_element(struct menu t[100]);
void set_bottom_element(struct menu t[100]);
void set_left_element(struct menu t[100]);
void set_right_element(struct menu t[100]);
void renew_set_array(struct menu t[100]);
void renew_appear_food(struct menu *f);
void output_score(void);
void set_screen(void);
int compare(struct menu t[100]);
int main(void)
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc");
srand(time(NULL));
set_screen();
draw_guest(guest);
process_program();
closegraph();
return 0;
}
void draw_guest(struct menu t[100])
{
int i;char text[]="Press Tab key,exit program.";
outtextxy(200,20,text);
setcolor(2);
for(i=1;i<=index;i++)
{
t[i].left=100+i*10-10;
t[i].top=100;
t[i].right=110+i*10-10;
t[i].bottom=110;
rectangle(t[i].left,t[i].top,t[i].right,t[i].bottom);
}
}
void process_program(void)
{
move_guest(guest);
}
void move_guest(struct menu t[100])
{
char ch,text[]="USER Score:";
setcolor(15);
outtextxy(530,70,text);
renew_appear_food(&food);
while(1)
{
if(kbhit())
{
ch=getch();
if(ch==9) file://if ch equal tab key,exit program
break;
if(ch==119) file://ch=w
{
delete_last_element(t);
conversion_array_element(t);
set_top_element(t);
renew_set_array(t);
}
if(ch==115) file://ch=s
{
delete_last_element(t);
conversion_array_element(t);
set_bottom_element(t);
renew_set_array(t);
}
if(ch==97) file://ch=a
{
delete_last_element(t);
conversion_array_element(t);
set_left_element(t);
renew_set_array(t);
}
if(ch==100) file://ch=d
{
delete_last_element(t);
conversion_array_element(t);
set_right_element(t);
renew_set_array(t);
}
if(t[index].left==food.left && t[index].top==food.top && t[index].right==food.right && t[index].bottom==food.bottom)
{
setfillstyle(1,0);
bar(food.left,food.top,food.right,food.bottom); file://guest eat up food
index++;
t[index].left=t[index-1].left+10;
t[index].top=t[index-1].top;
t[index].right=t[index-1].right+10;
t[index].bottom=t[index-1].bottom;
renew_appear_food(&food);
set_screen();
output_score(); file://record score function
}
if(compare(t))
{
setcolor(15);
outtextxy(100,250,"The snake is deid,press anykey exit program");
getch();
break;
}
}//if
}//while
}
void delete_last_element(struct menu t[100])
{
setcolor(0);
rectangle(t[1].left,t[1].top,t[1].right,t[1].bottom);
}
void conversion_array_element(struct menu t[100])
{
int i;
for(i=2;i<=index;i++)
t[i-1]=t[i];
}
void set_top_element(struct menu t[100])
{
t[index].top=t[index].top-10;
t[index].bottom=t[index].bottom-10;
}
void set_bottom_element(struct menu t[100])
{
t[index].top=t[index].top+10;
t[index].bottom=t[index].bottom+10;
}
void set_left_element(struct menu t[100])
{
t[index].left=t[index].left-10;
t[index].right=t[index].right-10;
}
void set_right_element(struct menu t[100])
{
t[index].left=t[index].left+10;
t[index].right=t[index].right+10;
}
void renew_set_array(struct menu t[100])
{
int i;
setcolor(2);
for(i=1;i<=index;i++)
rectangle(t[i].left,t[i].top,t[i].right,t[i].bottom);
}
void renew_appear_food(struct menu *f)
{
f->left=100+rand()%300;
f->left=f->left/10*10;
f->top=70+rand()%300;
f->top=f->top/10*10;
f->right=f->left+10;
f->bottom=f->top+10;
setfillstyle(1,15);
bar(f->left,f->top,f->right,f->bottom);
}
void output_score(void)
{
static int i=0;
char string[20]; file://attention array
i++;
setfillstyle(1,0);
bar(540,80,570,110);
sprintf(string,"%d",i);
setcolor(15);
outtextxy(550,100,string);
}
void set_screen(void)
{
setcolor(15);
setlinestyle(1,0,3);
rectangle(50,50,500,400);
}
int compare(struct menu t[100])
{
int i,flag=0;
for(i=1;i<index;i++)
{
if(t[i].left==t[index].left && t[i].top==t[index].top && t[i].right==t[index].right && t[i].bottom==t[index].bottom)
flag=1;
if(t[index].left==t[index-2].left && t[index].top==t[index-2].top && t[index].right==t[index-2].right && t[index].bottom==t[index-2].bottom)
flag=0;
}
return flag;
}


2006-03-04 11:34
血刃
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-2-15
收藏
得分:0 
郁闷怎么都这么谦虚啊
编游戏我至今还没找到门在哪里!妹妹竟然这么说
看来我的智商该从新格式化了
伤心啊!
2006-03-05 08:50
intin
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-3-1
收藏
得分:0 
以下是引用梦想中国在2006-3-4 11:34:00的发言:

这是我学3天编出来的:请你发贴时把时间去掉,OK?


?? 说我嘛
不过,我初试了一下,你的程序在文件编写方面好像有些问题。


2006-03-05 22:35
梦想中国
Rank: 2
等 级:新手上路
威 望:5
帖 子:539
专家分:0
注 册:2006-2-26
收藏
得分:0 
说楼主

2006-03-05 22:48
快速回复:大家好 能帮帮小妹吗
数据加载中...
 
   



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

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