English 中文(简体)
Point and Arraylyn Java
原标题:Point and Array game Java

我现在想在吉拉瓦建立一个大的游戏(而不是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);
}   
}

这正是我们的工作方式。 我曾试图另设一个职位类别,但我没有这样做。 ......

问题回答

建立2D阵列,可以在2D阵列中油漆一个电池(其中可能含有按电池价值界定的不同物体)。 因此,你可以检查广场油漆,如果价值是人体(事先确定的常数),那么该地点就会有人在屏幕上抽取。

void paint_cell(int x, int y) {
  if (array[x][y] == HUMAN) {
   printf("H");
  } else if (array[x][y] == ENEMY) {
    printf("E");
  } else if (array[x][y] == EMPTY) {
    printf(" ");
  }
}

void paint_maze() {
   for (int j = 0; j < 12; j++) {
       printf("|");
       for (int i = 0; i < 12; i++) {
          paint_cell(i,j);
       }
       printf("|
");
   }
}

当你收到一次关键事件时,会去人所在的囚室,然后根据钥匙转移到一个新的目的地。 然后又把马齐格人带走。

“阿雷”无疑是正确的想法——一个两维阵列可能是我用来控制电网的空间。 但是,在阵列中将怎么办? 代表用户移动空间的物体? 这种冷却;你必须说明如何界定这些空间,并表明如何在屏幕上显示每个空间。

You probably can t use a KeyListener to check for user keystrokes, since KeyListener is part of AWT/Swing, but you will need a way to get input from the keyboard. Reading from stdin is the easy way to go here. You will need to run a loop that listens for user input at the keyboard, and moves the user s "gamepiece" from square to square depending on which key they hit.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签