本周数据结构课程设计,哥挑了个简单点的题目,用C语言编写了一个图形界面的吃金子小游戏。
基本想法是:
定义了一个数组,通过数据映射到屏幕的坐标。
然后通过一些画图函数,画出淘金者(红色圆)和金子(黄色圆)。
通过键盘的上下左右键控制淘金者的上下左右移动。
每隔六秒钟,游戏界面会刷一次,此时金子会更换位置。
如果你是高手,一分钟吃到了20个那你就Win,如果你碰到墙壁,Game Over。
此游戏超挫,属于版本一,有兴趣的下下来玩玩也不错,当然没有那些Flash做的Beautiful。呵呵。
下面是源代码和一些注释:
/*
Version: v1.0
Author:xufeiyang
DateTime:2010.12.13
IDE:Turbo C 2.0
*/
/************************************/
#include "graphics.h" /*头文件*/
#include "time.h"
#include "stdlib.h"
#include "bios.h"
#include "dos.h"
#include "stdio.h"
#define ESC 0x11b /*键盘扫描码*/
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define F1 0x3b00
#define RIGHT 0x4d00
#define YES 0x1579
#define NO 0x316e
#define RESTART 0x1372
/****************************************/
time_t start, end;
int diff;
int oldtime;
int goldnum = 0;
int Bord[20][20]=
{
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1