Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                var gameLogic = new BlackJackGameLogic();
                Console.WriteLine($"Play Mini Blackjack :)");
                gameLogic.ShuffleDeck();
                while (gameLogic.GameStillInPlay)
                {
                    Console.WriteLine("1. Hit");
                    Console.WriteLine("2. Stay");
                    Console.WriteLine("3. Exit Game");
                    var validSelection = int.TryParse(Console.ReadLine(), out int selection);
                    if (!validSelection)
                    {
                        Console.WriteLine("Invalid selection. Try again");
                    }
                    else
                    {
                        switch (selection)
                        {
                        case 1:
                            gameLogic.PlayerPlays();
                            break;

                        case 2:
                            gameLogic.DealerPlays();
                            break;

                        case 3:
                            Environment.Exit(0);
                            break;

                        default:
                            Console.WriteLine("Invalid selection. Try again");
                            break;
                        }
                    }
                }
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Play Again? y/n");
                if (Console.ReadLine().ToLower() == "y")
                {
                    Main(args);
                }
                else
                {
                    Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occured. Please try again");
                Main(args);
            }
        }
        public IActionResult NewGame()
        {
            Game game = new Game();

            BlackJackGameLogic.BeginGame(game);
            context.Games.Add(game);

            context.SaveChanges();

            var view = new GameView(game);

            return(CreatedAtRoute("GetGame", new { id = game.Id }, view));
        }
        public IActionResult Stand(long id)
        {
            var result = context.Games.Include(game => game.DealerHand.Cards)
                         .Include(game => game.UserHand.Cards)
                         .Include(game => game.GameDeck.Cards)
                         .Include(game => game.GameStatus).First(game => game.Id == id);

            if (result != null)
            {
                BlackJackGameLogic.Stand(result);
            }

            context.Update(result);
            context.SaveChanges();

            return(Ok(new GameView(result)));
        }