简单写一个例子,相关函数如有不懂的,可以直接google
#include "Conio.h"
#include "dos.h"
#include "stdio.h"
#include "graphics.h"
#define closegr closegraph
void cursor();
void initgr(void);
int Xcursor,Ycursor ;
int main(void)
{
int a,b ;
int i,j ;
int Xsize=50,Ysize=24 ;
int start=50 ;
int Key=0 ;
printf("矩阵行:");
scanf("%d",&a);
printf("矩阵列:");
scanf("%d",&b);
initgr();
for(i=0;i<=a;i++)
{
line(start+i*Xsize,start,start+i*Xsize,start+b*Ysize);
}
for(i=0;i<=b;i++)
{
line(start,start+i*Ysize,start+a*Xsize,start+i*Ysize);
}
Xcursor=start+3 ;
Ycursor=start+12 ;
cursor();
while(Key!=45)
{
while(bioskey(1)==0)cursor();
Key=bioskey(0);
/*这里加入你的接收部分,可以用getch(),outtextxy()等函数来处理,并根据所处的屏幕x,y值来对应矩阵的数组*/
if(Key&0xff);
else
{
Key>>=8 ;
if(Key==75)Xcursor=Xcursor>start+3?Xcursor-Xsize:Xcursor ;
if(Key==77)Xcursor=Xcursor<start+3+(a-1)*Xsize?Xcursor+Xsize:Xcursor ;
if(Key==72)Ycursor=Ycursor>start+12?Ycursor-Ysize:Ycursor ;
if(Key==80)Ycursor=Ycursor<start+12+(b-1)*Ysize?Ycursor+Ysize:Ycursor ;
}
}
getch();
closegr();
return 0 ;
}
/* BGI初始化 */
void initgr(void)
{
int gd=DETECT,gm=0 ;
/* 和gd = VGA,gm = VGAHI是同样效果 */
registerbgidriver(EGAVGA_driver);
/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */
initgraph(&gd,&gm,"");
}
/*光标*/
void cursor()
{
setcolor(WHITE);
line(Xcursor,Ycursor+10,Xcursor+5,Ycursor+10);
delay(3500);
setcolor(BLACK);
line(Xcursor,Ycursor+10,Xcursor+5,Ycursor+10);
delay(3500);
}