Exemplo n.º 1
0
    public void CreateBoard()
    {
        if (currentBoard != null)
        {
            Destroy(currentBoard.gameObject);
        }

        board = new Cell[rows, cols];
        GameObject newBoard = new GameObject("Game Board");

        currentBoard = newBoard.AddComponent <Board>();

        for (int r = 0; r < rows; r++)
        {
            for (int c = 0; c < cols; c++)
            {
                if (r == 0 && c == 0)
                {
                    if (player != null)
                    {
                        PlayerControl newPlayer = Instantiate(player, newBoard.transform);
                        newPlayer.SetStartingPosition(r, c);
                        Cell clone = Instantiate(playSpaces[0], newBoard.transform);
                        clone.SetNewLocation((r * 10), (c * 10));
                        board[r, c] = clone;
                    }
                    else
                    {
                        Debug.LogError("Player PreFab reference is missing!!!");
                    }
                }//        this is the clue and mine placement factor
                else if (c == 0 && r == 7)
                {
                    if (escort != null)
                    {
                        PlayerControl battleship = Instantiate(escort, newBoard.transform);
                        battleship.SetStartingPosition(r * 10, c * 10);
                        Cell clone = Instantiate(playSpaces[0], newBoard.transform);
                        clone.SetNewLocation((r * 10), (c * 10));
                        board[r, c] = clone;
                    }
                    else
                    {
                        Debug.LogError("Player PreFab reference is missing!!!");
                    }
                }
                else if ((RandomMathEquation(r, c) && mineCount < totalMines && DiceRoll() == 2))
                {
                    Shadows mineClone = Instantiate(mineShadow, newBoard.transform);
                    mineClone.isMineSpot = true;
                    mineClone.SetNewLocation((r * 10), (c * 10));
                    board[r, c] = mineClone;
                    mineCount++;
                }
                else if ((r == rows - 1) && (c == cols - 1))
                {
                    Cell clone = Instantiate(playSpaces[3], newBoard.transform);
                    clone.SetNewLocation((r * 10), (c * 10));
                    board[r, c] = clone;
                }
                else
                {
                    Cell randomGridPiece = PickRandomCell();
                    Cell clone           = Instantiate(randomGridPiece, newBoard.transform);
                    clone.SetNewLocation((r * 10), (c * 10));
                    board[r, c] = clone;
                }
            }
        }
    }