本人自制的小游戏
废话不多说,直接上代码
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <conio.h>
#include <fstream>
#include <ctime>
#include <time.h>
#include <stdio.h>
using namespace std;
char a[20][20]={
"##################",
" #### # ### #",
"### ## ##### #",
"## ## #### ## #",
"##### ## ### ###",
"# #### # # ##",
" ",
" ## # ## ######",
" ## # ## # # #",
" ### # #### # #",
"# ### # ### ##o #",
"### ## # ### #",
"##### #### # ###",
"## # # ### ###",
"## # ####### ##",
"# #### # ##### ##",
"# ## ## ## ### ##",
"# # # # # ###",
"## ##### ### ####",
"######## #####",
};
//地图
int main() {
a[0][0]='*';
int z=0,x=0;
while(1) {//无限循环
system("cls");//清屏
for(int i=0; i<20; i++) {
for(int j=0; j<20; j++) {
cout<<a[i][j];
}
cout<<endl;
}
//输出数组
cout<<z<<' '<<x<<endl<<endl;
//坐标
int b;
b = _getch();
if(b=='s') {
if(a[z+1][x]=='o'){
cout<<"YOU WIN!!!";
return 0;
}
if(z+1<0||z+1>19||a[z+1][x]=='#')continue;
a[z+1][x]='*';
a[z][x]=' ';
z++;
//向下
} else if(b=='w') {
if(a[z-1][x]=='o'){
cout<<"YOU WIN!!!";
return 0;
}
if(z-1<0||z-1>19||a[z-1][x]=='#')continue;
a[z-1][x]='*';
a[z][x]=' ';
z--;
//向上
} else if(b=='a') {
if(a[z][x-1]=='o'){
cout<<"YOU WIN!!!";
return 0;
}
if(x-1<0||x-1>19||a[z][x-1]=='#')continue;
a[z][x-1]='*';
a[z][x]=' ';
x--;;
//向左
} else if(b=='d') {
if(a[z][x+1]=='o'){
cout<<"YOU WIN!!!";
return 0;
}
if(x+1<0||x+1>19||a[z][x+1]=='#')continue;
a[z][x+1]='*';
a[z][x]=' ';
x++;
}
//向右
}
return 0;
}
w s a d 分别指上 下 左 右
(做的不好,大佬们多多指教)