Ejemplo n.º 1
0
        public Result TryMakeTurn(int start, int end)
        {
            var gameTurn = GameTurnUtils.CreateTurnByTwoCells(_curField, Side, start, end);

            if (gameTurn == null || (gameTurn.IsSimple && _requiredJumps.Any()))
            {
                return(Result.Fail);
            }

            _turns.Add(gameTurn);

            GameFieldUtils.TryCreateField(_curField, gameTurn, out GameField newField);

            // Not the last jump
            if (!gameTurn.IsSimple && !gameTurn.IsLevelUp &&
                GameTurnUtils.FindTurnsForCell(newField, gameTurn.Steps.Last(), TurnType.Jump).Any())
            {
                _statusReporter.Status = $"{Side}: {Resources.WpfPlayer_JumpTurn_Continue}";

                DoJumpsContinue = true;

                _curField = newField;

                return(Result.Continue);
            }

            _sender?.Send(GameTurnUtils.CreateCompositeJump(_turns));

            return(Result.Ok);
        }
Ejemplo n.º 2
0
        public static IEnumerable <GameTurn> GetTurnsBySide(this CachedField gameField, PlayerSide side)
        {
            var simpleMoves   = new List <GameTurn>();
            var requiredJumps = new List <GameTurn>();

            void Processor(int cellIdx)
            {
                var cellTurns = GameTurnUtils.FindTurnsForCell(gameField, cellIdx);

                foreach (var turn in cellTurns)
                {
                    if (turn.IsSimple)
                    {
                        simpleMoves.Add(turn);
                    }
                    else
                    {
                        requiredJumps.Add(turn);
                    }
                }
            }

            gameField.ProcessCellsBySide(side, Processor);

            return(requiredJumps.Any() ? GetCompositeJumps(gameField.Origin, requiredJumps) : simpleMoves);
        }
Ejemplo n.º 3
0
        private static IEnumerable <GameTurn> GetCompositeJumps(GameField oldField, IEnumerable <GameTurn> jumps)
        {
            foreach (var jump in jumps)
            {
                GameFieldUtils.TryCreateField(oldField, jump, out GameField newField);
                var subJumps = GetCompositeJumps(newField, GameTurnUtils.FindTurnsForCell(newField, jump.Steps.Last(), TurnType.Jump));

                if (subJumps.Any() && !jump.IsLevelUp)
                {
                    foreach (var subJump in subJumps)
                    {
                        yield return(GameTurnUtils.CreateCompositeJump(new[] { jump, subJump }));
                    }
                }
                else
                {
                    yield return(jump);
                }
            }
        }