直接上代码:
#include <cstdio>
#include <iostream>
#include <ctime>
#include <conio.h>
#include <windows.h>
#include <cstdlib>
#include <cstring>
#include <stdlib.h>
using namespace std;
const int dt1t=8;
int x,y,n;
int dt1[10][10]={
{0,0,1,1,1,0,0,0},
{0,0,1,2,1,0,0,0},
{0,0,1,0,1,1,1,1},
{1,1,1,3,0,3,2,1},
{1,2,0,3,4,1,1,1},
{1,1,1,1,3,1,0,0},
{0,0,0,1,2,1,0,0},
{0,0,0,1,1,1,0,0},
};
int dt2[10][10]{
{0,1,1,1,1,1,1,0},
{1,1,0,0,0,0,1,1},
{1,0,3,0,3,3,0,1},
{1,0,2,2,2,0,0,1},
{1,0,3,3,0,3,0,1},
{1,1,1,0,4,1,1,1},
{0,0,1,1,1,1,0,0},
};
void pduan(char a,int i){
if(a=='w'){
if(dt1[x-1][y]==0){
dt1[x-1][y]=4;
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
x-=1;
cout<<1;
return ;
}
if(dt1[x-1][y]==2){
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
dt1[x-1][y]=6;
x-=1;
return ;
}
if((dt1[x-1][y]==3||dt1[x-1][y]==5)&&dt1[x-2][y]!=1&&dt1[x-2][y]!=3&&dt1[x-2][y]!=5){
// dt1[x-1][y]=4;
if(dt1[x-2][y]==2){
dt1[x-2][y]=5;
n--;
}
if(dt1[x-2][y]==0){
dt1[x-2][y]=3;
}
if(dt1[x-1][y]==5){
dt1[x-1][y]=6;
n++;
}
if(dt1[x-1][y]==3){
dt1[x-1][y]=4;
}
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
x-=1;
return ;
}
return ;
}
if(a=='a'){
if(dt1[x][y-1]==0){
dt1[x][y-1]=4;
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
y-=1;
return ;
}
if(dt1[x][y-1]==2){
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
dt1[x][y-1]=6;
y-=1;
return ;
}
if((dt1[x][y-1]==3||dt1[x][y-1]==5)&&dt1[x][y-2]!=1&&dt1[x][y-2]!=3&&dt1[x][y-2]!=5){
// dt1[x-1][y]=4;
if(dt1[x][y-2]==2){
dt1[x][y-2]=5;
n--;
}
if(dt1[x][y-2]==0){
dt1[x][y-2]=3;
}
if(dt1[x][y-1]==5){
dt1[x][y-1]=6;
n++;
}
if(dt1[x][y-1]==3){
dt1[x][y-1]=4;
}
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
y-=1;
return ;
}
return ;
}
if(a=='s'){
if(dt1[x+1][y]==0){
dt1[x+1][y]=4;
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
x+=1;
return ;
}
if(dt1[x+1][y]==2){
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
dt1[x+1][y]=6;
x+=1;
return ;
}
if((dt1[x+1][y]==3||dt1[x+1][y]==5)&&dt1[x+2][y]!=1&&dt1[x+2][y]!=3&&dt1[x+2][y]!=5){
// dt1[x-1][y]=4;
if(dt1[x+2][y]==2){
dt1[x+2][y]=5;
n--;
}
if(dt1[x+2][y]==0){
dt1[x+2][y]=3;
}
if(dt1[x+1][y]==5){
dt1[x+1][y]=6;
n++;
}
if(dt1[x+1][y]==3){
dt1[x+1][y]=4;
}
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
x+=1;
return ;
}
return ;
}
if(a=='d'){
if(dt1[x][y+1]==0){
dt1[x][y+1]=4;
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
y+=1;
return ;
}
if(dt1[x][y+1]==2){
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
dt1[x][y+1]=6;
y+=1;
return ;
}
if((dt1[x][y+1]==3||dt1[x][y+1]==5)&&dt1[x][y+2]!=1&&dt1[x][y+2]!=3&&dt1[x][y+2]!=5){
// dt1[x-1][y]=4;
if(dt1[x][y+2]==2){
dt1[x][y+2]=5;
n--;
}
if(dt1[x][y+2]==0){
dt1[x][y+2]=3;
}
if(dt1[x][y+1]==5){
dt1[x][y+1]=6;
n++;
}
if(dt1[x][y+1]==3){
dt1[x][y+1]=4;
}
if(dt1[x][y]==6) dt1[x][y]=2;
else dt1[x][y]=0;
y+=1;
return ;
}
return ;
}
}
void dt1yx(){
char a;
while(n){
system("cls");
cout<<x<<" "<<y<<endl;
for(int i=0;i<dt1t;++i){
for(int j=0;j<dt1t;++j){
if(dt1[i][j]==0) cout<<" ";
if(dt1[i][j]==1){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
cout<<"■";
}
if(dt1[i][j]==2){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|
FOREGROUND_GREEN);
cout<<"○";
}
if(dt1[i][j]==3||dt1[i][j]==5){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
cout<<"◆";
}
if(dt1[i][j]==4||dt1[i][j]==6){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
cout<<"◎";
}
}
cout<<endl;
}
a=getch();
pduan(a,1);
}
}
int main(){
// Sleep(4000);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|
FOREGROUND_GREEN);
cout<<" 制作人:sdzbyzh 地图提供者:北极以北,青柠最美";
Sleep(2000);
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
cout<<" 正在初始化,请耐心等待(请开启英文模式)"<<endl<<" ";
for(int i=1;i<=20;++i){
Sleep(200);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
cout<<"■";
}
cout<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
cout<<" 加载完必祝您游戏愉快";
Sleep(2000);
system("cls");
n=4;
x=4;y=4;
dt1yx();
system("cls");
for(int i=0;i<dt1t;++i){
for(int j=0;j<dt1t;++j){
if(dt1[i][j]==0) cout<<" ";
if(dt1[i][j]==1){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
cout<<"■";
}
if(dt1[i][j]==2){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|
FOREGROUND_GREEN);
cout<<"○";
}
if(dt1[i][j]==3||dt1[i][j]==5){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
cout<<"◆";
}
if(dt1[i][j]==4||dt1[i][j]==6){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
cout<<"◎";
}
}
cout<<endl;
}
cout<<"正在前往下一关";
Sleep(2000);
for(int i=0;i<8;++i){
for(int j=0;j<8;++j){
dt1[i][j]=dt2[i][j];
}
}
n=3;
x=5;y=4;
system("cls");
dt1yx();
system("cls");
for(int i=0;i<dt1t;++i){
for(int j=0;j<dt1t;++j){
if(dt1[i][j]==0) cout<<" ";
if(dt1[i][j]==1){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
cout<<"■";
}
if(dt1[i][j]==2){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|
FOREGROUND_GREEN);
cout<<"○";
}
if(dt1[i][j]==3||dt1[i][j]==5){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
cout<<"◆";
}
if(dt1[i][j]==4||dt1[i][j]==6){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
cout<<"◎";
}
}
cout<<endl;
}
cout<<"恭喜你赢了";
Sleep(3000);
return 0;
}