Example #1
0
    /// <summary>
    /// Converts the given playerColour into a usable Color object
    /// </summary>
    /// <returns>The real color.</returns>
    /// <param name="c">PlayerColour(Enum)</param>
    public static Color32 ConvertToColor32(Player.PlayerColour c)
    {
        switch (c)
        {
        case PlayerColour.Brown:
            return(new Color32(143, 90, 60, 255));

        case PlayerColour.Purple:
            return(new Color32(150, 100, 255, 255));

        case PlayerColour.Black:
            return(new Color32(70, 70, 70, 255));

        case PlayerColour.Red:
            return(new Color32(203, 64, 66, 255));

        case PlayerColour.Blue:
            return(new Color32(46, 169, 233, 255));

        case PlayerColour.Green:
            return(new Color32(0, 155, 0, 255));

        case PlayerColour.Hook:
            return(new Color32(255, 255, 0, 255));

        default:
            return(new Color32(0, 0, 0, 255));
        }
    }
Example #2
0
 /// <summary>
 /// Constructor for a new tower
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="startingPiece"></param>
 /// <param name="startNode"></param>
 public PieceTower(Player owner, PieceData startingPiece, TileNode startNode)
 {
     pieces       = new List <PieceData>(6);
     owningColour = owner.colour;
     owningPlayer = owner;
     AddPiece(startingPiece);
     node = startNode;
     MoveTo(startNode);
     startingPiece.SetupTextures();
 }
Example #3
0
    /// <summary>
    /// Gets the player by colour.
    /// </summary>
    /// <returns>The player by colour.</returns>
    /// <param name="colour">A playters colour enum. Does not work with hook "colour"</param>
    public Player getPlayerByColour(Player.PlayerColour colour)
    {
        // search each player for one with the correct colour
        foreach (Player p in players)
        {
            if (p.colour == colour)
            {
                return(p);
            }
        }

        // did not find a matching player
        return(null);
    }
Example #4
0
    /// <summary>
    /// Creates a piece.
    /// </summary>
    /// <returns>The piece.</returns>
    /// <param name="colour">Colour.</param>
    /// <param name="dir">Dir.</param>
    /// <param name="range">Range.</param>
    private PieceData CreatePiece(Player.PlayerColour colour, int dir, int range)
    {
        // only 6 directions
        Debug.Assert(0 <= dir && dir <= 5);

        // max range of 3
        Debug.Assert(1 <= range && range <= 3);

        // only hooks have range of 1
        if (colour == Player.PlayerColour.Hook)
        {
            Debug.Assert(range == 1);
        }
        else
        {
            Debug.Assert(range != 1);
        }

        // normal and flipped/alternate
        int normRan    = range;
        int normDir    = dir;
        int altRan     = normRan == 2 ? 3 : 2;
        int wheelIndex = normDir * 2;

        if (normRan == 3)
        {
            wheelIndex++;
        }

        // array "wheel" dir offset
        wheelIndex += dirWheelOffset[(int)colour, normRan == 2 ? 0 : 1];
        wheelIndex  = wheelIndex % 12;

        int altDir = dirWheel[wheelIndex];

        if (altDir == 1 || altDir == 4)
        {
            altDir = (altDir + 4) % 6;
        }
        else if (altDir == 5 || altDir == 2)
        {
            altDir = (altDir + 2) % 6;
        }

        // create piece
        PieceData piece = new PieceData(colour, normDir, normRan, altDir, altRan, Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/GameObject/HexagonPiece")));

        return(piece);
    }
Example #5
0
    /// <summary>
    /// Creates the tower at the given location.
    /// </summary>
    /// <param name="colour">Colour of the piece</param>
    /// <param name="dir">Direction based on hexagon (0 to 5)</param>
    /// <param name="range">Range of the piece (1 for hook, otherwise 2 or 3)</param>
    /// <param name="node">TileNode location.</param>
    private void CreateTower(Player.PlayerColour colour, int dir, int range, TileNode node)
    {
        // node must be clear of tower
        Debug.Assert(node.tower == null);

        Player player = GetComponentInParent <TurnHandler>().getPlayerByColour(colour);

        // no player found with colour
        if (player == null)
        {
            return;
        }

        // create piece
        PieceData piece = CreatePiece(colour, dir, range);

        // create tower at node location owned by player
        PieceTower tower = new PieceTower(player, piece, node);

        // add to player
        player.AddTower(tower);
    }
Example #6
0
    /// <summary>
    /// Constructor for a normal pieceData
    /// </summary>
    /// <param name="colour">The colour of the piece</param>
    /// <param name="normalDir">Normal direction that this peice can go</param>
    /// <param name="normalRan">Normal range that this piece can go</param>
    /// <param name="altDir">The alternative direction when this piece is captured</param>
    /// <param name="altRan">The alternative range when this piece is captured</param>
    /// <param name="obj">Game object associated with this pieceData</param>
    public PieceData(Player.PlayerColour colour, int normalDir, int normalRan, int altDir, int altRan, GameObject obj)
    {
        Debug.Assert(normalDir < 6 && normalDir >= 0, "PieceData's normal direction must be between 0 and 6");
        Debug.Assert(normalRan > 0, "PieceData's normal range must be greater than 0");
        Debug.Assert(altDir < 6 && altDir >= 0, "PieceData's alt direction must be between 0 and 6");
        Debug.Assert(altRan > 0, "PieceData's alt range must be greater than 0");
        Debug.Assert(obj != null, "PieceData's obj is null on creation");
        this.normalDir = normalDir;
        this.normalRan = normalRan;
        this.altDir    = altDir;
        this.altRan    = altRan;
        this.colour    = colour;
        this.obj       = obj;
        value          = 1;
        type           = Type.Normal;
        direction      = normalDir;
        range          = normalRan;

        obj.transform.SetParent(GameObject.Find("Pieces").transform);

        // Move to center of the board
        obj.transform.position = new Vector3(975, 1000, 925);
    }
Example #7
0
 /// <summary>
 /// Changes the colour which converts the int into the enum for representing player colour
 /// </summary>
 /// <param name="colour">Colour.</param>
 public void ChangeColour(int colour)
 {
     selectedColour = (Player.PlayerColour)colour;
     Debug.Log("Sandbox Colour= " + selectedColour);
 }
Example #8
0
    /// <summary>
    /// Constructor for overstacking.
    /// Sets up and displays the overstack interface.
    /// </summary>
    /// <param name="attacker">The attacking piece</param>
    /// <param name="victim">The victim piece</param>
    public void Construct(PieceTower attacker, PieceTower victim)
    {
        this.attacker  = attacker;
        this.victim    = victim;
        destination    = victim.GetNode();
        attackerColour = attacker.owningColour;

        done = false;

        // Offset the piece locations
        float offset = 0f;

        for (int i = attacker.pieces.Count - 1; i >= 0; i--)
        {
            PieceData p = attacker.pieces[i];
            // Duplicate the piece onto the canvas
            GameObject dup = GameObject.Instantiate(p.getObj());
            dup.AddComponent <OverstackPieceUI>();
            dup.GetComponent <OverstackPieceUI>().Piece = p;
            dup.transform.SetParent(transform, false);

            // Position on the screen
            Vector3 newPos = new Vector3(-250f, 150f - offset, 0f);
            Vector3 newRot = new Vector3(270f, 120f, 0f);

            // Flip pieces that are not the same colour as the attacker
            if (p.colour != attacker.owningColour && p.type != PieceData.Type.Hook)
            {
                newPos.y += 25f;
                newRot    = new Vector3(-270f, 60f, 0f);
                dup.GetComponent <OverstackPieceUI>().Flipped = true;
            }

            // Set the position and angles
            dup.transform.localPosition    = newPos;
            dup.transform.localEulerAngles = newRot;

            offset += 30f;
        }

        // Offset between towers
        offset += 30f;

        for (int i = victim.pieces.Count - 1; i >= 0; i--)
        {
            PieceData p = victim.pieces[i];
            // Duplicate the piece onto the canvas
            GameObject dup = GameObject.Instantiate(p.getObj());
            dup.AddComponent <OverstackPieceUI>();
            dup.GetComponent <OverstackPieceUI>().Piece   = p;
            dup.GetComponent <OverstackPieceUI>().Flipped = true;
            dup.transform.SetParent(transform, false);

            // Position on the screen
            Vector3 newPos = new Vector3(-250f, 175f - offset, 0f);
            Vector3 newRot = new Vector3(-270f, 60f, 0f);

            // Don't flip hook pieces or pieces that are the same colour as the attacker
            if (p.type == PieceData.Type.Hook || p.colour == attacker.owningColour)
            {
                newPos.y -= 25f;
                newRot    = new Vector3(270f, 120f, 0f);
                dup.GetComponent <OverstackPieceUI>().Flipped = false;
            }

            // Set the location and angles
            dup.transform.localPosition    = newPos;
            dup.transform.localEulerAngles = newRot;

            offset += 30;
        }

        offsets          = new int[] { 0, 25, 50, 75, 100, 125 };
        consideredPieces = new LinkedList <OverstackPieceUI>();

        // Enable the backdrop and overstack button
        GameObject.Find("UICanvas").GetComponent <RawImage>().enabled = true;
        GameObject.Find("UICanvas").transform.Find("DoneOverstackBtn").gameObject.SetActive(true);

        // Overstacking for AI
        if (attacker.owningPlayer.IsAI)
        {
            StartCoroutine(((AIPlayer)attacker.owningPlayer).AIOverstack());
        }
    }
Example #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="colour"></param>
 /// <returns>The number of pieces with the parameter colour in the tower</returns>
 public int GetColourCount(Player.PlayerColour colour)
 {
     return(colourCount[(int)colour]);
 }
Example #10
0
    /// <summary>
    /// Called by the overstack interface button when clicked.
    /// </summary>
    public void Finished()
    {
        // Get all the pieces by searching in the Overstack object
        GameObject ga = GameObject.Find("UICanvas").transform.Find("Overstack").gameObject;

        // List of all the considered pieces
        List <PieceData> pieces = new List <PieceData>(6);
        int numHooks            = 0;

        // Populate the list of considered pieces
        foreach (Transform child in ga.transform)
        {
            if (child.GetComponent <OverstackPieceUI>().Considered)
            {
                pieces.Add(child.GetComponent <OverstackPieceUI>().Piece);
            }

            if (child.GetComponent <OverstackPieceUI>().Piece.type == PieceData.Type.Hook)
            {
                numHooks++;
            }
        }

        // Must select a valid number of pieces
        if (pieces.Count < ga.transform.childCount - numHooks && pieces.Count != 6)
        {
            if (!GameObject.Find("Taoex").GetComponent <TurnHandler>().GetCurrentPlayer().IsAI)
            {
                GameObject.Find("OverstackError").GetComponent <OverstackError>().ShowError("Must select more pieces");
            }
            return;
        }

        // For validation purposes
        Player.PlayerColour attackerColour = ga.GetComponent <OverstackUI>().AttackerColour;
        bool ownColourSelected             = false;

        // Validate the pieces
        foreach (PieceData piece in pieces)
        {
            if (piece.colour == attackerColour)
            {
                ownColourSelected = true;
            }
        }

        // Didn't select any of own pieces
        if (!ownColourSelected)
        {
            if (!GameObject.Find("Taoex").GetComponent <TurnHandler>().GetCurrentPlayer().IsAI)
            {
                GameObject.Find("OverstackError").GetComponent <OverstackError>().ShowError("Must select at least one of your own pieces");
            }
            return;
        }

        // Send validated tower to the overstack user interface for completion
        ga.GetComponent <OverstackUI>().Finished(pieces);

        // Disable this button
        gameObject.SetActive(false);
    }