A
Avalon
Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个类似打鼹鼠的游戏,数字键盘上冒出鼹鼠时玩家按下相应按键即可消灭,此时需要使用一个延时的语句来实现"一定时间内玩家如果不按下按键的话就失败"的效果.我尝试过在循环中使用delay(),但似乎循环中是不支持delay()函数的...请问大家应该怎么办?
我使用turboc2.0,以下是我的游戏代码:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/timeb.h>
void main()
{
int driver,mode;
int line, column;
int i,j;
int input;
int a[3][3]={7,4,1,8,5,2,9,6,3};
driver=DETECT;
mode=0;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
setcolor(15);
for(line=0;line<3;line++)
for(column=0;column<3;column++)
rectangle((170+line*2*50),(80+column*2*50),
(220+line*2*50),(130+column*2*50));
/*Draw squares.*/
randomize();
for(;
{
setcolor(5);
i=random(3);
j=random(3);
/*Random the number of the lines and rows. Totally 3*3=9 positions.*/
rectangle((180+i*2*50),(90+j*2*50),
(210+i*2*50),(120+j*2*50));
/*Draw a colored rectangle at the randomized position.*/
input=getch();
/*Wait till the player's input*/
if((input-48)!=a[j])
exit(0);
/*If the player entered the wrong number, then
exit game.*/
setcolor(0);
rectangle((180+i*2*50),(90+j*2*50),
(210+i*2*50),(120+j*2*50));
/*If the player entered the right number, then
delete the existing rectangle and begin
the next circle.*/
}
/* getch();
restorecrtmode();
*/
}
我使用turboc2.0,以下是我的游戏代码:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/timeb.h>
void main()
{
int driver,mode;
int line, column;
int i,j;
int input;
int a[3][3]={7,4,1,8,5,2,9,6,3};
driver=DETECT;
mode=0;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
setcolor(15);
for(line=0;line<3;line++)
for(column=0;column<3;column++)
rectangle((170+line*2*50),(80+column*2*50),
(220+line*2*50),(130+column*2*50));
/*Draw squares.*/
randomize();
for(;
{
setcolor(5);
i=random(3);
j=random(3);
/*Random the number of the lines and rows. Totally 3*3=9 positions.*/
rectangle((180+i*2*50),(90+j*2*50),
(210+i*2*50),(120+j*2*50));
/*Draw a colored rectangle at the randomized position.*/
input=getch();
/*Wait till the player's input*/
if((input-48)!=a[j])
exit(0);
/*If the player entered the wrong number, then
exit game.*/
setcolor(0);
rectangle((180+i*2*50),(90+j*2*50),
(210+i*2*50),(120+j*2*50));
/*If the player entered the right number, then
delete the existing rectangle and begin
the next circle.*/
}
/* getch();
restorecrtmode();
*/
}