Beispiel #1
0
 private void ProvideExtraTurnOnReachHome(Pawn.PawnID pawnID)
 {
     if (CurrentPlayer.GetTilesTraveled(pawnID) == Constants.Tiles.TotalStepsToReachHome)
     {
         reachedHomeExtraTurns++;
     }
 }
Beispiel #2
0
    private void OnMoveEnded(Pawn.PawnID pawnID)
    {
        switch (rulesManager.CheckRulesOnMoveEnd(pawnID))
        {
        case RulesManager.PawnMoveStates.EndTurn:
            EndTurnAfter(Constants.DiceRoll.WaitForDiceDisplayDuration);
            break;

        case RulesManager.PawnMoveStates.RollDice:
            CurrentPlayer.GainedExtraDiceThrow();
            break;

        case RulesManager.PawnMoveStates.KillPawn:
            MakePawnKillAnother(pawnID);
            break;

        case RulesManager.PawnMoveStates.PlayerWon:
            AddCurrentPlayerToRank();
            if (ReachedGameEnd())
            {
                AddNextPlayerToRank();
                EndGame();
            }
            else
            {
                EndTurnAfter(Constants.DiceRoll.WaitForDiceDisplayDuration);
            }
            break;
        }
    }
Beispiel #3
0
    private void MakePawnKillAnother(Pawn.PawnID pawnID)
    {
        var pawnToKill = rulesManager.GetPawnKilledBy(pawnID);
        var player     = pawnToKill.Key;
        var pawn       = pawnToKill.Value;

        player.ReturnPawnToStart(pawn, () => { OnMoveEnded(pawnID); });
    }
Beispiel #4
0
    public void ReturnPawnToStart(PawnID pawnID)
    {
        Pawn pawn = GetPawnForID(pawnID);

        if (pawn != null)
        {
            pawn.ReturnToStart();
        }
    }
Beispiel #5
0
    public void MovePawn(Pawn.PawnID pawnID, int tiles, Action <Pawn.PawnID> onMoveCompleted)
    {
        var  pawnData            = GetPawnData(pawnID);
        int  tilesTraveled       = boardPlayer.GetTilesTraveled(pawnID);
        int  travelToTile        = tilesTraveled + tiles;
        bool isAlreadyInInerTile = TileManager.Instance.IsInnerTile(tilesTraveled);
        bool isTravelToInnerTile = TileManager.Instance.IsInnerTile(travelToTile);

        if (travelToTile == Constants.Tiles.TotalStepsToReachHome)
        {
            // Move pawn to home
            MovePawnToHome(pawnID, tiles, onMoveCompleted);
            return;
        }


        // Ungroup Pawns ----------------
        if (isAlreadyInInerTile)
        {
            UngroupPawnsInInnerTile(tilesTraveled);
        }
        else
        {
            UngroupPawnsInTile(tilesTraveled);
        }
        var pawnsInTile = GetAllPawnsTraveled(tilesTraveled);

        if (pawnsInTile.Count > 2)
        {
            boardPlayerUI.ReturnPawnToNormal(GetPawnData(pawnID).pawnUI);
        }
        // ------------------------------


        if (isTravelToInnerTile)
        { // Travel to inner tile
            int tileNo = TileManager.Instance.GetInnerPathTileNo(tilesTraveled, tiles);
            Debugger.Log("Move Pawn To Inner tile : " + tileNo);
            boardPlayerUI.MovePawnToInnerTile(pawnData.pawnUI, tileNo, () =>
            {
                boardPlayer.MovePawn(pawnID, tiles);
                GroupPawnsInInnerTile(travelToTile);
                onMoveCompleted.Invoke(pawnID);
            });
        }
        else
        { // Trave in outer path
            int tileNo = TileManager.Instance.GetOuterPathTileNo(playerBoardType, tilesTraveled, tiles);
            Debugger.Log("Move Pawn To : " + tileNo);
            boardPlayerUI.MovePawnToTile(pawnData.pawnUI, tileNo, () =>
            {
                boardPlayer.MovePawn(pawnID, tiles);
                GroupPawnsInTile(tileNo, travelToTile);
                onMoveCompleted.Invoke(pawnID);
            });
        }
    }
Beispiel #6
0
    public void MovePawn(PawnID pawnID, int tiles)
    {
        Pawn pawn = GetPawnForID(pawnID);

        if (pawn != null)
        {
            pawn.MoveTo(tiles);
        }
    }
Beispiel #7
0
    public int GetTilesTraveled(PawnID pawnID)
    {
        Pawn pawn = GetPawnForID(pawnID);

        if (pawn == null)
        {
            return(-1);
        }
        return(pawn.TilesTravled);
    }
Beispiel #8
0
    private PawnData GetPawnData(Pawn.PawnID pawnID)
    {
        var pawnData = GetPawnDataInStart(pawnID);

        if (pawnData != null)
        {
            return(pawnData);
        }
        pawnData = GetPawnDataInOpen(pawnID);
        return(pawnData);
    }
Beispiel #9
0
    public new void GetPawnOutOfStart(Pawn.PawnID pawnID, Action <Pawn.PawnID> onCompleted)
    {
        var pawnData = GetPawnData(pawnID);

        boardPlayerUI.GetPawnOutOfStart(pawnData.pawnUI);
        boardPlayer.GetPawnOutOfStart(pawnID);
        pawnsInStart.Remove(pawnData);
        pawnsInOpen.Add(pawnData);
        onCompleted.Invoke(pawnID);
        GroupPawnsInTile(TileManager.Instance.GetStartingTileNo(playerBoardType), Constants.Tiles.FirstTileNoOut);
    }
Beispiel #10
0
 private Pawn GetPawnForID(PawnID pawnID)
 {
     foreach (var pawn in pawns)
     {
         if (pawn.pawnID.equals(pawnID))
         {
             return(pawn);
         }
     }
     return(null);
 }
Beispiel #11
0
 private PawnData GetPawnDataInOpen(Pawn.PawnID pawnID)
 {
     foreach (var pawnData in pawnsInOpen)
     {
         if (pawnData.pawn.equals(pawnID))
         {
             return(pawnData);
         }
     }
     return(null);
 }
Beispiel #12
0
    public void ReturnPawnToStart(Pawn.PawnID pawnID, Action onCompleted)
    {
        var pawnData = GetPawnData(pawnID);

        boardPlayerUI.ReturnPawnToStart(pawnData.pawnUI, () =>
        {
            pawnsInOpen.Remove(pawnData);
            pawnsInStart.Add(pawnData);
            ReturnPawnToStart(pawnID);
            onCompleted.Invoke();
        });
    }
Beispiel #13
0
    public void MovePawnToHome(Pawn.PawnID pawnID, int tiles, Action <Pawn.PawnID> onCompleted)
    {
        var pawnData = GetPawnData(pawnID);

        boardPlayerUI.MovePawnToHome(pawnData.pawnUI, () =>
        {
            boardPlayer.MovePawn(pawnID, tiles);
            pawnsInOpen.Remove(pawnData);
            pawnUIsInHome.Add(pawnData.pawnUI);
            if (pawnUIsInHome.Count > 1)
            {
                boardPlayerUI.GroupPawnsInHome(pawnUIsInHome);
            }
            onCompleted.Invoke(pawnID);
        });
    }
Beispiel #14
0
    private PawnMoveStates InternalCheckRulesOnMoveEnd(Pawn.PawnID pawnID)
    {
        // Rules:
        //  Rules for RollDice:
        //      On Rolling a 6
        //      On sending any opponents pawn to start
        //      On Reaching a pawn to home
        //  Rules for KillPawn:
        //      When there is a pawn landed on a tile with other player's pawn
        //      If a piece lands upon a piece of the same colour, this forms a block. This block cannot be killed by any opposing piece.
        //  Rules for EndTurn:
        //      When there is no move to make

        if (IsCurrentPlayerWon())
        {
            return(PawnMoveStates.PlayerWon);
        }

        ProvideExtraTurnOnReachHome(pawnID);
        if (IsPawnKillsAny(pawnID))
        {
            ProvideExtraTurnOnKillOther(); return(PawnMoveStates.KillPawn);
        }

        if (LastRolledDice() == Constants.DiceRoll.RollForExtraTurn)
        {
            return(PawnMoveStates.RollDice);
        }

        if (killPawnExtraTurns > 0)
        {
            killPawnExtraTurns--; return(PawnMoveStates.RollDice);
        }
        if (reachedHomeExtraTurns > 0)
        {
            reachedHomeExtraTurns--; return(PawnMoveStates.RollDice);
        }

        return(PawnMoveStates.EndTurn);
    }
Beispiel #15
0
    public KeyValuePair <Player, Pawn.PawnID> GetPawnKilledBy(Pawn.PawnID pawnID)
    {
        int currentPawnTilesTraveled = CurrentPlayer.GetTilesTraveled(pawnID);
        var nullValue = new KeyValuePair <Player, Pawn.PawnID>(null, Pawn.PawnID.nullID);

        if (CurrentPlayer.IsPawnInSafeTile(pawnID))
        {
            return(nullValue);                                        // Pawn landed on a safe tile, cannot kill pawn
        }
        if (CurrentPlayer.GetAllPawnsTraveled(currentPawnTilesTraveled).Count > 1)
        {
            return(nullValue); // More than one pawn of the player in the spot forms a group
        }
        var pawnKilled = nullValue;
        int tileNo     = TileManager.Instance.GetOuterPathTileNo(CurrentPlayer.GetPlayerBoardType(), currentPawnTilesTraveled);

        foreach (var player in players)
        {
            if (player != CurrentPlayer)
            {
                int pawnTraveled = TileManager.Instance.ConvertTileNoToTilesTraveled(player.GetPlayerBoardType(), tileNo);
                var pawnsInTile  = player.GetAllPawnsTraveled(pawnTraveled);
                if (pawnsInTile.Count == 0)
                {
                    continue;                         // No pawns found to kill
                }
                if (pawnsInTile.Count > 1)
                {
                    return(nullValue);                       // More than one pawn in the spot cannot kill
                }
                if (pawnsInTile.Count == 1 && !pawnKilled.Value.IsNull())
                {
                    return(nullValue);                                                      // Different player pawns in a group cannot kill
                }
                pawnKilled = new KeyValuePair <Player, Pawn.PawnID>(player, pawnsInTile[0]);
            }
        }
        return(pawnKilled);
    }
Beispiel #16
0
 private void MoveSelectedPawn(Pawn.PawnID pawnID, int diceRoll) => CurrentPlayer.MovePawn(pawnID, diceRoll, OnMoveEnded);
Beispiel #17
0
 public void GetPawnOutOfStart(PawnID pawnID) => GetPawnForID(pawnID).GetOutOfStart();
Beispiel #18
0
 public bool IsPawnSafeTile(PawnID pawnID) => GetPawnForID(pawnID).IsSafe;
Beispiel #19
0
 public void ReturnPawnToStart(Pawn.PawnID pawnID, Action onCompleted)
 {
     throw new NotImplementedException();
 }
Beispiel #20
0
 public void MovePawn(Pawn.PawnID pawnID, int tiles, Action <Pawn.PawnID> onMoveCompleted)
 {
     throw new NotImplementedException();
 }
Beispiel #21
0
 public void ReturnPawnToStart(Pawn.PawnID pawnID)
 {
     boardPlayer.ReturnPawnToStart(pawnID);
 }
Beispiel #22
0
 public int GetTilesTraveled(Pawn.PawnID pawnID)
 {
     return(boardPlayer.GetTilesTraveled(pawnID));
 }
Beispiel #23
0
 // Board Player Start
 public bool IsPawnInSafeTile(Pawn.PawnID pawnID) => boardPlayer.IsPawnSafeTile(pawnID);
Beispiel #24
0
 public void GetPawnOutOfStart(Pawn.PawnID pawnID, Action <Pawn.PawnID> onCompleted)
 {
 }
Beispiel #25
0
 private bool IsPawnKillsAny(Pawn.PawnID pawnID) => GetPawnKilledBy(pawnID).Value.IsNull() == false;
Beispiel #26
0
 public PawnMoveStates CheckRulesOnMoveEnd(Pawn.PawnID pawnID) => InternalCheckRulesOnMoveEnd(pawnID);
Beispiel #27
0
 private void GetSelectedPawnOutOfStart(Pawn.PawnID pawnID) => CurrentPlayer.GetPawnOutOfStart(pawnID, OnMoveEnded);
Beispiel #28
0
 public PawnData(Pawn.PawnID pawn, PawnUI.PawnUIID pawnUI)
 {
     this.pawn   = pawn;
     this.pawnUI = pawnUI;
 }