如何在Android Studio中显示2D Tiles数组?

时间:2019-06-14 18:18:10

标签: java android

我正在尝试制作一个基于图块的游戏,其中随机图块点亮一秒钟并关闭。我创建了一个Tile对象的2D矩阵,想知道如何渲染/显示2D矩阵。如何使用Canvas和onDraw函数执行此操作?还是我可以使用其他渲染方法?先谢谢您的帮助!

瓷砖课:

public class Tile {
    String fileName;
    int symbolColor;
    int backgroundColor;
    boolean tested = false;         
    boolean seen = false;          
    int XxCor;
    int YyCor;

public Tile(int symbolColor, int backgroundColor, int x, int y) {
    this.backgroundColor = backgroundColor;
    this.symbolColor = symbolColor;
    XxCor = x;
    YyCor = y;
}

包含2D Tile Objects网格的World类

public class World {

    private int width;          // Width & Height of the world
    private int height;

    public static final String TAG = "MainActivity";

    private int FPxx = this.width / 2;         
    private int FPyy = this.height / 2;

    private int totalNumberOfTiles = width * height - 1;           
    private int TilesCounter;               

    private Random Pgenerator;      
    private Random Cgenerator;     

    private Tile[][] grid;
    public static final Tile NOTHING = new Tile(Color.BLACK,     Color.BLACK);       
private ArrayList<Tile> arrayOfMissedTiles = new ArrayList<>();        
private int missedTilesIndex = 0;     // Keeps track of the index No of the missed Tiles to re-display next
private int missedTilesInterval = 3;      // Number of Tiles to display before re-displaying a missed Tiles

/**
 *
 * @param width: width of the world grid
 * @param height: height of the world grid
 * @param seedP: seed for Peripheral points Random Generator
 * @param seedC: seed for Center points Random Generator
 */
public World(int width, int height, int seedP, int seedC) {
    this.width = width;
    this.height = height;
    grid = new Tile[width][height];
    Pgenerator = new Random(seedP);
    Cgenerator = new Random(seedC);
}

0 个答案:

没有答案