Exemplo n.º 1
0
    public void CreateBoard()
    {
        if (m_board != null)
        {
            //kill the existing board
            for (int i = 0; i < C_BOARD_SIZE; i++)
            {
                m_board[i].Destroy();
                m_board[i] = null;
            }

            m_board = null;
        }
        Debug.Log("Creating board");

        m_board = new GameCell[C_BOARD_SIZE];

        float startX = -((C_CELL_SIZE * C_BOARD_WIDTH) / 2);
        float startY = -((C_CELL_SIZE * C_BOARD_WIDTH) / 2);

        for (int x = 0; x < C_BOARD_WIDTH; x++)
        {
            for (int y = 0; y < C_BOARD_WIDTH; y++)
            {
                GameCell c = new GameCell();
                c.m_cell       = GameObject.CreatePrimitive(PrimitiveType.Cube);
                c.m_cellScript = c.m_cell.AddComponent("Cell") as Cell;
                //c.m_cell.AddComponent("MeshFlasher");

                c.m_cell.transform.position   = new Vector3(startX + x * C_CELL_SIZE, startY + y * C_CELL_SIZE, 0);
                c.m_cell.transform.localScale = new Vector3(C_CELL_SIZE, C_CELL_SIZE, 0);

                c.m_cellScript.m_x = x;
                c.m_cellScript.m_y = y;

                c.Set(G.CELL_EMPTY);

                //put it in its slot:
                m_board[GetCellIndex(x, y)] = c;
            }
        }
    }