Пример #1
0
        public TurnContext Reroll(BoardContext board, IList <int> dicesToReroll)
        {
            var newDices = Dices.ToList(); //copy

            foreach (int diceToReroll in dicesToReroll)
            {
                if (newDices.Contains(diceToReroll))
                {
                    newDices.RemoveAt(newDices.LastIndexOf(diceToReroll));
                }
                else
                {
                    throw new System.FormatException();
                }
            }
            newDices.AddRange(Enumerable.Range(0, 4 - newDices.Count).Select(_ => RollDice));
            var newDicesArray = newDices.ToArray();

            return(new TurnContext(
                       currentPlayer: CurrentPlayer,
                       dices: newDicesArray,
                       remainReroll: dicesToReroll.Count - 1,
                       remainMove: dicesToReroll.Count,
                       isStuckInThisTurn: board.IsStuck(CurrentPlayer, newDicesArray)
                       ));
        }
Пример #2
0
 TurnState(
     DisboardGame ctx,
     BoardContext board,
     TurnContext turn
     ) : base(ctx)
 {
     Board = board;
     Turn  = turn;
 }
Пример #3
0
        static public TurnState New(DisboardGame ctx, IReadOnlyList <DisboardPlayer> players)
        {
            new XanthFactory().OnHelp(ctx.Channel);

            var board = BoardContext.New(players);
            var turn  = TurnContext.New(board);
            var next  = StartTurn(ctx: ctx, board: board, turn: turn);

            return(next);
        }
Пример #4
0
        static TurnState StartTurn(DisboardGame ctx, BoardContext board, TurnContext turn)
        {
            TurnState next = new TurnState(
                ctx: ctx,
                board: board,
                turn: turn
                );

            next.PrintTurn();
            return(next);
        }
Пример #5
0
        static TurnContext Next_(BoardContext board, Player nextPlayer)
        {
            var newDices = RollFourDices;

            return(new TurnContext(
                       currentPlayer: nextPlayer,
                       dices: newDices,
                       remainReroll: 3,
                       remainMove: 4,
                       isStuckInThisTurn: board.IsStuck(nextPlayer, newDices)
                       ));
        }
Пример #6
0
 public TurnContext Next(BoardContext board)
 => Next_(
     board: board,
     nextPlayer: CurrentPlayer.NextPlayer
     );
Пример #7
0
 public static TurnContext New(BoardContext board)
 => Next_(
     board: board,
     nextPlayer: board.Players.First()
     );