在c语言中怎么样控制光标?
我正在用编写"5指棋"程序,困难在用光标键控制它走棋? 问题点数:0、回复次数:3Top
1 楼novo(探索-学习-创新)回复于 2003-05-01 19:37:41 得分 0
upTop
2 楼chengdulang(CD哑)回复于 2003-05-01 19:41:26 得分 0
你可以用一个变量保存光标的位置。
然后是这个位子的光标闪动。
在判断按键是哪个方向。向那个方向移动就行了。Top
3 楼zhumerchant(faq)回复于 2003-05-01 21:04:43 得分 0
我这儿有个五子其的程序,里边也有光标的处理,你可以参考:
转载自白云黄鹤:
发信人: glutton (液态蛇), 信区: VC
标 题: 五子棋小游戏(转载)
发信站: 武汉白云黄鹤站 (2001年10月29日20:06:01 星期一), 站内信件
运行环境为: Visual C++ 以下c语言版本
(只支持双人下棋).
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
static int dx[4]={1,1,0,-1};
static int dy[4]={0,1,1,1};
int c[17][17];
int bz,x,y,i,cf,xx,yy,gs;
char ch;
void judge()
{ for (i=0;i<4;i++)
{ gs=cf=1; /* when cf=-1,turn around */
do{
xx=x; yy=y;
do{
xx+=dx[i]*cf;
yy+=dy[i]*cf;
if (c[xx][yy]==bz) gs++;
if (gs==5) return;
}
while (c[xx][yy]==bz);
cf=-cf;
}
while (cf==-1);
}
}
void recover()
{ gotoxy(2*x-1,y);
if (abs(c[x][y])==1) { textcolor(11-c[x][y]); cputs("●"); }
else
{ textcolor(0);
switch (x)
{
case 1: switch(y)
{case 1: cputs("┏"); break;
case 15: cputs("┗"); break;
default: cputs("┣"); break;
} break;
case 15: switch(y)
{case 1: cputs("┓"); break;
case 15: cputs("┛"); break;
default: cputs("┫"); break;
} break;
default: switch(y)
{case 1: cputs("┳"); break;
case 15: cputs("┻"); break;
default: cputs("╋"); break;
} break;
} /* end switch */
}/* end else */
textcolor(11-bz);
}
main()
{
again:
/* picture init */
textmode(C80); clrscr(); textattr(6*16+0);
window(25,3,54,23); cputs("┏┳┳┳┳┳┳┳┳┳┳┳┳┳┓");
for (i=2;i<15;i++) cputs("┣╋╋╋╋╋╋╋╋╋╋╋╋╋┫");
cputs("┗┻┻┻┻┻┻┻┻┻┻┻┻┻┛");
gotoxy(1,17); cputs(" 走 Esc 退出游戏 F1 重新开始");
textattr(2*16+15);
gotoxy(1,19); cputs(" 设计者: 电子994班 刘涛 ");
textattr(6*16+10); gotoxy(15,8); cputs("╋");
/* data init */
for (x=0;x<17;x++)
for (y=0;y<17;y++)
c[x][y]=0;
bz=1; x=y=8; gs=0;
/* control center */
while (gs<5)
{
textcolor(11-bz); gotoxy(1,17); cputs("●");
ch=getch();
recover();
/* move chessman */
switch (ch)
{
case 27: exit(0); break; /* Quit the game */
case 59: goto again; /* Start a new game */
case 75: x--; break;
case 77: x++; break;
case 72: y--; break;
case 80: y++; break;
}/* end switch */
x=x-15*(x>15)+15*(x<1);
y=y-15*(y>15)+15*(y<1);
gotoxy(2*x-1,y); cputs("╋");
/* lay down a chessman */
if (ch==13)
switch (abs(c[x][y]))
{
case 1: sound(523); delay(3000); nosound(); break;
case 0: gotoxy(x*2-1,y); cputs("●"); c[x][y]=bz;
sound(131); delay(500); nosound();
judge(); /* judge somebody win ? */
bz=-bz; /* turn to another person*/
break;
} /* end switch */
} /* end while */
gotoxy(1,17); cputs("●子胜利*******游戏结束*******");
getch(); /* press any key to quit */
}
※ 转载:·武汉白云黄鹤站 bbs.whnet.edu.cn·[FROM: 202.114.25.114]
Top




