最近搞病毒搞多了,现在搞点游戏。
首先‘#’代表墙,‘p’代表玩家,‘o’终点。
代码如下:
#include <iostream>
#include <windows.h>
#include <conio.h>
int main()
{
char a[11][12]={"##########","#p# # o#","# # # # ##","# # # # #","# # # #","## ## # #","## ### #","# # #","# #","# #","##########"};//绘制地图
int y=1,x=1;
while(1)
{
Sleep(10);//延迟10毫秒
system("cls");//清屏
for(int i=0;i<=10;i++)puts(a[i]);//显示地图
if(kbhit())
{
a[y][x]=' ';
if(getch()=='d'&&a[y][x+1]=='o')return 0;//到达终点了
if(getch()=='d'&&a[y][x+1]==' ')x++;
if(getch()=='a'&&a[y][x-1]==' ')x--;
if(getch()=='s'&&a[y+1][x]==' ')y++;
if(getch()=='w'&&a[y-1][x]==' ')y--;
a[y][x]='p';
}
}
}
通过EGE图形库的改造版:https://download.csdn.net/download/qq_46628334/19419993?spm=1001.2014.3001.5501