JavaFXML:GridPane映射

问题描述

我正在制作一个基于文本的冒险游戏,我在网格窗格上有一个地图控件,当玩家进入房间时,该控件显示不同的房间。我想添加一项功能,允许玩家当前位置显示在他当前所在的房间内。

这是GridPane类的示例,我尝试使用其中一个房间(吉萨房间)来显示当前位置,如下所示,但是它不起作用。

     public class GridMap extends GridPane {
      GameController gc = new GameController();
      Game curGame = new Game();
      Player curPlayer = new Player();
      Room curRoom = curPlayer.getCurrentRoom();

  GridPane g = new GridPane();


  public GridMap(GridPane gp) throws IOException {

      g = gp;
  }

  public void displayPlayerLocation(int colIndex,int rowIndex){
    Region playerlocation = new Region();
    playerlocation.setStyle("-fx-background-color: white");
    playerlocation.setMaxHeight(10);
    playerlocation.setMaxWidth(10);
    Node n = playerlocation;
    g.add(n,colIndex,rowIndex,10,10);

}

public void setGizaRoom() {

    try {

        Region ta = new Region();
        ta.setStyle("-fx-background-color: coral");
        ta.setMaxWidth(40);
        ta.setMaxHeight(40);
         Room room = curGame.getGizaRoom();
        Node n = ta;
        g.add(n,40,40);
        Tooltip hoverInfo = new Tooltip("Room name : " + room.getName() + "Item: " + 
        room.getItem().name());
        Tooltip.install(n,hoverInfo);
        System.out.println(curPlayer.getCurrentRoom().getName());



        if (curRoom == curGame.getGizaRoom()){
            displayPlayerLocation(0,0);

        } 

我有一个带有Player类的游戏模型,该类由访问器方法getCurrentRoom()和setCurrentRoom()组成,还有一个带有房间描述和名称的Room类,等等。 在UI控制器中调用网格窗格类,如下所示:

  public class GameController {


  public Stage gameStage = new Stage();
  ArrayList<Object> list = new ArrayList<>();

  @FXML
  public Button save;
  public Button exit;
  public TextArea Output;
  public TextField Input;
  public ListView<String> InventoryControl;
  public GridPane GridMap;

  GridMap g = new GridMap(GridMap);
 

  //this if statement gets used in a method called InterpretCommand() which analyzes input from the 
    user and displays the room on on the grid map if user enters that room
                           if (curRoom == curGame.getGizaRoom()){
                                g.setGizaRoom();
                            }

我将如何实现玩家的当前位置,并将其从上一个房间中移除并添加到新房间中?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...