小游戏的C++代码
/*在编译时添加以下命令:-std=c++11,否则会导致编译错误*/
# include & ltcstdio & gt
# include & ltcstdlib & gt
# include & ltWindows.h & gt
# include & ltthread & gt
# include & ltconio.h & gt
使用命名空间std
const unsigned char CTRL _ KEY = 0x E0;
const无符号char LEFT = 0X4B
const无符号char RIGHT = 0X4D
const无符号char DOWN = 0X50
const无符号char UP = 0X48
int men2[2] = {0,0 };
int women2[2]={10,10 };
int Game();
Void gotoxy( int x,int y) //光标移动到(x,y)位置。
{
HANDLE HANDLE = GetStdHandle(STD _ OUTPUT _ HANDLE);
坐标位置;
位置。X = x
位置。Y = y
SetConsoleCursorPosition(handle,pos);
}
int clean( int mm,int nn)
{
gotoxy ( mm,nn);
printf(" ");
gotoxy ( mm,nn+1);
printf(" ");
gotoxy ( mm,nn+2);
printf(" ");
}
int men( int x,int y)
{
SetConsoleTextAttribute(GetStdHandle(STD _ OUTPUT _ HANDLE),FOREGROUND _ INTENSITY | FOREGROUND _ BLUE | FOREGROUND _ GREEN);
gotoxy( x,y);
printf(" O ");
gotoxy( x,y+1);
printf(" & lt;h >;);
gotoxy( x,y+2);
printf(" I I ");
}
int women( int i,int j)
{
SetConsoleTextAttribute(GetStdHandle(STD _ OUTPUT _ HANDLE),FOREGROUND _ INTENSITY | FOREGROUND _ RED);
gotoxy( i+1,j);
printf(" O ");
gotoxy( i+1,j+1);
printf(" & lt;h >;);
gotoxy( i,j+2);
printf("/I I \ \ ");
}
int m=10,n = 10;
int x = 0;int y = 0;
int TorF()
{
if(x = = m & amp;& ampy == n)返回1;
否则返回0;
}
int womenmove()
{
int turn
int yn break = 0;
while( YNbreak == 0)
{
YNbreaak = TorF();
turn = rand()% 3;
clean( m,n);
如果(m & ltx)m++;
else m-;
如果(m == x)
{
如果(n & lty)n++;
else n-;
}
如果(m & lt0)m = 0;
如果(m & gt= 75)m = 75;
如果(n & lt0)n = 0;
如果(n & gt= 22)n = 22;
女性(男,女);
女人2[0]= m;
women 2[1]= n;
睡眠(100);
}
系统(“cls”);
gotoxy ( 28,10);
printf("你死了!!!\ n ");
SetConsoleTextAttribute(GetStdHandle(STD _ OUTPUT _ HANDLE),FOREGROUND _ INTENSITY | FOREGROUND _ GREEN | FOREGROUND _ RED | FOREGROUND _ BLUE);
系统(“暂停”);
退出(0);
返回0;
}
int menmove()
{
系统(“cls”);
while (1)
{
开关(getch())
{
case UP:y-;打破;
case DOWN:y++;打破;
案例左:x-;打破;
case RIGHT:x++;打破;
}
系统(“cls”);
if(x & lt;0)x = 0;
if(x & gt;77)x = 77;
if(y & lt;0)y = 0;
如果(y & gt22)y = 22;
男性(x,y);
men 2[0]= x;
men 2[1]= y;
}
}
int Game()
{
女性(10,10);
男性(0,0);
int t = 0;
线程QQ(women move);
menmove();
QQ . join();
返回0;
}
int main()
{
system("模式控制列=80行=25行");
Printf("游戏开始后,随机按一个键,唤醒你的小蓝人。如果你被一个老红娘碰了,那你就死定了\ n ");
Printf("控制反派的关键\ n ");
系统(“暂停”);
系统(“cls”);
game();
返回0;
}
/*留下你的赞带走,谢谢!*/