具有特殊属性的瓷砖

时间:2014-10-30 04:58:36

标签: java attributes tile game-development

所以我正在创建一个基于区块的游戏,如果主要玩家控制的角色进入地图上的某些区域,他/她会获得能量提升或中毒,这取决于玩家角色进入/落入哪个区块。我已经已经创建了一个带有玩家对象的二维数组。所以我想问一下如何实施踩到地图上某些位置的助力或中毒角色。所以我想知道我是否必须创建一个额外的维度来在我的地图中添加这些特殊的“区域”,或者我创建一个额外的链接列表来存储特殊的“区域”并实现它们?

 public final class Engine
{
    private int maximumAttackerWarrior;
    private int maximumDefenderWarrior;
    private int attackerWarrior;
    private int defenderWarrior;
    private final Random rand;
    private ArrayList<Integer> defenderA;
    private ArrayList<Integer> attackerA;

    /**
     * Constructor of class Engine
     */
    public Engine()    {
        // initialise instance variables
        rand = new Random();
        maximumAttackerWarrior = 0;
        maximumDefenderarrior = 0;
        attackerWarrior = 0;
        defenderWarrior = 0;
        defenderDices = new ArrayList<Integer>();
        attackerDices = new ArrayList<Integer>();
    }
public map{
// purely for visualization purposes 
Zones [][] map =
{
    {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
 };}}

1 个答案:

答案 0 :(得分:1)

如果您将使用的唯一磁贴类型是boost / poison,那么我将使用map数组来存储每个位置的boost / poison值(正值表示boost和Negative含义,0表示常规tile)。并分别存储玩家x和y位置。

另一方面,如果您认为以后可能会有更多花哨的瓷砖,我会采用面向对象的方法,其中地图包含瓷砖对象(如果您的地图,您可以使用GoF Flyweight模式来消除重复的对象创建非常大。)

希望这有帮助