Example #1
0
 private void highlightWinningSequence()
 {
     //the last possible winning sequence is the one that registered a win, use it again here
     for (int n = 0; n < m_possible_winning_tiles.Length; n++)
     {
         TTT_Tile winning_tile = m_possible_winning_tiles[n];
         winning_tile.m_scale_pulser.activatePulsingButton(n * WIN_PULSE_DELAY);
     }
 }
Example #2
0
    private int searchSequenceForWin(WinConditions.TileSequence tile_sequence)
    {
        //returns index of winning player (or -1)

        //build up the (temp, reused) potential winning tile sequence for examination
        for (int n = 0; n < tile_sequence.Tiles.Length; n++)
        {
            m_possible_winning_tiles[n] = m_board_tiles[tile_sequence.Tiles[n]];
        }

        //first, look for empty tiles. if any tiles are empty, there cannot be a win
        for (int n = 0; n < m_possible_winning_tiles.Length; n++)
        {
            if (m_possible_winning_tiles[n].getTileMarkState() == TTT_Tile.TileState.NONE)
            {
                return(-1);
            }
        }

        //next, compare the first tile to all other tiles. if any fail to match, no winner
        TTT_Tile first_tile = m_possible_winning_tiles[0];

        for (int n = 1; n < m_possible_winning_tiles.Length; n++)
        {
            TTT_Tile compare_tile = m_possible_winning_tiles[n];
            if (first_tile.getTileMarkState() != compare_tile.getTileMarkState())
            {
                //not a match, no win possible here
                return(-1);
            }
        }

        //all the tiles are marked and match one another. return the winners index
        if (first_tile.getTileMarkState() == TTT_Tile.TileState.PLAYER_1)
        {
            return((int)TTT_GameManager.PlayerIndex.Player1);
        }
        else if (first_tile.getTileMarkState() == TTT_Tile.TileState.PLAYER_2)
        {
            return((int)TTT_GameManager.PlayerIndex.Player2);
        }
        else
        {
            Debug.LogError("Winning tile mark does not belong to either player. Something went horribly wrong");
        }

        return(-1);
    }
Example #3
0
    public void constructGameBoard(int grid_size)
    {
        showBoard();

        if (m_board_constructed)
        {
            //board is already constructed from a previous game, no need to do it again
            return;
        }

        //Resize the gameboard image to fit all tiles
        float board_side_length = (m_tile_spacing * (grid_size)) + (2 * m_outer_board_buffer_width);

        m_board_rectform.sizeDelta = new Vector2(board_side_length, board_side_length);


        //Fill the board with tiles
        float half_anchor_width = m_tile_spacing * grid_size / 2;

        m_board_tiles = new List <TTT_Tile>();
        for (int n = 0; n < grid_size; n++)
        {
            for (int m = 0; m < grid_size; m++)
            {
                //this will construct the grid left to right, top to bottom (indices increase like a page of text)
                Vector2 tile_position = new Vector2(-half_anchor_width + ((n + 0.5f) * m_tile_spacing), half_anchor_width - ((m + 0.5f) * m_tile_spacing));

                //create tile, set position within grid
                GameObject    new_tile_go = Instantiate(m_tile_prefab, transform);
                RectTransform rectform    = new_tile_go.GetComponent <RectTransform>();
                rectform.anchoredPosition = tile_position;

                //add ref to active list for further access
                TTT_Tile new_tile = new_tile_go.GetComponent <TTT_Tile>();
                m_board_tiles.Add(new_tile);
                new_tile.assignGridIndices(n, m);
            }
        }

        //define the win conditions for this board
        //define win-examination array for reuse based on grid size
        m_possible_winning_tiles = new TTT_Tile[grid_size];
        if (grid_size == 3)
        {
            m_active_win_conditions = m_3x3_winconditions;
        }
        else if (grid_size == 4)
        {
            m_active_win_conditions = m_4x4_winconditions;
        }
        else
        {
            Debug.LogError("No win conditions found for grid size " + grid_size);
        }

        //mark that the board is constructed
        m_board_constructed = true;

#if UNITY_EDITOR
        verifyWinConditions(grid_size);
#endif
    }