Example #1
0
    IEnumerator WinVisualsRoutine(byte playerId, Vector2Int start, Vector2Int delta)
    {
        // Wait for the ball drop visual to complete before continuing
        yield return(new WaitForSeconds(1.0f));

        // Show the "You Win", "You Lose" or "Stalemate" text
        StartCoroutine(WinVisualsTextRoutine(playerId));

        // Highlight winning sequence
        if (ConnectFour.IsPlayerValid(playerId))
        {
            // Three times
            for (int count = 0; count < 3; count++)
            {
                // For each ball in the winning sequence
                for (int i = 0; i < ConnectFour.SEQ_COUNT; i++)
                {
                    // Get the placed ball at an offset from the start of the winning sequence
                    var obj = placedVisuals[start.x + (delta.x * i), start.y + (delta.y * i)];
                    var r   = obj.GetComponent <Renderer>();

                    // Wait 0.5 seconds between each item
                    yield return(new WaitForSeconds(0.5f));

                    StartCoroutine(WinVisualsItemRoutine(playerId, r));
                }
            }
        }

        // Wait 1 second for padding
        yield return(new WaitForSeconds(1.0f));

        completedWinVisuals = true;
    }
Example #2
0
 public static byte GetOtherPlayer(byte playerId)
 {
     if (ConnectFour.IsPlayerValid(playerId))
     {
         return(playerId == 1 ? ConnectFour.PLAYER_TWO : ConnectFour.PLAYER_ONE);
     }
     else
     {
         return(0);
     }
 }
Example #3
0
    // Does the move for this board in a specific column.
    // If this returns true, the move resulted in a win and we should stop constructing the board deeper than this point
    public bool DoMove(int column)
    {
        if (!ConnectFour.IsPlayerValid(move.playerId))
        {
            Debug.LogError("BoardState : Set valid playerId first!");
            return(false);
        }

        move.column = column;
        board.Drop(move.playerId, column, out move.row);
        UpdateScore();

        // Return true if the column is now occupied, or the move won, or if it was a stalemate
        return(board.IsSpaceOccupied(column, 0) || board.CheckForWinIncremental(move.playerId, move.coord) || board.CheckForStalemate());
    }