Ejemplo n.º 1
0
    /// <summary>
    /// Removes a piece from the considered tower.
    /// </summary>
    /// <param name="piece">The piece to remove</param>
    public void DeconsiderPiece(OverstackPieceUI piece)
    {
        // Remove from the considered list
        consideredPieces.Remove(piece);
        piece.Considered = false;

        // Deselected a hook piece
        if (piece.Piece.type == PieceData.Type.Hook)
        {
            hookConsidered = false;
        }

        // Update the considered tower
        BuildConsideredTower();
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Considers a piece to be put into the considered tower.
    /// </summary>
    /// <param name="consideredPiece">The piece to consider</param>
    public void ConsiderPiece(OverstackPieceUI consideredPiece)
    {
        // Check if there are already six pieces
        if (consideredPieces.Count == 6)
        {
            return;
        }

        // Hook piece validation
        if (consideredPiece.Piece.type == PieceData.Type.Hook)
        {
            if (!hookConsidered)
            {
                hookConsidered = true;
            }
            else
            {
                if (!GameObject.Find("Taoex").GetComponent <TurnHandler>().GetCurrentPlayer().IsAI)
                {
                    GameObject.Find("OverstackError").GetComponent <OverstackError>().ShowError("Can't select more than one hook.");
                }
                return;
            }

            // Pushing the hook piece to the front of the list
            consideredPieces.AddFirst(consideredPiece);
        }
        else
        {
            // Add it to the considered list
            consideredPieces.AddLast(consideredPiece);
        }
        consideredPiece.Considered = true;

        // Update the considered tower
        BuildConsideredTower();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Handles AI choices for overstacking.
    /// </summary>
    /// <returns></returns>
    public IEnumerator AIOverstack()
    {
        // Get all the pieces by searching in the Overstack object
        GameObject ga = GameObject.Find("UICanvas").transform.Find("Overstack").gameObject;

        // List of possible indexes to choose
        List <int> indices = new List <int>();

        for (int i = 0; i < ga.transform.childCount; i++)
        {
            indices.Add(i);
        }

        // Select one of own pieces first
        for (int i = 0; i < ga.transform.childCount; i++)
        {
            // Information about the overstack piece
            OverstackPieceUI overstackPiece = ga.transform.GetChild(i).GetComponent <OverstackPieceUI>();
            if (overstackPiece.Piece.colour == colour)
            {
                yield return(new WaitForSeconds(AIDelay));

                // Select the piece
                overstackPiece.OnMouseUpAsButton();

                indices.Remove(i);
                break;
            }
        }

        // Attempt to select a hook
        for (int i = 0; i < ga.transform.childCount; i++)
        {
            // Information about the overstack piece
            OverstackPieceUI overstackPiece = ga.transform.GetChild(i).GetComponent <OverstackPieceUI>();
            if (overstackPiece.Piece.type == PieceData.Type.Hook)
            {
                yield return(new WaitForSeconds(AIDelay));

                // Select the piece
                overstackPiece.OnMouseUpAsButton();

                indices.Remove(i);
                break;
            }
        }

        // Keep selecting random pieces
        while (indices.Count > 0)
        {
            yield return(new WaitForSeconds(AIDelay));

            int randomIndex = new System.Random().Next(0, indices.Count);
            OverstackPieceUI overstackPiece = ga.transform.GetChild(indices[randomIndex]).GetComponent <OverstackPieceUI>();
            overstackPiece.OnMouseUpAsButton();

            indices.RemoveAt(randomIndex);
        }

        // Done selecting
        GameObject.Find("UICanvas").transform.Find("DoneOverstackBtn").GetComponent <OverstackBtnClick>().Finished();
    }