import java.util.*;
public class t{
public static void main(String args[]){
//准备空间
int zxyr=0;
int zx=0;
int zy=0;
String ip;
Random ran=new Random();
Scanner a=new Scanner(System.in);
String[] b=new String[]{" ","□","●","墙","人"};
String[] c=new String[]{"→","↑","←","↓"};
System.out.println("欢迎使用
★★★★★★★★★★★★“推箱子”★★★★★★★★★★★★
系统初始化完成!
走起〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
所有命令: 右: "+c[0]+" 上: "+c[1]+" 左: "+c[2]+" 下: "+c[3]+"
使用方法输入键后回车:
");
int[][] d=new int[8][8];
String[][] p=new String[8][8];
int Stop=0;
int winflag=0;
//随机布局
Stop++;
if(Stop>10000){
Stop=0;
}
for(int i=0;i<3;i++){
d[ran.nextInt(8)][ran.nextInt(8)]=1;
d[ran.nextInt(8)][ran.nextInt(8)]=2;
d[ran.nextInt(8)][ran.nextInt(8)]=3;
}
for(int x=0;Stop>-1;x++){
//显示图形
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
if(i!=zx||j!=zy){
p[i][j]=b[(d[i][j])];
System.out.print(p[i][j]);
}else{
System.out.print("人");
}
}
System.out.println();
}
//主过程
zxyr=d[zx][zy];
int zyr=zy;
int zxr=zx;
int backupmark=0;
int xxy;
//已备份人位置
if (winflag==1){
break;
}
for(int i=0;i<8;i++){
System.out.println("〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓");
}
ip=a.next();
if(ip.equals("a")||ip.equals("A")){
if(zy!=0&&d[zx][zy-1]!=3){
zy--;
backupmark=1;
}
}else if(ip.equals("s")||ip.equals("S")){
if(zx!=7&&d[zx+1][zy]!=3){
zx++;
backupmark=2;
}
}else if("d".equals(ip)||ip.equals("D")){
if(zy!=7&&d[zx][zy+1]!=3){
zy++;
backupmark=3;
}
}else if("w".equals(ip)||ip.equals("W")){
if(zx!=0&&d[zx-1][zy]!=3){
zx--;
backupmark=4;
}
}else{
backupmark=0;
}
//检测与还原
if(zx<8&&zy<8&&zy>=0&&zx>=0){
//
if(d[zx][zy]==0){
d[zxr][zyr]=d[zx][zy];
d[zx][zy]=zxyr;
}else if(d[zx][zy]==1){
int cx=zx-zxr;
int cy=zy-zyr;
if((zx+cx)>0&&(zx+cx)<7&&(zy+cy)<7&&(zy+cy)>0){
xxy=d[zx+cx][zy+cy];
if(xxy==0&&d[zx][zy]==1){
d[zx+cx][zy+cy]=d[zx][zy];
d[zx][zy]=d[zxr][zyr];
d[zxr][zyr]=xxy;
System.out.println("oh,year"+d[zx+cx][zy+cy]+" "+d[zx][zy]+" "+d[zxr][zyr]+" "+xxy);
}else{
switch(backupmark){
case 1:
zy++;
break;
case 2:
zx--;
break;
case 3:
zy--;
break;
case 4:
zx++;
break;
}
}
if(xxy==2){
winflag=1;
System.out.println("★★★★★★★★★★★★★★★★★★★★★★
★★★★★★★★★★★★★★★★★★★★★★
★★★★★★★ 【 你赢了 】 ★★★★★★★★
");
d[zx][zy]=0;
d[zx+cx][zy+cy]=0;
}
}else{
switch(backupmark){
case 1:
zy++;
break;
case 2:
zx--;
break;
case 3:
zy--;
break;
case 4:
zx++;
break;
}
}
}else{
switch(backupmark){
case 1:
zy++;
break;
case 2:
zx--;
break;
case 3:
zy--;
break;
case 4:
zx++;
break;
}
}
}
for(int i=0;i<8;i++){
System.out.println("〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓");
}
}
}
}