我现在想在吉拉瓦建立一个大的游戏(而不是gui),但现在,我很想知道,我会如何建立一个12x12的电网,在0时(左上角) player一个角色,并用钥匙把他移走?
我试图制造一个阵列,但似乎没有人去工作。 我要说一个新奇,因此欢迎任何建议。
package hunters;
import java.io.*;
import java.util.*;
import java.awt.*;
public class Hunters {
private static int score;
private static String player = "P";
private static String move;
private static String emptyfield = "X";
private static String [][]a2 = new String [12][12];
private static int pr,cr;
public static void paint_board(){
for (int r = 0 ; r < a2.length; r++){
for (int c= 0; c <a2[r].length; c++){
a2 [r][c] = emptyfield;
a2[pr][cr] = player;
System.out.print(" "+a2[r][c]);
}
System.out.println("");
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
score = 0;
paint_board();
do{
System.out.println("Input your move");
move = in.nextLine();
if (move.equalsIgnoreCase("w")){
//move up
a2[pr-1][cr]= player;
//repaint
paint_board();
//check for collision
//check for health
}else if(move.equalsIgnoreCase("s")){
//move down
a2[pr+1][cr]= player;
//repaint
paint_board();
//check for collision
//check for health
}else if(move.equalsIgnoreCase("d")){
//move right
a2[pr][cr+1] = player;
//repaint
paint_board();
//check for collision
//check for health
}else if(move.equalsIgnoreCase("a")){
//move left
a2[pr][cr-1]=player;
//repaint
paint_board();
//check for collision
//check for health
}
}while(score !=5);
}
}
这正是我们的工作方式。 我曾试图另设一个职位类别,但我没有这样做。 ......