import java
.util
.Scanner
;
public class work6 {
public static void main(String
[] args
) {
Scanner input
= new Scanner(System
.in
);
int[][] map
= new int[10][10];
int rx
= 5;
int ry
= 4;
map
[rx
][ry
] = 1;
int xx
= 3;
int xy
= 2;
map
[xx
][xy
] = 2;
int zx
= 4;
int zy
= 1;
map
[zx
][zy
] = 3;
do {
for (int i
= 0; i
< map
.length
; i
++) {
for (int j
= 0; j
< map
[i
].length
; j
++) {
if (map
[i
][j
] == 0) {
System
.out
.print("口");
} else if (map
[i
][j
] == 1) {
System
.out
.print("汉");
} else if (map
[i
][j
] == 2) {
System
.out
.print("车");
} else if (map
[i
][j
] == 3) {
System
.out
.print("终");
}
}
System
.out
.println();
}
if(map
[xx
][xy
]==map
[zx
][zy
]){
System
.out
.println("恭喜你推车成功!");
break;
}
if (xx
==0||xx
==9||xy
==0||xy
==9) {
System
.out
.println("游戏失败");
break;
}
System
.out
.println("请输入方向:w上,s下,a左,d右");
String str
= input
.next();
if (str
.equals("w")) {
if(str
.equals("w")&&rx
==0){
rx
++;
map
[rx
][ry
]=map
[rx
+1][ry
];
map
[rx
][ry
]=1;
}else if(str
.equals("a")||str
.equals("S")||str
.equals("d")){
continue;
}
if(map
[rx
-1][ry
]==2){
xx
--;
map
[xx
][xy
]=2;
}
map
[rx
][ry
]=0;
rx
--;
map
[rx
][ry
]=1;
} else if (str
.equals("s")) {
if(str
.equals("s")&&rx
==9){
rx
--;
map
[rx
][ry
]=map
[rx
-1][ry
];
map
[rx
][ry
]=1;
}else if(str
.equals("w")||str
.equals("a")||str
.equals("d")){
continue;
}
if(map
[rx
+1][ry
]==2){
xx
++;
map
[xx
][xy
]=2;
}
map
[rx
][ry
]=0;
rx
++;
map
[rx
][ry
]=1;
} else if (str
.equals("a")) {
if(str
.equals("a")&&ry
==0){
ry
++;
map
[rx
][ry
]=map
[rx
][ry
+1];
map
[rx
][ry
]=1;
}else if(str
.equals("w")||str
.equals("S")||str
.equals("d")){
continue;
}
if(map
[rx
][ry
-1]==2){
xy
--;
map
[xx
][xy
]=2;
}
map
[rx
][ry
]=0;
ry
--;
map
[rx
][ry
]=1;
} else if (str
.equals("d")) {
if(str
.equals("d")&&rx
==0){
rx
++;
map
[rx
][ry
]=map
[rx
][ry
-1];
map
[rx
][ry
]=1;
}else if(str
.equals("a")||str
.equals("S")||str
.equals("w")){
continue;
}
if(map
[rx
][ry
+1]==2){
xy
++;
map
[xx
][xy
]=2;
}
map
[rx
][ry
]=0;
ry
++;
map
[rx
][ry
]=1;
}
map
[zx
][zy
]=3;
} while(true);
}
转载请注明原文地址:https://tech.qufami.com/read-19001.html