コード例 #1
0
    /// <summary>
    /// Attempts to carry out the desired move.
    /// </summary>
    /// <returns></returns>
    public bool Execute()
    {
        // check if valid move
        if (!CheckValid())
        {
            result = ResultType.Failed;
            return(false);
        }

        bool forcedWayMove;
        bool srcIsWay  = src.type == TileNode.Type.Way || src.type == TileNode.Type.WayCross;
        bool destIsWay = dest.type == TileNode.Type.Way || dest.type == TileNode.Type.WayCross;

        // determine inital type
        #region determine move type
        // same position
        if (src == dest)
        {
            type = MoveType.Move;

            // move to empty tile
        }
        else if (dest.tower == null)
        {
            type = MoveType.Move;
            src.tower.MoveTo(destMove);

            // attacking move on existing tower
        }
        else
        {
            PieceTower attacker = src.tower;
            PieceTower victim   = dest.tower;
            attacker.owningPlayer.capture += victim.pieces.Count;

            // check attack type
            if ((dest.type == TileNode.Type.Way || dest.type == TileNode.Type.WayCross) &&
                (src.type == TileNode.Type.Way || src.type == TileNode.Type.WayCross))
            {
                type = MoveType.WayAttack;
            }
            else
            {
                type = MoveType.Attack;
            }

            // Check if this move results in a win
            if (CheckWin())
            {
                result = ResultType.Win;
                for (int i = 0; i < victim.pieces.Count; i++)
                {
                    attacker.AddPiece(victim.pieces[i]);
                }
                victim.Die();
                attacker.MoveTo(destMove);
                attacker.owningPlayer.updateScore();
                victim.owningPlayer.updateScore();
                return(true);
            }

            // trigger overstack UI if too many pieces
            if (victim.pieces.Count + attacker.pieces.Count > 6 || (victim.GetHook() != null && attacker.GetHook() != null))
            {
                // Start the overstack UI and return immediately
                GameObject.Find("UICanvas").transform.Find("Overstack").GetComponent <OverstackUI>().Construct(attacker, victim);
                attacker.owningPlayer.HighestTower = 6;
            }
            else
            {
                // transfer all pieces to attacker
                for (int i = 0; i < victim.pieces.Count; i++)
                {
                    attacker.AddPiece(victim.pieces[i]);
                }
                victim.Die();
                attacker.MoveTo(destMove);
            }
            //update tower info
            attacker.owningPlayer.HighestTower = attacker.pieces.Count;

            // update scores
            attacker.owningPlayer.updateScore();
            victim.owningPlayer.updateScore();
        }
        #endregion

        #region checking waymove
        forcedWayMove = true;

        // if not moving to way
        if (!destIsWay)
        {
            forcedWayMove = false;
        }

        // endturn if moving along way (after way move)
        if ((srcIsWay && destIsWay) && (src.wayLine == dest.wayLine) && !destMove.hookInvolved)
        {
            forcedWayMove = false;
        }

        // check for proper forced way
        if (forcedWayMove)
        {
            Debug.Assert(forcedWayMove && destIsWay, "Way conditions did not match");
        }
        #endregion

        if (result == ResultType.Undetermined)
        {
            if (forcedWayMove)
            {
                if (dest.type == TileNode.Type.Way)
                {
                    result = ResultType.ForcedWay;
                }
                else
                {
                    result = ResultType.ForcedWayCross;
                }
            }
            else
            {
                result = ResultType.Normal;
            }
        }

        return(true);
    }
コード例 #2
0
    /// <summary>
    /// Called when there is a valid finish request from the overstack button.
    /// Handles the creation of the new tower, and removes all old pieces from the game.
    /// </summary>
    /// <param name="pieces">The considered pieces that have been validated.</param>
    public void Finished(List <PieceData> pieces)
    {
        // Reference to the attacking player
        Player    player        = GameObject.Find("Taoex").GetComponent <TurnHandler>().getPlayerByColour(attacker.owningColour);
        PieceData startingPiece = null;

        HashSet <TileNode> attackerMoves = attacker.GetMoves().Destinations;

        // Remove references to the selected pieces
        attacker.RemovePieces(pieces);
        victim.RemovePieces(pieces);

        // Pick the first selected attacker piece as the starting piece
        foreach (PieceData p in pieces)
        {
            if (p.colour == player.colour)
            {
                startingPiece = p;
                break;
            }
        }

        Debug.Assert(startingPiece != null, "Starting piece was null");

        // Create the new tower
        PieceTower newTower = new PieceTower(player, startingPiece, destination);

        newTower.owningPlayer.AddTower(newTower);

        // Add rest of the pieces
        foreach (PieceData p in pieces)
        {
            if (p != startingPiece)
            {
                newTower.AddPiece(p);
            }
        }

        // Clear the UI
        foreach (Transform ga in transform)
        {
            Destroy(ga.gameObject);
        }

        // Kill off the extra pieces
        foreach (PieceData p in attacker.pieces)
        {
            // Take extra pieces for scoring
            if (!pieces.Contains(p))
            {
                player.TakePiece(p);
            }

            // Liberate the piece if it's the attacker's colour
            if (p.colour == attackerColour)
            {
                if (p.getObj().GetComponent <PlacementPiece>() != null)
                {
                    p.getObj().GetComponent <PlacementPiece>().Liberate();
                }
                else
                {
                    Debug.Log("PlacementPiece script was null, probably testing with sandbox mode");
                    Destroy(p.getObj());
                }
            }
            else if (p.type == PieceData.Type.Hook)
            {
                // Return hook
                ReturnHook(p);
            }
            else
            {
                Destroy(p.getObj());
            }
        }

        foreach (PieceData p in victim.pieces)
        {
            // Take extra pieces for scoring
            if (!pieces.Contains(p))
            {
                player.TakePiece(p);
            }

            // Liberate the piece if it's the attacker's colour
            if (p.colour == attackerColour)
            {
                if (p.getObj().GetComponent <PlacementPiece>() != null)
                {
                    p.getObj().GetComponent <PlacementPiece>().Liberate();
                }
                else
                {
                    Debug.Log("PlacementPiece script was null, probably testing with sandbox mode");
                    Destroy(p.getObj());
                }
            }
            else if (p.type == PieceData.Type.Hook)
            {
                // Return hook
                ReturnHook(p);
            }
            else
            {
                Destroy(p.getObj());
            }
        }

        attacker.Die();
        victim.Die();

        // Update player status
        newTower.GetNode().tower = newTower;
        newTower.updatePosition();
        attacker.owningPlayer.updateScore();
        victim.owningPlayer.updateScore();

        // Reset variables
        hookConsidered = false;
        consideredPieces.Clear();

        this.newTower = newTower;

        // Disable the dim effect
        GameObject.Find("UICanvas").GetComponent <RawImage>().enabled = false;

        done = true;
    }