gpt4 book ai didi

java - 创建并连接游戏的位置

转载 作者:行者123 更新时间:2023-12-01 12:09:29 25 4
gpt4 key购买 nike

我想制作一款文本冒险游戏作为学校项目,我想知道如何创建连接故事发生的游戏地点.

我想创建一个父类(super class) Location ,其中包含诸如 name 之类的变量和像这样的二维数组

int[][] locnow = new int[20][20];

用于位置本身(北、西、东、南点)。

我的主要问题是

  1. 以这种方式实现类似的事情是一个好方法,还是其他更好的方法?
  2. 如何加载“单击按钮 -> 向东”等位置并加载向东一处的位置?

感谢您的帮助。

最佳答案

关于:

public class Location {
private int x, y;
private String name;

// getters and setters here
}

结合

public class Game {
private GameTile[][] field;

// getters and setters here
}

public class GameTile {
// some tile-specific information goes here
}

这样,您就可以存储游戏领域的特定信息(如果需要,可以存储在 GameTile 中)。如果不需要 GameTile 类,则可以省略 Game 类中的数组,只存储最大尺寸。

<小时/>

这如何回答您的问题:

  • 向东走就是x += 1
  • 西x -= 1
  • 等等...

关于java - 创建并连接游戏的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27344062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com