/* WIN-TC BGI 图形编程模板 */
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <graphics.h>
/*键盘扫描码*/
#define VK_DOWN 0x5000
#define VK_UP 0x4800
#define VK_ESC 0x011b
#define VK_ENTER 0x1c0d
#define UP 1
#define DOWN 0
#define IDLE -1
#define GO_BACK 1
#define TIMER 0x1c
#define __CPPARGS
/*电梯的数据结构*/
typedef struct elevator{
int state; /*电梯的状态*/
int current; /*电梯目前所处楼
层*/
int movingto; /*电梯的目标楼层*/
}Elevator;
Elevator ele;
/*队列成员的数据结构*/
typedef struct queue{
int floor;
int up_down;
struct queue *next;
}Queue;
Queue *head;
void two_thread(); /*主体函数,它将整个程序
分割为两个进程*/
void getin(int *); /*模拟乘客进入电梯,处
理等待队列中的 成员*/
void getout(); /*模拟乘客出电梯*/
void up_arrowhead(); /*绘图函数:电梯外的向上
按钮*/
void down_arrowhead(); /*绘图函数:电梯外的向下
按钮*/
void drawfloor(); /*绘图函数:电梯主体*/
void waiting(); /*电梯等待函数,当有新
的命令时结束等待*/
void button(); /*绘图函数:电梯内的楼
层按钮*/
void in_queue(int,int); /*等待的乘客进入队列*/
void out_queue(int,int); /*进入电梯的乘客出队列
*/
void finalfloor(int); /*设定电梯在目前方向
上的最终楼层*/
int y_to_floor(int); /*将图象模式下的坐标
值转换层对应的楼层号*/
void message();
void music();
void instruction(); /*使用说明*/
int callup[10]={0,0,0,0,0,0,0,0,0,0}, /*记录每
层楼等待向上的乘客的数 l 量*/
calldown[10]={0,0,0,0,0,0,0,0,0,0}, /*记录每
层楼等待向下的乘客的数 l 量*/
out[10]={0,0,0,0,0,0,0,0,0,0}, /*记录以
每层楼为目标楼层的乘客的数 l 量*/
TimerCounter=0,
/* 计时变量,每秒钟增加 1 */
floor=1,key,calling=1,up_or_down=1,waittime=20, total=0,
x=270,
y=52,
x0=365,
y0=50,
bx=315,
by=40,
ex=345,
ey=80;
/* 指向原来时钟中断处理过程入口的中断处理函数指针(句柄)
*/
void interrupt ( *oldhandler)(__CPPARGS);
/* 新的时钟中断处理函数 */
void interrupt newhandler(__CPPARGS)
{
/* increase the global counter */
TimerCounter++;
/* call the old routine */
oldhandler();
}
/* 设置新的时钟中断处理过程 */
void SetTimer(void interrupt (*IntProc)(__CPPARGS))
{
oldhandler=getvect(TIMER);
disable(); /* 设置新的时钟中断处理过程时,禁止所有中
断 */
setvect(TIMER,IntProc);
enable(); /* 开启中断 */
}
/* 恢复原有的时钟中断处理过程 */
void KillTimer()
{
disable();
setvect(TIMER,oldhandler);
enable();