コード例 #1
0
        protected override void ExecuteCore(Guid playerId)
        {
            var player = PlayerService.GetPlayer(playerId);

            var balance = _ledgerService.GetBalance(playerId);

            if (balance <= 0)
            {
                ConsoleHelpers.WriteRedLine($"This player has {balance} credits and is ineligible to cash out.");
                return;
            }

            Console.WriteLine($"{player.Name} has {balance} credits. How many are you cashing out?");
            var creditsString = Console.ReadLine();
            int credits;

            if (string.IsNullOrEmpty(creditsString) || !int.TryParse(creditsString, out credits))
            {
                ConsoleHelpers.WriteRedLine("Invalid input, try again");
                return;
            }

            if (credits <= 0)
            {
                return;
            }
            if (credits > balance)
            {
                ConsoleHelpers.WriteRedLine($"{player.Name} only has {balance} credits. You can't cash out {credits}.");
                return;
            }

            _ledgerService.PurchaseCredits(playerId, -credits);
            ConsoleHelpers.WriteGreenLine($"Successfully cashed out {player.Name} with {credits} credits");
        }
コード例 #2
0
        public void RemoveElectionFromRound(Guid roundId, Guid playerId)
        {
            var entities = ValidateIds(roundId, playerId);

            _ledgerService.PurchaseCredits(playerId, 1);
            entities.Item1.EntrantPlayerIds.Remove(playerId);
            UpdateEntity(entities.Item1, a => a.Id == roundId);
        }
コード例 #3
0
        protected override void ExecuteCore(Guid playerId)
        {
            var player = PlayerService.GetPlayer(playerId);

            Console.WriteLine($"How many credits did {player.Name} purchase?");
            var creditsString = Console.ReadLine();
            int credits;

            if (string.IsNullOrEmpty(creditsString) || !int.TryParse(creditsString, out credits))
            {
                ConsoleHelpers.WriteRedLine("Invalid input, try again");
                return;
            }

            _ledgerService.PurchaseCredits(playerId, credits);
            ConsoleHelpers.WriteGreenLine($"Successfully credited {player.Name} with {credits} credits");
        }