| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 849 人关注过本帖
标题:请教一个问题。
只看楼主 加入收藏
卡拉是只猫
Rank: 1
等 级:新手上路
威 望:1
帖 子:129
专家分:0
注 册:2005-12-7
收藏
 问题点数:0 回复次数:8 
请教一个问题。

头文件 #include <bios.h>
这个头文件是做什么用得。 在网上找的个搬运工的程序,我在VC++6.0里面运行 这个东西,报错。
希望有人回答一下,谢谢。。
这个是源代码:

#include <stdio.h>
#include <bios.h>
#include <conio.h>


#define ESC 0x011b
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00

#define MAXSIZE 10

typedef struct
{
int x;
int y;
}point;

point des[MAXSIZE];

char map[10][10] =
{
" ",
" ####",
" ### @#",
" # b #",
" ## # ###",
" # # #*#",
" # # b*#",
" # b *#",
" ########",
" "
};

void DrawMan(int x, int y)
{
gotoxy(x+10, y+5);
textcolor(YELLOW);
putch(2);
printf("\b");
}

void DrawSpace(int x, int y)
{
gotoxy(x+10, y+5);
printf(" ");
}

void DrawBox(int x, int y)
{
gotoxy(x+10, y+5);
textcolor(CYAN);
putch('@');
}

void DrawDes(int x, int y)
{
gotoxy(x+10, y+5);
textcolor(YELLOW);
putch('*');
}

void DrawBoxIn(int x, int y)
{
gotoxy(x+10, y+5);
textcolor(YELLOW);
putch('@');
}

void DrawMap(point *pman)
{
int x = 0, y = 0;
int i = 0;
for (; y < 10; ++y)
{
for (x=0; x < 10; ++x)
{
if (map[y][x] == '#')
{
textcolor(GREEN);
gotoxy(x+10, y+5);
putch(219);
}
else if (map[y][x] == '*')
{
DrawDes(x, y);
des[i].x = x;
des[i].y = y;
++i;
}
else if (map[y][x] == '@')
{
pman->x = x;
pman->y = y;
DrawMan(x, y);
map[y][x] = ' ';
}
else if (map[y][x] == 'b')
{
DrawBox(x, y);
}
else if (map[y][x] == 'i')
{
DrawBoxIn(x, y);
des[i].x = x;
des[i].y = y;
++i;
}
des[i].x = -1;
}
gotoxy(48, 6);
printf("Welcome to come to BoxMan!!");
gotoxy(48, 8);
printf("Press direct key to move the man!");
gotoxy(48, 10);
printf("Press ESC to quit the game!");
gotoxy(48, 12);
printf("Enjoy yourself in this game!");
gotoxy(36, 2);
textcolor(RED);
putch('B');
putch('o');
putch('x');
putch('M');
putch('a');
putch('n');
}
}

int main()
{
point man = {1, 1};
int key = 0;
int i = 0, count = 0;
clrscr();
DrawMap(&man);

while (key != ESC)
{
while (bioskey(1) == 0);
key = bioskey(0);

switch (key)
{
case UP:
if (map[man.y - 1][man.x] == '#')
{
break;
}
else if (map[man.y - 1][man.x] == 'b' || map[man.y - 1][man.x] == 'i')
{
switch (map[man.y - 2][man.x])
{
case 'b':
case '#':
case 'i':
break;
case ' ':
/*move box*/
if (map[man.y - 1][man.x] == 'i')
{
map[man.y - 1][man.x] = '*';
}
else
{
map[man.y - 1][man.x] = ' ';
}

map[man.y - 2][man.x] = 'b';
DrawBox(man.x, man.y - 2);


if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

--man.y;
DrawMan(man.x, man.y);
break;
case '*':
/*move box in*/
if (map[man.y - 1][man.x] == 'i')
{
map[man.y - 1][man.x] = '*';
}
else
{
map[man.y - 1][man.x] = ' ';
}

map[man.y - 2][man.x] = 'i';
DrawBoxIn(man.x, man.y - 2);


if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

--man.y;
DrawMan(man.x, man.y);
break;
defalut:
break;
}

break;
}
else
{
if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

--man.y;
DrawMan(man.x, man.y);
break;
}

case DOWN:
if (map[man.y + 1][man.x] == '#')
{
break;
}
else if (map[man.y + 1][man.x] == 'b' || map[man.y + 1][man.x] == 'i')
{
switch (map[man.y + 2][man.x])
{
case 'b':
case '#':
case 'i':
break;
case ' ':
/*move box*/
if (map[man.y + 1][man.x] == 'i')
{
map[man.y + 1][man.x] = '*';
}
else
{
map[man.y + 1][man.x] = ' ';
}

map[man.y + 2][man.x] = 'b';
DrawBox(man.x, man.y + 2);


if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

++man.y;
DrawMan(man.x, man.y);
break;
case '*':
/*move box in*/
if (map[man.y + 1][man.x] == 'i')
{
map[man.y + 1][man.x] = '*';
}
else
{
map[man.y + 1][man.x] = ' ';
}

map[man.y + 2][man.x] = 'i';
DrawBoxIn(man.x, man.y + 2);


if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

++man.y;
DrawMan(man.x, man.y);
break;
default:
break;
}

break;
}
else
{
if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

++man.y;
DrawMan(man.x, man.y);
break;
}
case LEFT:
if (map[man.y][man.x - 1] == '#')
{
break;
}
else if (map[man.y][man.x - 1] == 'b' || map[man.y][man.x - 1] == 'i')
{
switch (map[man.y][man.x - 2])
{
case 'b':
case '#':
case 'i':
break;
case ' ':
/*move box*/
if (map[man.y][man.x - 1] == 'i')
{
map[man.y][man.x - 1] = '*';
}
else
{
map[man.y][man.x - 1] = ' ';
}

map[man.y][man.x - 2] = 'b';
DrawBox(man.x - 2, man.y);


if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

--man.x;
DrawMan(man.x, man.y);
break;
case '*':
/*move box in*/
if (map[man.y][man.x - 1] == 'i')
{
map[man.y][man.x - 1] = '*';
}
else
{
map[man.y][man.x - 1] = ' ';
}

map[man.y][man.x - 2] = 'i';
DrawBoxIn(man.x - 2, man.y);


if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

--man.x;
DrawMan(man.x, man.y);
break;
default:
break;
}

break;
}
else
{
if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}
--man.x;
DrawMan(man.x, man.y);
break;
}
case RIGHT:
if (map[man.y][man.x + 1] == '#')
{
break;
}
else if (map[man.y][man.x + 1] == 'b' || map[man.y][man.x + 1] == 'i')
{
switch (map[man.y][man.x + 2])
{
case 'b':
case '#':
case 'i':
break;
case ' ':
/*move box*/
if (map[man.y][man.x + 1] == 'i')
{
map[man.y][man.x + 1] = '*';
}
else
{
map[man.y][man.x + 1] = ' ';
}

map[man.y][man.x + 2] = 'b';
DrawBox(man.x + 2, man.y);


if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

++man.x;
DrawMan(man.x, man.y);
break;
case '*':
/*move box in*/
if (map[man.y][man.x + 1] == 'i')
{
map[man.y][man.x + 1] = '*';
}
else
{
map[man.y][man.x + 1] = ' ';
}

map[man.y][man.x + 2] = 'i';
DrawBoxIn(man.x + 2, man.y);


if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}

++man.x;
DrawMan(man.x, man.y);
break;
default:
break;
}

break;
}
else
{
if (map[man.y][man.x] == '*')
{
DrawDes(man.x, man.y);
}
else
{
DrawSpace(man.x, man.y);
}
DrawSpace(man.x, man.y);
++man.x;
DrawMan(man.x, man.y);
break;
}
defualt:
break;
}

for (i=0, count=0; des[i].x != -1; ++i)
{
if (map[des[i].y][des[i].x] == '*')
{
++count;
}
}
if (count == 0)
{
gotoxy(35, 3);
printf("Ok! you win!");
getch();
key = ESC;
}
}

return 0;
}


[此贴子已经被作者于2006-1-10 14:29:24编辑过]

搜索更多相关主题的帖子: include 源代码 搬运工 做什么 color 
2006-01-10 14:25
金金
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-1-3
收藏
得分:0 
恐怖!我刚学编程没有3个月,这么长把我看傻了。

If you think you can,you can.
2006-01-10 22:31
卡拉是只猫
Rank: 1
等 级:新手上路
威 望:1
帖 子:129
专家分:0
注 册:2005-12-7
收藏
得分:0 

我晕。
这个#include<bios.h>头文件是什么意思
麻烦谁回答一下,谢谢了


搞不懂就问人,搞得懂就答人。
2006-01-11 00:50
welldone2006
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-1-8
收藏
得分:0 
VC++6.0应该没有这个头文件

2006-01-11 08:41
welldone2006
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-1-8
收藏
得分:0 

它在TC中的作用是ROM基本输入输出函数,我只知道这些


2006-01-11 08:46
卡拉是只猫
Rank: 1
等 级:新手上路
威 望:1
帖 子:129
专家分:0
注 册:2005-12-7
收藏
得分:0 
这是个图形文件。
VC里面不能运行,要到TC下运行。
明白了,谢谢

搞不懂就问人,搞得懂就答人。
2006-01-12 00:06
zhangdongy
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-1-11
收藏
得分:0 
函数bioskey()用#include&lt;bios.h&gt;定义的
2006-01-12 06:56
zhangdongy
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-1-11
收藏
得分:0 
c语言中的bioskey()函数剖析(有不对的地方,请大家提出。)

函 数 名: bioskey 头文件:bios.h
功 能: 直接使用BIOS服务的键盘接口(也可以理解为:读取键盘值)
用 法: int bioskey(int cmd);
输入参数:cmd=0 返回一个键盘值,如无键盘按下,一直等待。

cmd=1 查询键盘是否按下 0-无键按下,非0-有键按下。

cmd=2 返回控制键状态,返回值保存在低8位中。

===========================================================================
bioskey(1)的一个很好的应用:while(bioskey(1)==0) 按一下键盘就退出while循环。
===========================================================================

=======================
bioskey(2)的返回值如下:
=======================

----------------------以下为测试结果--------------------

1、以上测试的键都未按下或都未开取,bioskey(2)的值为:0
2、左shift键对应bioskey(2)的值为: 34
3、右shift键对应bioskey(2)的值为: 33
4、ctrl键对应bioskey(2)的值为: 36
5、alt键对应bioskey(2)的值为: 40
6、左shift+Ctrl键对应bioskey(2)的值为: 38
7、右shift+Ctrl键对应bioskey(2)的值为: 37
8、左shift+Alt键对应bioskey(2)的值为: 42
9、右shift+Alt键对应bioskey(2)的值为: 41
10、左shift+Ctrl+Alt键对应bioskey(2)的值为: 46
11、右shift+Ctrl+Alt键对应bioskey(2)的值为: 45
12、开启Scroll Lock键对应bioskey(2)的值为: 48
13、开启Num Lock键对应bioskey(2)的值为: 32
14、开启Caps Lock键对应bioskey(2)的值为: 32
15、开启Insert键对应bioskey(2)的值为: 160

----------------------以上为测试结果----------------------

**********************************************************************************
+++++++例子1:是我编的测试上面的结果的程序(有不对的地方,请提出,谢谢)++++++++++++++

**********************************************************************************
#include <stdio.h>
#include <bios.h>
#include <ctype.h>

int main(void)
{
FILE *fp;
int i, key, modifiers[14];
char fname[]="bikey(2).txt";
for(i=0;i<14;i++)
{
switch (i)
{

case 0:{printf("测试左shift键,请按下左shift键+任一键\n");break;}
case 1:{printf("测试右shift键,请按下右shift键+任一键\n");break;}
case 2:{printf("测试Ctrl键,请按下Ctrl键+任一键\n");break;}
case 3:{printf("测试Alt键,请按下Alt键+任一键\n");break;}
case 4:{printf("测试左shift+Ctrl键,请按下左shift+Ctrl键+任一键\n");break;}
case 5:{printf("测试右shift+Ctrl键,请按下右shift+Ctrl键+任一键\n");break;}
case 6:{printf("测试左shift+Alt键,请按下左shift+Alt键+任一键\n");break;}
case 7:{printf("测试右shift+Alt键,请按下右shift+Alt键+任一键\n");break;}
case 8:{printf("测试右shift+Ctrl+Alt键,请按下右shift+Alt键+任一键\n");break;}
case 9:{printf("测试右shift+Ctrl+Alt键,请按下右shift+Alt键+任一键\n");break;}
case 10:{printf("测试是否打开了Scroll Lock键,请打开Scroll Lock键再按一键\n");break;}
case 11:{printf("测试是否打开了Num Lock键,请打开Num Lock键再按一键\n");break;}
case 12:{printf("测试是否打开了Caps Lock键,请打开Caps Lock键再按一键\n");break;}
case 13:{printf("测试是否打开了Insert键,请打开Insert键\n");break;}
}
key=bioskey(0);
switch (i)
{

case 0:{printf("按下左shift键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 1:{printf("按下右shift键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 2:{printf("按下Ctrl键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 3:{printf("按下Alt键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 4:{printf("按下左shift+Ctrl键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 5:{printf("按下右shift+Ctrl键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 6:{printf("按下左shift+Alt键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 7:{printf("按下右shift+Alt键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 8:{printf("按下左shift+Ctrl+Alt键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 9:{printf("按下右shift+Ctrl+Alt键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 10:{printf("已打开Scroll Lock键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 11:{printf("已打开Num Lock键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 12:{printf("已打开Caps Lock键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
case 13:{printf("已打开Insert键");modifiers = bioskey(2);printf("bioskey对应返回值:%d\n",modifiers);printf("------------------------------------------------------------\n");break;}
}

} clrscr();
printf("\n\n----------------------以下为测试结果--------------------\n\n");
printf("1、以上测试的键都未按下或都未开取,bioskey(2)的值为:0\n");
printf("2、左shift键对应bioskey(2)的值为: %d\n",modifiers[0]);
printf("3、右shift键对应bioskey(2)的值为: %d\n",modifiers[1]);
printf("4、ctrl键对应bioskey(2)的值为: %d\n",modifiers[2]);
printf("5、alt键对应bioskey(2)的值为: %d\n",modifiers[3]);
printf("6、左shift+Ctrl键对应bioskey(2)的值为: %d\n",modifiers[4]);
printf("7、右shift+Ctrl键对应bioskey(2)的值为: %d\n",modifiers[5]);
printf("8、左shift+Alt键对应bioskey(2)的值为: %d\n",modifiers[6]);
printf("9、右shift+Alt键对应bioskey(2)的值为: %d\n",modifiers[7]);
printf("10、左shift+Ctrl+Alt键对应bioskey(2)的值为: %d\n",modifiers[8]);
printf("11、右shift+Ctrl+Alt键对应bioskey(2)的值为: %d\n",modifiers[9]);
printf("12、开启Scroll Lock键对应bioskey(2)的值为: %d\n",modifiers[10]);
printf("13、开启Num Lock键对应bioskey(2)的值为: %d\n",modifiers[11]);
printf("14、开启Caps Lock键对应bioskey(2)的值为: %d\n",modifiers[12]);
printf("15、开启Insert键对应bioskey(2)的值为: %d\n\n",modifiers[13]);
printf("----------------------以上为测试结果----------------------\n\n");
printf(" +++++++++测试完毕!+++++++++\n\n");

getch();
if((fp=fopen(fname,"w"))==NULL)
{ printf("创建文件失败!");
getch();
exit(0);
}
fprintf(fp,"\n\n----------------------以下为测试结果--------------------\n\n");
fprintf(fp,"1、以上测试的键都未按下或都未开取,bioskey(2)的值为:0\n");
fprintf(fp,"2、左shift键对应bioskey(2)的值为: %d\n",modifiers[0]);
fprintf(fp,"3、右shift键对应bioskey(2)的值为: %d\n",modifiers[1]);
fprintf(fp,"4、ctrl键对应bioskey(2)的值为: %d\n",modifiers[2]);
fprintf(fp,"5、alt键对应bioskey(2)的值为: %d\n",modifiers[3]);
fprintf(fp,"6、左shift+Ctrl键对应bioskey(2)的值为: %d\n",modifiers[4]);
fprintf(fp,"7、右shift+Ctrl键对应bioskey(2)的值为: %d\n",modifiers[5]);
fprintf(fp,"8、左shift+Alt键对应bioskey(2)的值为: %d\n",modifiers[6]);
fprintf(fp,"9、右shift+Alt键对应bioskey(2)的值为: %d\n",modifiers[7]);
fprintf(fp,"10、左shift+Ctrl+Alt键对应bioskey(2)的值为: %d\n",modifiers[8]);
fprintf(fp,"11、右shift+Ctrl+Alt键对应bioskey(2)的值为: %d\n",modifiers[9]);
fprintf(fp,"12、开启Scroll Lock键对应bioskey(2)的值为: %d\n",modifiers[10]);
fprintf(fp,"13、开启Num Lock键对应bioskey(2)的值为: %d\n",modifiers[11]);
fprintf(fp,"14、开启Caps Lock键对应bioskey(2)的值为: %d\n",modifiers[12]);
fprintf(fp,"15、开启Insert键对应bioskey(2)的值为: %d\n\n",modifiers[13]);
fprintf(fp,"----------------------以上为测试结果----------------------\n\n");
printf("测试结果已经保存到文件bikey(2).txt中!谢谢您使用!\n");getch();
fclose(fp);
return 0;
} *******************************************************************************

*******************************************************************************

+++++++例子2:是从网上下的经典例子++++++++++++++

#include <stdio.h>
#include <bios.h>
#include <ctype.h>

#define RIGHT 0x01
#define LEFT 0x02
#define CTRL 0x04
#define ALT 0x08

int main(void)
{
int key, modifiers;

/* function 1 returns 0 until a key is pressed */
while (bioskey(1) == 0);

/* function 0 returns the key that is waiting */
key = bioskey(0);

/* use function 2 to determine if shift keys were used */
modifiers = bioskey(2);
if (modifiers)
{
printf("[");
if (modifiers & RIGHT) printf("RIGHT");
if (modifiers & LEFT) printf("LEFT");
if (modifiers & CTRL) printf("CTRL");
if (modifiers & ALT) printf("ALT");
printf("]");
}
/* print out the character read */
if (isalnum(key & 0xFF))
printf("'%c'\n", key);
else
printf("%#02x\n", key);
return 0;
}

2006-01-12 07:00
zhangdongy
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-1-11
收藏
得分:0 
这是我找的一些相关资料,希望对你的理解有些帮助哈!
2006-01-12 07:01
快速回复:请教一个问题。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.118883 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved