2014-10-30 71 views
0

所以我創建了一個基於瓷磚的遊戲,如果主要玩家控制的角色步入地圖上的某些區域,他/她獲得能量提升或中毒,具體取決於玩家角色踩/落地的瓦片。我已經創建了一個包含player對象的二維數組。所以我想問一下,我應該如何在地圖上的某些位置上實施助推或中毒角色。所以我想知道是否必須創建一個額外的維度來在我的地圖中添加這些特殊的「區域」,或者我創建了一個額外的鏈接列表來存儲特殊的「區域」並實施它們?具有特殊屬性的瓷磚

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是有規律的升壓/毒藥值瓦)。並分別儲存玩家的x和y位置。另一方面,如果您認爲以後可能會有更多花式瓷磚,那麼我會採用面向對象的方法,其中地圖包含瓷磚對象(您可以使用GoF Flyweight模式消除重複的對象創建,如果您的地圖非常大)。

希望這有助於

+0

是,幫助這麼多非常感謝你我的朋友,我想我會去GoF的享元模式閱讀起來。 – 2014-10-30 05:42:16