微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JavaFXML:GridPane映射

如何解决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 举报,一经查实,本站将立刻删除。