推箱子c++游戏

直接上代码:

#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;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值