예제 #1
0
        public Maybe <GameState> CompleteWord(CombatMode mode)
        {
            if (!CharBoard.HasSelectedCharCells)
            {
                return(Maybe.None <GameState>());
            }

            var word = new Word(StartsWith.Value + CharBoard.EndsWith);

            var seed = word.Value.Aggregate(0, (c, a) => (int)c + a);

            var attemptResult = CharBoard.HasWord(word)
                ? AttemptResult.Success(word.Value)
                : AttemptResult.Failure(word.Value);

            var encounter = Encounter;
            var player    = Player;

            var items = LootEscrow;
            var xp    = XPEscrow;

            if (attemptResult is AttemptResult.SuccessResult)
            {
                if (mode == CombatMode.Attack)
                {
                    encounter = Encounter.TakeMitigatedDamage(Player.AttackDamage(Random, word.Value.Length));
                }
                else if (mode == CombatMode.Defense)
                {
                    var enemyAttack = encounter.ActiveEnemy.Select(e => e.AttackDamage(Random, -word.Value.Length)).ValueOr(() => 0);
                    player = Player.TakeMitigatedDamage(enemyAttack);
                }

                items = items.Concat(CharBoard.CollectItems());
                xp   += word.Value.Length;
            }
            else
            {
                if (mode == CombatMode.Defense)
                {
                    var enemyAttack = encounter.ActiveEnemy.Select(e => e.AttackDamage(Random, word.Value.Length)).ValueOr(() => 0);
                    player = Player.TakeMitigatedDamage(enemyAttack);
                }
            }

            var nextStartsWith = Words.GetNextStartsWith(Random, attemptResult is AttemptResult.SuccessResult ? word.ToMaybe() : Maybe.None <Word>());

            return(new GameState(
                       Random,
                       Words,
                       nextStartsWith,
                       CharBoard.New(Random, Words, nextStartsWith),
                       AttemptResults.Prepend(attemptResult),
                       player,
                       encounter,
                       items,
                       xp
                       ).ToMaybe());
        }
예제 #2
0
        public static GameState New(Words words, string playerName)
        {
            var random     = new Random();
            var startsWith = new StartsWith('n', 'o');
            var charBoard  = CharBoard.New(random, words, startsWith, "nothing");

            return(new GameState(
                       random,
                       words,
                       startsWith,
                       charBoard,
                       Enumerable.Empty <AttemptResult>(),
                       Player.New(playerName, random),
                       Encounters.EnterDungeon(random),
                       Enumerable.Empty <Item>(),
                       0
                       ));
        }