能不能尽可能详细的帮我注释一下这个C语言程序呢?通过上下左右来移动光标的程序!!拜托啦, 我在TC下运行的.
#include<stdio.h>#include<bios.h>#include<conio.h>#defineESC0x011b#defineUP0x4800#def...
#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);
key = bioskey(0);
switch (key)
{
case UP:
DrawSpace(man.x, man.y);
--man.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;
} 展开
#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);
key = bioskey(0);
switch (key)
{
case UP:
DrawSpace(man.x, man.y);
--man.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;
} 展开
1个回答
展开全部
#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;
}
#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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询