#include
#include <windows.h>
#include <conio.h>
#include
#include “basic.cpp”
using namespace std;
class game
{
private:
int x,y;
clock_t t,tt;
bool flag;
char c1,c2;//用于接收键盘码的字符型变量
public :
game(int x0,int y0,int tt0)
{
x=x0;
y=y0;
tt=tt0;
flag=true;
t=clock();
}
void key()//接收键盘码
{
if(kbhit())//当键盘按下时
{
c1=getch();
if(c1==27)exit(0);//如果是按下esc键则退出程序
if(c1==32)
{
c2=getch();
}
}
}
void move()
{
if(flag==true)
{
gotoxy(x,y);
cout<<"●";
flag=false;
}
if(clock()-t>tt)
{
gotoxy(x,y);
cout<<" ";
switch(c2)
{
case 77:
++x;
x=x%77;
break;
case 75:
--x;
if(x<0)x=78;
break;
}
flag=true;
t=clock();//重新进行计时
}
}
};
int main()
{
game g(0,10,20);
g.hide_cursor();
while(true)
{
g.key();
g.move();
}
g.show_cursor();
}