猫史档案馆


【推箱子】

用户:一块蒙脱石一块蒙脱石查看:3 回复:3 评论:3 创建时间:2021-02-02T13:26:07


#include<bits/stdc++.h>
#include<conio.h>
using namespace std;
int main()
{
	int max=2,w=10,h=10;				//max-关卡总数 w-宽度 h-高度 
	system("mode con cols=20 lines=11");//cols=2*w lines=h+1
	int	map[max][h][w]=
		{
			{
				0,0,0,0,0,0,0,0,0,0,
				0,0,0,1,1,1,0,0,0,0,
				0,0,0,1,3,1,0,0,0,0,
				0,0,0,1,2,1,1,1,1,0,
				0,1,1,1,0,0,2,3,1,0,
				0,1,3,2,4,0,1,1,1,0,
				0,1,1,1,1,2,1,0,0,0,
				0,0,0,0,1,3,1,0,0,0,
				0,0,0,0,1,1,1,0,0,0,
				0,0,0,0,0,0,0,0,0,0,
			},
			{
				0,0,0,0,0,0,0,0,0,0,
				0,0,0,1,0,0,1,0,0,0,
				0,0,1,3,1,1,3,1,0,0,
				0,1,0,0,0,0,0,0,1,0,
				0,1,0,2,0,0,2,0,1,0,
				0,1,0,2,4,0,2,0,1,0,
				0,0,1,0,0,0,0,1,0,0,
				0,0,0,1,3,3,1,0,0,0,
				0,0,0,0,1,1,0,0,0,0,
				0,0,0,0,0,0,0,0,0,0,
			}
		};
	int level=0,s=0;;
	do
	{
		next:cout<<endl;
		for(int i=0;i<(h-1);i++)
		{
			for(int j=0;j<w;j++)
			{
				switch(map[level][i][j])
				{
					case 0:cout<<"  ";break;
					case 1:cout<<"▓";break;
					case 2:cout<<"□";break;
					case 3:cout<<"☆";break;
					case 4:cout<<"";break;
					case 5:cout<<"★";break;
					case 7:cout<<"";break;
				}
			}
		}
		for(int j=0;j<w;j++)
		{
			switch(map[level][(h-1)][j])
			{
				case 0:cout<<"  ";break;
				case 1:cout<<"▓";break;
				case 2:cout<<"□";break;
				case 3:cout<<"☆";break;
				case 4:cout<<"";break;
				case 5:cout<<"★";break;
				case 7:cout<<"";break;
			}
		}
		cout<<"步数:"<<s;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(map[level][i][j]==2)
					goto no;
			}
		}
		if(level<(max-1))
		{
			cout<<endl<<"按任意键进入下一关~";
		level++;
		s=0;
		getch();
		getch();
		goto next;
		}
		else
		{
			goto end;
		}
		no:int i=0,j=0;
		for(i=0;i<h;i++)
		{
			for(j=0;j<w;j++)
			{
				if((map[level][i][j]==4)||(map[level][i][j]==7))
				{
				goto over;
				}
			}
		}
		over:getch();
		switch(getch())
		{
			case 72:
				if(map[level][i-1][j]==0||map[level][i-1][j]==3)
				{
					map[level][i-1][j]+=4;
					map[level][i][j]-=4;
					s++;
				}
				else if((map[level][i-1][j]==2)&&(map[level][i-2][j]==0||map[level][i-2][j]==3))
					{
						map[level][i-2][j]+=2;
						map[level][i-1][j]+=2;
						map[level][i][j]-=4;
						s++;
					}
				break;
			case 75:
				if(map[level][i][j-1]==0||map[level][i][j-1]==3)
				{
					map[level][i][j-1]+=4;
					map[level][i][j]-=4;
					s++;
				}
				else if((map[level][i][j-1]==2)&&(map[level][i][j-2]==0||map[level][i][j-2]==3))
					{
						map[level][i][j-2]+=2;
						map[level][i][j-1]+=2;
						map[level][i][j]-=4;
						s++;			
					}
				break;	
			case 77:
				if(map[level][i][j+1]==0||map[level][i][j+1]==3)
				{
					map[level][i][j+1]+=4;
					map[level][i][j]-=4;
					s++;
				}
				else if((map[level][i][j+1]==2)&&(map[level][i][j+2]==0||map[level][i][j+2]==3))
					{
						map[level][i][j+2]+=2;
						map[level][i][j+1]+=2;
						map[level][i][j]-=4;
						s++;
					}
				break;
			case 80:
				if(map[level][i+1][j]==0||map[level][i+1][j]==3)
				{
					map[level][i+1][j]+=4;
					map[level][i][j]-=4;
					s++;
				}
				else if((map[level][i+1][j]==2)&&(map[level][i+2][j]==0||map[level][i+2][j]==3))
					{
						map[level][i+2][j]+=2;
						map[level][i+1][j]+=2;
						map[level][i][j]-=4;
						s++;
					}
				break;
		}
	}
	while(1);
	end:cout<<endl<<"恭喜通关~~~";
}


回复

上一页1 页 / 共 1下一页
沉著的阿尔法415沉著的阿尔法415

666

点赞0


评论


一块蒙脱石一块蒙脱石

#include<bits/stdc++.h>
#include<conio.h>
using namespace std;
int main()
{
	int max=7,h=10,w=10;				//max-关卡总数 h-高度 w-宽度
	system("mode con cols=20 lines=11");//cols=2w lines=h+1!!! 
	int	map[max][h][w]=
	{
		{
			0,0,0,0,0,0,0,0,0,0,
			0,0,0,1,1,1,0,0,0,0,
			0,0,0,1,3,1,0,0,0,0,
			0,0,0,1,0,1,1,1,1,0,
			0,1,1,1,2,0,2,3,1,0,
			0,1,3,0,2,4,1,1,1,0,
			0,1,1,1,1,2,1,0,0,0,
			0,0,0,0,1,3,1,0,0,0,
			0,0,0,0,1,1,1,0,0,0,
			0,0,0,0,0,0,0,0,0,0,
		},
		{
			1,1,1,1,1,0,0,0,0,0,
			1,4,0,0,1,0,0,0,0,0,
			1,0,2,2,1,0,1,1,1,0,
			1,0,2,0,1,0,1,3,1,0,
			1,1,1,0,1,1,1,3,1,0,
			0,1,1,0,0,0,0,3,1,0,
			0,1,0,0,0,1,0,0,1,0,
			0,1,0,0,0,1,1,1,1,0,
			0,1,1,1,1,1,0,0,0,0,
			0,0,0,0,0,0,0,0,0,0,
		},
		{
			0,0,0,0,0,0,0,0,0,0,
			0,1,1,1,1,1,1,1,0,0,
			0,1,0,0,0,0,0,1,1,1,
			1,1,2,1,1,1,0,0,0,1,
			1,0,0,4,2,0,0,2,0,1,
			1,0,3,3,1,0,2,0,1,1,
			1,1,3,3,1,0,0,0,1,0,
			0,1,1,1,1,1,1,1,1,0,
			0,0,0,0,0,0,0,0,0,0,
			0,0,0,0,0,0,0,0,0,0,
		},
		{
			0,0,0,0,0,0,0,0,0,0,
			0,0,0,1,1,1,1,0,0,0,
			0,0,1,1,0,0,1,0,0,0,
			0,0,1,4,2,0,1,0,0,0,
			0,0,1,1,2,0,1,1,0,0,
			0,0,1,1,0,2,0,1,0,0,
			0,0,1,3,2,0,0,1,0,0,
			0,0,1,3,3,5,3,1,0,0,
			0,0,1,1,1,1,1,1,0,0,
			0,0,0,0,0,0,0,0,0,0,
		},
		{
			0,0,0,0,0,0,0,0,0,0,
			0,0,1,1,1,1,1,0,0,0,
			0,0,1,0,0,1,1,1,0,0,
			0,0,1,4,2,0,0,1,0,0,
			0,1,1,1,0,1,0,1,1,0,
			0,1,3,1,0,1,0,0,1,0,
			0,1,3,2,0,0,1,0,1,0,
			0,1,3,0,0,0,2,0,1,0,
			0,1,1,1,1,1,1,1,1,0,
			0,0,0,0,0,0,0,0,0,0,
		},
		{
			0,0,0,0,0,0,0,0,0,0,
			0,0,0,1,1,1,1,1,1,1,
			0,0,1,1,0,0,1,0,4,1,
			0,0,1,0,0,0,1,0,0,1,
			0,0,1,2,0,2,0,2,0,1,
			0,0,1,0,2,1,1,0,0,1,
			1,1,1,0,2,0,1,0,0,1,
			1,3,3,3,3,3,0,0,1,0,
			1,1,1,1,1,1,1,1,1,0,
			0,0,0,0,0,0,0,0,0,0,
		},
		{
			0,0,0,0,0,0,0,0,0,0,
			0,0,0,1,0,1,1,1,1,0,
			0,1,1,1,0,0,0,0,1,0,
			1,1,3,0,2,1,1,0,1,1,
			1,3,3,2,0,2,0,0,4,1,
			1,3,3,0,2,0,2,0,1,1,
			1,1,1,1,1,1,0,0,1,0,
			0,0,0,0,0,1,1,1,1,0,
			0,0,0,0,0,0,0,0,0,0,
			0,0,0,0,0,0,0,0,0,0,
		}
	};
	int level=0,s=0;
	do
	{
		next:cout<<endl;
		for(int i=0;i<(h-1);i++)
		{
			for(int j=0;j<w;j++)
			{
				switch(map[level][i][j])
				{
					case 0:cout<<"  ";break;
					case 1:cout<<"▓";break;
					case 2:cout<<"□";break;
					case 3:cout<<"☆";break;
					case 4:cout<<"♀";break;
					case 5:cout<<"★";break;
					case 7:cout<<"♂";break;
				}
			}
		}
		for(int j=0;j<w;j++)
		{
			switch(map[level][(h-1)][j])
			{
				case 0:cout<<"  ";break;
				case 1:cout<<"▓";break;
				case 2:cout<<"□";break;
				case 3:cout<<"☆";break;
				case 4:cout<<"♀";break;
				case 5:cout<<"★";break;
				case 7:cout<<"♂";break;
			}
		}
		cout<<"步数:"<<s;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(map[level][i][j]==2)
					goto no;
			}
		}
		if(level<(max-1))
		{
			cout<<endl<<"按任意键进入下一关~";
		level++;
		s=0;
		getch();
		getch();
		goto next;
		}
		else
		{
			goto end;
		}
		no:int i=0,j=0;
		for(i=0;i<h;i++)
		{
			for(j=0;j<w;j++)
			{
				if((map[level][i][j]==4)||(map[level][i][j]==7))
				{
				goto over;
				}
			}
		}
		over:getch();
		switch(getch())
		{
			case 72:
				if(map[level][i-1][j]==0||map[level][i-1][j]==3)
				{
					map[level][i-1][j]+=4;
					map[level][i][j]-=4;
					s++;
				}
				else if(((map[level][i-1][j]==2)||(map[level][i-1][j]==5))&&(map[level][i-2][j]==0||map[level][i-2][j]==3))
					{
						map[level][i-2][j]+=2;
						map[level][i-1][j]+=2;
						map[level][i][j]-=4;
						s++;
					}
				break;
			case 75:
				if(map[level][i][j-1]==0||map[level][i][j-1]==3)
				{
					map[level][i][j-1]+=4;
					map[level][i][j]-=4;
					s++;
				}
				else if(((map[level][i][j-1]==2)||(map[level][i][j-1]==5))&&(map[level][i][j-2]==0||map[level][i][j-2]==3))
					{
						map[level][i][j-2]+=2;
						map[level][i][j-1]+=2;
						map[level][i][j]-=4;
						s++;			
					}
				break;	
			case 77:
				if(map[level][i][j+1]==0||map[level][i][j+1]==3)
				{
					map[level][i][j+1]+=4;
					map[level][i][j]-=4;
					s++;
				}
				else if(((map[level][i][j+1]==2)||(map[level][i][j+1]==5))&&(map[level][i][j+2]==0||map[level][i][j+2]==3))
					{
						map[level][i][j+2]+=2;
						map[level][i][j+1]+=2;
						map[level][i][j]-=4;
						s++;
					}
				break;
			case 80:
				if(map[level][i+1][j]==0||map[level][i+1][j]==3)
				{
					map[level][i+1][j]+=4;
					map[level][i][j]-=4;
					s++;
				}
				else if(((map[level][i+1][j]==2)||(map[level][i+1][j]==5))&&(map[level][i+2][j]==0||map[level][i+2][j]==3))
					{
						map[level][i+2][j]+=2;
						map[level][i+1][j]+=2;
						map[level][i][j]-=4;
						s++;
					}
				break;
		}
	}
	while(1);
	end:cout<<endl<<"恭喜通关~~~";
}

点赞0


评论


我需要复制粘贴我需要复制粘贴

#导入模块
from pygame import *
from sys import *
#初始化
init()
font.init()
#显示窗口
screen=display.set_mode((400,400))
#显示标题
display.set_caption("推箱子")
#设置地图坐标
x=0
y=0
#背景颜色
screen.fill((255,255,255))
#设置地图
map1=[]
#循环变量
i=0
#调整地图
for a in range(8):
    for a in range(8):
        map1.append(0)
for a in range(8):
    map1[i]=10
    i+=1
i=len(map1)-1
for a in range(8):
    map1[i]=10
    i-=1
i=8
for a in range(6):
    map1[i]=10
    i+=8
i=15
for a in range(6):
    map1[i]=10
    i+=8
map1[0]=0
map1[1]=0
map1[9]=10
map1[10]=10
map1[63]=0
map1[62]=0
map1[54]=10
map1[53]=10
map1[13]=4
map1[44]=5
map1[12]=6
map1[43]=7
map1[49]=1
i=0
k=49#人的编号
d=44#箱子1的编号
o=13#箱子2的编号
while True:#喵循环
    for a in event.get():
        if a.type==QUIT:
            #退出窗口
            quit()
            exit()
        #移动人,箱子
        elif a.type == KEYDOWN: #键被按下
                if a.key == K_LEFT:
                    if map1[k-1]==5 and map1[d-1]!=10 and map1[d-8]!=4:
                         map1[k]=0
                         k-=1
                         map1[d]=1
                         d-=1
                         map1[d]=5
                    if map1[k-1]==4 and map1[o-1]!=10 and map1[d-8]!=5:
                         map1[k]=0
                         k-=1
                         map1[o]=1
                         o-=1
                         map1[o]=4
                    if map1[k-1]!=10 and map1[k-1]!=5 and map1[k-1]!=4:
                        map1[k]=0
                        k-=1
                        map1[k]=1
                elif a.key == K_RIGHT:
                    if map1[k+1]==5 and map1[d+1]!=10 and map1[d-8]!=4:
                         map1[k]=0
                         k+=1
                         map1[d]=1
                         d+=1
                         map1[d]=5
                    if map1[k+1]==4 and map1[o+1]!=10 and map1[d-8]!=5:
                         map1[k]=0
                         k+=1
                         map1[o]=1
                         o+=1
                         map1[o]=4
                    if map1[k+1]!=10 and map1[k+1]!=5 and map1[k-8]!=5:
                        map1[k]=0
                        k+=1
                        map1[k]=1
                elif a.key == K_UP:
                    #判断上面是否有箱子,箱子上面是否是墙
                    #因为图层问题,界面上多显示出一个箱子
                    if map1[k-8]==5 and map1[d-8]!=10 and map1[d-8]!=4:
                         map1[k]=0
                         k-=8
                         map1[d]=1
                         d-=8
                         map1[d]=5
                    if map1[k-8]==4 and map1[o-8]!=10 and map1[d-8]!=5:
                         map1[k]=0
                         k-=8
                         map1[o]=1
                         o-=8
                         map1[o]=4
                    if map1[k-8]!=10 and map1[k-8]!=5 and map1[k-8]!=4 :
                         map1[k]=0
                         k-=8
                         map1[k]=1
                         
                         
                elif a.key == K_DOWN:
                    if map1[k+8]==5 and map1[d+8]!=10 and map1[d-8]!=4:
                         map1[k]=0
                         k+=8
                         map1[d]=1
                         d+=8
                         map1[d]=5
                    if map1[k+8]==4 and map1[o+8]!=10 and map1[d-8]!=5:
                         map1[k]=0
                         k+=8
                         map1[o]=1
                         o+=8
                         map1[o]=4
                    if map1[k+8]!=10 and map1[k+8]!=5 and map1[k-8]!=5:
                        map1[k]=0
                        k+=8
                        map1[k]=1
    #显示地图
    for a in range(8):
        for a in range(8):
            if map1[i]==10:
                draw.rect(screen,(196,74,86),(x,y,50,50),0)
                draw.rect(screen,(0,0,0),(x,y,50,50),5)
            if map1[i]==5:
                draw.rect(screen,(219,182,125),(x,y,50,50),0)
                draw.rect(screen,(0,0,0),(x,y,50,50),5)
            if map1[i]==4:
                draw.rect(screen,(219,182,125),(x,y,50,50),0)
                draw.rect(screen,(0,0,0),(x,y,50,50),5)
            if map1[i]==1:
                draw.circle(screen,(55,162,212),(x+20,y+20),20,0)
                draw.circle(screen,(0,0,0),(x+20,y+20),20,5)
            if map1[i]==6:
                draw.rect(screen,(0,212,101),(x,y,30,30),0)
                draw.rect(screen,(0,0,0),(x,y,30,30),5)
            if map1[i]==7:
                draw.rect(screen,(0,212,101),(x,y,30,30),0)
                draw.rect(screen,(0,0,0),(x,y,30,30),5)
            if map1[i]==0:
                draw.rect(screen,(255,255,255),(x,y,50,50),0)
            if map1[12]==0:
                draw.rect(screen,(0,212,101),(200,60,30,30),0)
                draw.rect(screen,(0,0,0),(200,60,30,30),5)
            if map1[43]==0:
                draw.rect(screen,(0,212,101),(200-30,300-30,30,30),0)
                draw.rect(screen,(0,0,0),(200-30,300-30,30,30),5)
            i+=1
            x+=50
        x=0
        y+=50
    if (map1[12]==4 and map1[43]==4) or (map1[12]==5 and map1[43]==5) or (map1[12]==5 and map1[43]==4) or (map1[12]==4 and map1[43]==5):
        font1=font.SysFont('方正喵宋简体',50)
        font2=font1.render('恭喜你,闯关成功!',1,(0,0,0))
        screen.blit(font2,(0,200))
    i=0
    x=0
    y=0
    #刷新
    display.flip()

点赞0


评论