...注释一下这个C语言程序呢?通过上下左右来移动光标的程序!!拜托啦...
发布网友
发布时间:2024-03-27 05:12
我来回答
共1个回答
热心网友
时间:2024-03-31 09:08
#include <stdio.h>
#include <bios.h>
#include <conio.h>
#define ESC 0x011b//这些是这几个键的键值
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
typedef struct
{
int x;
int y;
}point;
DrawMan(int x, int y)
{
gotoxy(x, y);//移动到相应的位置
printf("%c\b", 2);//画笑脸
}
DrawSpace(int x, int y)
{
gotoxy(x, y);
printf(" ");
}
int main()
{
point man = {35, 15};
int key = 0;
clrscr();
DrawMan(man.x, man.y);
while (key != ESC)
{
while (bioskey(1) == 0);//bioskey(1)查询是否按下一个键,若按下一个键则返回键值,否则返回0。
key = bioskey(0);
switch (key)//筛选键值操作
{
case UP:
DrawSpace(man.x, man.y);
--man.y;//向上对应的坐标是y坐标减一,下面的类似就不再说了
DrawMan(man.x, man.y);
break;
case DOWN:
DrawSpace(man.x, man.y);
++man.y;
DrawMan(man.x, man.y);
break;
case LEFT:
DrawSpace(man.x, man.y);
--man.x;
DrawMan(man.x, man.y);
break;
case RIGHT:
DrawSpace(man.x, man.y);
++man.x;
DrawMan(man.x, man.y);
break;
defualt:
break;
}
}
return 0;
}