import java.util.Scanner; public class 第13关完美版 { public static void main(String[] args) { Scanner in=new Scanner(System.in); String XH=""; int rx=4,ry=2,xx1=3,xy1=2,xx2=3,xy2=3,xx3=3,xy3=4,xx4=3,xy4=5,xx5=3,xy5=6; int[][] a=new int[9][7]; a[ry][rx]=1;a[xy1][xx1]=2;a[xy2][xx2]=2;a[xy3][xx3]=2;a[xy4][xx4]=2;a[xy5][xx5]=2; do{ for(int y=0;y<9;y++){ for(int x=0;x<7;x++){ if((x==0&&y>=2&&y<=6)||(x==1&&(y==2||y==6))||(x==2&&(y<3||y>5))||(y==0&&x>=2&&x<=5)||(y==8&&x>=2&&x<=4)||(y==7&&x==4)||(x==5&&((y>4&&y!=8)||y<3))||(x==6&&y>1&&y<6)){ System.out.print("■"); }else if(x==3&&y==3){ if((xx1==3&&xy1==3)||(xx2==3&&xy2==3)||(xx3==3&&xy3==3)||(xx4==3&&xy4==3)||(xx5==3&&xy5==3)){ System.out.print("㊣"); }else if(rx==3&&ry==3){ System.out.print("♀"); }else{ System.out.print("☆"); } }else if(x==3&&y==4){ if((xx1==3&&xy1==4)||(xx2==3&&xy2==4)||(xx3==3&&xy3==4)||(xx4==3&&xy4==4)||(xx5==3&&xy5==4)){ System.out.print("㊣"); }else if(rx==3&&ry==4){ System.out.print("♀"); }else{ System.out.print("☆"); } }else if(x==3&&y==5){ if((xx1==3&&xy1==5)||(xx2==3&&xy2==5)||(xx3==3&&xy3==5)||(xx4==3&&xy4==5)||(xx5==3&&xy5==5)){ System.out.print("㊣"); }else if(rx==3&&ry==5){ System.out.print("♀"); }else{ System.out.print("☆"); } }else if(x==3&&y==6){ if((xx1==3&&xy1==6)||(xx2==3&&xy2==6)||(xx3==3&&xy3==6)||(xx4==3&&xy4==6)||(xx5==3&&xy5==6)){ System.out.print("㊣"); }else if(rx==3&&ry==6){ System.out.print("♀"); }else{ System.out.print("☆"); } }else if(x==3&&y==7){ if((xx1==3&&xy1==7)||(xx2==3&&xy2==7)||(xx3==3&&xy3==7)||(xx4==3&&xy4==7)||(xx5==3&&xy5==7)){ System.out.print("㊣"); }else if(rx==3&&ry==7){ System.out.print("♀"); }else{ System.out.print("☆"); } }else if(a[y][x]==2){ System.out.print("●"); }else if(a[y][x]==1){ System.out.print("♀"); }else{ System.out.print(" "); } } System.out.println(); } if((xx1==3&&xy1<8&&xy1>2)&&(xx2==3&&xy2<8&&xy2>2)&&(xx3==3&&xy3<8&&xy3>2)&&(xx4==3&&xy4<8&&xy4>2)&&(xx5==3&&xy5<8&&xy5>2)){ System.out.println("挑战成功");break; } System.out.println(XH); XH=""; System.out.println("操作提示:w(↑)a(←)s(↓)d(→)"); String d=in.next(); if(d.equalsIgnoreCase("w")){ if((rx==xx1&&ry==xy1+1)||(rx==xx2&&ry==xy2+1)||(rx==xx3&&ry==xy3+1)||(rx==xx4&&ry==xy4+1)||(rx==xx5&&ry==xy5+1)){ if(rx==xx1&&ry==xy1+1){ if(xy1==1||(xy1==3&&(xx1==1||xx1==2||xx1==5))||(xx1==xx2&&xy1==xy2+1)||(xx1==xx3&&xy1==xy3+1)||(xx1==xx4&&xy1==xy4+1)||(xx1==xx5&&xy1==xy5+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy1][xx1]=0;ry=ry-1;xy1=xy1-1;a[ry][rx]=1;a[xy1][xx1]=2; } }else if(rx==xx2&&ry==xy2+1){ if(xy2==1||(xy2==3&&(xx2==1||xx2==2||xx2==5))||(xx2==xx1&&xy2==xy1+1)||(xx2==xx3&&xy2==xy3+1)||(xx2==xx4&&xy2==xy4+1)||(xx2==xx5&&xy2==xy5+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy2][xx2]=0;ry=ry-1;xy2=xy2-1;a[ry][rx]=1;a[xy2][xx2]=2; } }else if(rx==xx3&&ry==xy3+1){ if(xy3==1||(xy3==3&&(xx3==1||xx3==2||xx3==5))||(xx3==xx2&&xy3==xy2+1)||(xx1==xx3&&xy3==xy1+1)||(xx3==xx4&&xy3==xy4+1)||(xx3==xx5&&xy3==xy5+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy3][xx3]=0;ry=ry-1;xy3=xy3-1;a[ry][rx]=1;a[xy3][xx3]=2; } }else if(rx==xx4&&ry==xy4+1){ if(xy4==1||(xy4==3&&(xx4==1||xx4==2||xx4==5))||(xx4==xx2&&xy4==xy2+1)||(xx4==xx3&&xy4==xy3+1)||(xx1==xx4&&xy4==xy1+1)||(xx4==xx5&&xy4==xy5+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy4][xx4]=0;ry=ry-1;xy4=xy4-1;a[ry][rx]=1;a[xy4][xx4]=2; } }else if(rx==xx5&&ry==xy5+1){ if(xy5==1||(xy5==3&&(xx5==1||xx5==2||xx5==5))||(xx5==xx2&&xy5==xy2+1)||(xx5==xx3&&xy5==xy3+1)||(xx5==xx4&&xy5==xy4+1)||(xx1==xx5&&xy5==xy1+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy5][xx5]=0;ry=ry-1;xy5=xy5-1;a[ry][rx]=1;a[xy5][xx5]=2; } } }else if(ry==1||(ry==3&&(rx<3||rx>4))){ XH="走不动啦!"; }else{ a[ry][rx]=0;ry=ry-1;a[ry][rx]=1; } } if(d.equalsIgnoreCase("s")){ if((rx==xx1&&ry==xy1-1)||(rx==xx2&&ry==xy2-1)||(rx==xx3&&ry==xy3-1)||(rx==xx4&&ry==xy4-1)||(rx==xx5&&ry==xy5-1)){ if(rx==xx1&&ry==xy1-1){ if(xy1==7||(xy1==6&&(xx1==1||xx1==1))||(xy1==5&&xx1==5)||(xx1==xx2&&xy1==xy2-1)||(xx1==xx3&&xy1==xy3-1)||(xx1==xx4&&xy1==xy4-1)||(xx1==xx5&&xy1==xy5-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy1][xx1]=0;ry=ry+1;xy1=xy1+1;a[ry][rx]=1;a[xy1][xx1]=2; } }else if(rx==xx2&&ry==xy2-1){ if(xy2==7||(xy2==6&&(xx2==1||xx2==2))||(xy2==5&&xx2==5)||(xx1==xx2&&xy2==xy1-1)||(xx2==xx3&&xy2==xy3-1)||(xx2==xx4&&xy2==xy4-1)||(xx2==xx5&&xy2==xy5-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy2][xx2]=0;ry=ry+1;xy2=xy2+1;a[ry][rx]=1;a[xy2][xx2]=2; } }else if(rx==xx3&&ry==xy3-1){ if(xy3==7||(xy3==6&&(xx3==1||xx3==2))||(xy3==5&&xx3==5)||(xx3==xx2&&xy3==xy2-1)||(xx1==xx3&&xy3==xy1-1)||(xx3==xx4&&xy3==xy4-1)||(xx3==xx5&&xy3==xy5-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy3][xx3]=0;ry=ry+1;xy3=xy3+1;a[ry][rx]=1;a[xy3][xx3]=2; } }else if(rx==xx4&&ry==xy4-1){ if(xy4==7||(xy4==6&&(xx4==1||xx4==1))||(xy4==5&&xx4==5)||(xx4==xx2&&xy4==xy2-1)||(xx4==xx3&&xy4==xy3-1)||(xx1==xx4&&xy4==xy1-1)||(xx4==xx5&&xy4==xy5-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy4][xx4]=0;ry=ry+1;xy4=xy4+1;a[ry][rx]=1;a[xy4][xx4]=2; } }else if(rx==xx5&&ry==xy5-1){ if(xy5==7||(xy5==6&&(xx5==1||xx5==2))||(xy5==5&&xx5==5)||(xx5==xx2&&xy5==xy2-1)||(xx5==xx3&&xy5==xy3-1)||(xx5==xx4&&xy5==xy4-1)||(xx1==xx5&&xy5==xy1-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy5][xx5]=0;ry=ry+1;xy5=xy5+1;a[ry][rx]=1;a[xy5][xx5]=2; } } }else if(ry==7||(ry==6&&rx==4)||(ry==5&&(rx==1||rx==2))||(ry==4&&rx==5)){ XH="走不动啦!"; }else{ a[ry][rx]=0;ry=ry+1;a[ry][rx]=1; } } if(d.equalsIgnoreCase("a")){ if((ry==xy1&&rx==xx1+1)||(ry==xy2&&rx==xx2+1)||(ry==xy3&&rx==xx3+1)||(ry==xy4&&rx==xx4+1)||(ry==xy5&&rx==xx5+1)){ if(ry==xy1&&rx==xx1+1){ if(xx1==1||(xx1==3&&(xy1<3||xy1>5))||(xy1==xy2&&xx1==xx2+1)||(xy1==xy3&&xx1==xx3+1)||(xy1==xy4&&xx1==xx4+1)||(xy1==xy5&&xx1==xx5+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy1][xx1]=0;rx=rx-1;xx1=xx1-1;a[ry][rx]=1;a[xy1][xx1]=2; } }else if(ry==xy2&&rx==xx2+1){ if(xx2==1||(xx2==3&&(xy2<3||xy2>5))||(xy1==xy2&&xx2==xx1+1)||(xy2==xy3&&xx2==xx3+1)||(xy2==xy4&&xx2==xx4+1)||(xy2==xy5&&xx2==xx5+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy2][xx2]=0;rx=rx-1;xx2=xx2-1;a[ry][rx]=1;a[xy2][xx2]=2; } }else if(ry==xy3&&rx==xx3+1){ if(xx3==1||(xx3==3&&(xy3<3||xy3>5))||(xy3==xy2&&xx3==xx2+1)||(xy1==xy3&&xx3==xx1+1)||(xy3==xy4&&xx3==xx4+1)||(xy3==xy5&&xx3==xx5+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy3][xx3]=0;rx=rx-1;xx3=xx3-1;a[ry][rx]=1;a[xy3][xx3]=2; } }else if(ry==xy4&&rx==xx4+1){ if(xx4==1||(xx4==3&&(xy4<3||xy4>5))||(xy4==xy2&&xx4==xx2+1)||(xy4==xy3&&xx4==xx3+1)||(xy1==xy4&&xx4==xx1+1)||(xy4==xy5&&xx4==xx5+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy4][xx4]=0;rx=rx-1;xx4=xx4-1;a[ry][rx]=1;a[xy4][xx4]=2; } }else if(ry==xy5&&rx==xx5+1){ if(xx5==1||(xx5==3&&(xy5<3||xy5>5))||(xy5==xy2&&xx5==xx2+1)||(xy5==xy3&&xx5==xx3+1)||(xy5==xy4&&xx5==xx4+1)||(xy1==xy5&&xx5==xx1+1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy5][xx5]=0;rx=rx-1;xx5=xx5-1;a[ry][rx]=1;a[xy5][xx5]=2; } } }else if(rx==1||(rx==3&&(ry<3||ry>5))){ XH="走不动啦!"; }else{ a[ry][rx]=0;rx=rx-1;a[ry][rx]=1; } } if(d.equalsIgnoreCase("d")){ if((ry==xy1&&rx==xx1-1)||(ry==xy2&&rx==xx2-1)||(ry==xy3&&rx==xx3-1)||(ry==xy4&&rx==xx4-1)||(ry==xy5&&rx==xx5-1)){ if(ry==xy1&&rx==xx1-1){ if(xx1==5||(xx1==4&&xy1!=3&&xy1!=4)||(xx1==3&&xy1==7)||(xy1==xy2&&xx1==xx2-1)||(xy1==xy3&&xx1==xx3-1)||(xy1==xy4&&xx1==xx4-1)||(xy1==xy5&&xx1==xx5-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy1][xx1]=0;rx=rx+1;xx1=xx1+1;a[ry][rx]=1;a[xy1][xx1]=2; } }else if(ry==xy2&&rx==xx2-1){ if(xx2==5||(xx2==4&&xy2!=3&&xy2!=4)||(xx2==3&&xy2==7)||(xy1==xy2&&xx2==xx1-1)||(xy2==xy3&&xx2==xx3-1)||(xy2==xy4&&xx2==xx4-1)||(xy2==xy5&&xx2==xx5-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy2][xx2]=0;rx=rx+1;xx2=xx2+1;a[ry][rx]=1;a[xy2][xx2]=2; } }else if(ry==xy3&&rx==xx3-1){ if(xx3==5||(xx3==4&&xy3!=3&&xy3!=4)||(xx3==3&&xy3==7)||(xy3==xy2&&xx3==xx2-1)||(xy1==xy3&&xx3==xx1-1)||(xy3==xy4&&xx3==xx4-1)||(xy3==xy5&&xx3==xx5-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy3][xx3]=0;rx=rx+1;xx3=xx3+1;a[ry][rx]=1;a[xy3][xx3]=2; } }else if(ry==xy4&&rx==xx4-1){ if(xx4==5||(xx4==4&&xy4!=3&&xy4!=4)||(xx4==3&&xy4==7)||(xy4==xy2&&xx4==xx2-1)||(xy4==xy3&&xx4==xx3-1)||(xy1==xy4&&xx4==xx1-1)||(xy4==xy5&&xx4==xx5-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy4][xx4]=0;rx=rx+1;xx4=xx4+1;a[ry][rx]=1;a[xy4][xx4]=2; } }else if(ry==xy5&&rx==xx5-1){ if(xx5==5||(xx5==4&&xy5!=3&&xy5!=4)||(xx5==3&&xy5==7)||(xy5==xy2&&xx5==xx2-1)||(xy5==xy3&&xx5==xx3-1)||(xy5==xy4&&xx5==xx4-1)||(xy1==xy5&&xx5==xx1-1)){ XH="推不动啦!"; }else{ a[ry][rx]=0;a[xy5][xx5]=0;rx=rx+1;xx5=xx5+1;a[ry][rx]=1;a[xy5][xx5]=2; } } }else if(rx==5||(rx==4&&(ry<3||ry>4))||(rx==3&&ry==7)){ XH="走不动啦!"; }else{ a[ry][rx]=0;rx=rx+1;a[ry][rx]=1; } } }while(true); } } /* 2←4←5↓3↓2→→3↑←4→→2←←4↑1↓↓↓↓2→↑4←↓3→2↓ */
楼主好功底啊!
楼主好NB
楼主好无聊