500行C语言程序
一 、 题目阐述:
通过本学期对C语言的学习,对程序编译有了初步的了解,并运用了各种函数(如文件包含,宏定义,结构体,函数调用等)编写了这个推箱子游戏。
二 、 设计思路:
程序中“3”代表墙壁,“2”代表箱子,“4”代表目的地,“0”代表空,“5”代表人+目的地,“ 1“ 代表人,“6“代表箱子+目的地,用“Enter”键选择关数,按“p“键可以毁步,但最多只能毁5次。通过上下左右键实现箱子的上下左右移动,在可移动的范围内,推送到目的地。在推动的过程中若彻底失败,便按r键重新启动游戏。
三、主要解决问题的方法及技术关键
主要问题及解决方法
★函数的定义及调用
★光标的定位设置处理问题
★光标的定位设置处理是通过void gotoxy(int x,int y)函数实现的。定位设置手段是通过型参x、y获取定位点,应用int86的中断调用完成光标定位。
★数组函数,switch,if语句,for循环语句的应用
技术关键
★光标定位
C语言中循环语句的使用
★C语言绘图及定义函数的使用
I
Input name();
C
Char;
P
Printf(“\n\nPlease input your name…”)
C
C=getchar();
C
C!=’y’&&c!=’y’&&c!
C!=’
C!=’y’&&c!=’y’
intgd=DETECT,gm;
intgd=DETECT,gm;
Judgeide();
Judgeide();
Key!=key-Enter
CASE
Key=bio=key(0);
bio=key(1)
IF
Setbkcolor(BKCOLOR);
Idc=0
Idc=0
Idc=1Game();break;
Idc=1
Game();break;
ViewRecord();bio=key
ViewRecord();bio=key
Idc=2
Idc=2
DeleteRecord=();bio=keyIdc=3
DeleteRecord=();bio=key
Idc=3
exit(0);
exit(0);
Key=Key_EnterInti,I,flog;NextMission();time(&t1);break;flag==1Flog=0;1IFIF
Key=Key_Enter
Inti,I,flog;
NextMission();time(&t1);break;
flag==1
Flog=0;
1
IF
IF
T
The end.
四: 程序清单:
#define MAX 2 /*游戏中总关数*/
#define STARTX 180
#define STARTY 80
#define BKCOLOR BLACK
#define MANCOLOR RED
#define OBJECTCOLOR YELLOW
#define TIMEINT 2
#define STARNUM 300
#define STEPMAX 5
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define Key_R 0x1372
#define Key_Up 0x4800
#define Key_Enter 0x1c0d
#define Key_Down 0x5000
#define Key_P 0x1970
#define Key_Esc 0x11b
#define Key_Right 0x4d00
#define Key_Left 0x4b00
typedef struct star
{
int x;
int y;
int c;
}Star;
Star s[STARNUM];
typedef struct record
{
char name[20];
int second;
struct time t;
struct date d;
}Record;
Record r[MAX];
typedef struct c
{
int x;
int y;
}Add;
typedef struct a
{
int x;
int y;
}Player;
Player p;
char name[20]; /*进入游戏时记录玩家的姓名*/
time_t t1,t2; /*游戏结束时的时间*/
int Ide; /*开始进入游戏时,选择菜单时返的功能号(1,2,3)*/
int