import java.util.Scanner;
public class migong {
public static void main(String[] args) {
String[][] map = {
{ "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#" },
{ "#", "O", "#", " ", " ", " ", "#", " ", " ", "#", "#", "#" },
{ "#", " ", "#", " ", "#", " ", " ", " ", "#", "#", " ", " " },
{ "#", " ", "#", " ", "#", " ", "#", "#", "#", "#", " ", "#" },
{ "#", " ", " ", " ", "#", " ", " ", "#", "#", " ", " ", "#" },
{ "#", " ", "#", "#", "#", " ", " ", " ", "#", " ", "#", "#" },
{ "#", " ", "#", "#", "#", "#", "#", " ", "#", " ", "#", "#" },
{ "#", " ", "#", " ", " ", " ", "#", " ", "#", " ", "#", "#" },
{ "#", " ", "#", " ", "#", "#", " ", " ", "#", " ", "#", "#" },
{ "#", " ", "#", " ", "#", "#", " ", "#", "#", " ", "#", "#" },
{ "#", " ", " ", " ", "#", "#", " ", " ", " ", " ", " ", "#" },
{ "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#" } };
int x=1;
int y=1;
int endx=11;
int endy=2;
Scanner scanner=new Scanner(System.in);
while(true) {
boolean wan=false;
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[i].length; j++) {
System.out.print(map[i][j]+" ");
if(map[2][11].equals("O")) {
wan =true;
}
}
System.out.println();
}
if (wan) {
System.out.println("成功!!!");
return;
}
System.out.println("请输入操作:");
String move=scanner.nextLine();
if (move.equals("w")) {
if (map[x-1][y].equals("#")) {
System.out.println("您撞墙了!!!");
}else {
map[x-1][y]="O";
map[x][y]=" ";
x--;
}
}
if (move.equals("s")) {
if (map[x+1][y].equals("#")) {
System.out.println("您撞墙了啊!!!看着点!!!");
}else {
map[x+1][y]="O";
map[x][y]=" ";
x++;
}
}
if (move.equals("a")) {
if (map[x][y-1].equals("#")) {
System.out.println("您撞墙了!!");
}else {
map[x][y-1]="O";
map[x][y]=" ";
y--;
}
}
if (move.equals("d")) {
if (map[x][y+1].equals("#")) {
System.out.println("您撞墙了!!");
}else {
map[x][y+1]="O";
map[x][y]=" ";
y++;
}
}
}
}
}
java--迷宫小游戏
最新推荐文章于 2023-01-09 21:05:52 发布