本游戏以更新为1.4版
本次更新改变了输出,让玩家有更好的视觉效果
代码:
#include <conio.h>
#include <windows.h>
#include <bits/stdc++.h>
using namespace std;
char a[308][308];
int x=1,y=1;
void color(int a) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
int main() {
color(956);
int m,w=2;
for(int i=1; i<=30; i++) {
for(int j=1; j<=30; j++) {
if(i==1&&j==1||i==30&&j==30) {
if(i==1&&j==1)
m=3;
if(i==30&&j==30)
m=2;
} else {
m=rand()%w;
}
if(m==1) {
a[i][j]='*';
}
if(m==0) {
a[i][j]='#';
}
if(m==2) {
a[i][j]='@';
}
if(m==3) {
a[i][j]='O';
}
}
}
while(1) {
system("cls");
int x_=x,y_=y;
char e='.';
for(int i=0; i<=31; i++) {
for(int j=0; j<=31; j++) {
if(i==0||i==31||j==0||j==31)
{
cout<<"★";
}
else
{
switch(a[i][j])
{
case 'O':cout<<"♀";break;
case '*':cout<<" ";break;
case '#':cout<<"■";break;
case '@':cout<<"◎";break;
}
}
}
cout<<endl;
}
cout<<"W:向上\nX:向下\nA:向左\nD:向右\nQ:左上\nZ:左下\nE:右上\nC:右下\n请选择\n";
while(e!='w'&&e!='x'&&e!='a'&&e!='d'&&e!='q'&&e!='z'&&e!='e'&&e!='c') {
e=getch();
if(e=='w') {
x--;
}
if(e=='x') {
x++;
}
if(e=='a') {
y--;
}
if(e=='d') {
y++;
}
if(e=='q') {
x--;
y--;
}
if(e=='z') {
x++;
y--;
}
if(e=='e') {
x--;
y++;
}
if(e=='c') {
x++;
y++;
}
if(e!='w'&&e!='x'&&e!='a'&&e!='d'&&e!='q'&&e!='z'&&e!='e'&&e!='c') {
cout<<"无,请重新选择\n";
}
}
if(x<1||y<1||x>30||y>30) {
system("cls");
cout<<"游戏失败"<<endl;
return 0;
}
if(a[x][y]=='#') {
system("cls");
cout<<"游戏失败"<<endl;
return 0;
}
if(a[x][y]=='@') {
system("cls");
cout<<"成功"<<endl;
return 0;
}
a[x_][y_]='*';
a[x][y]='O';
}
return 0;
}