Example #1
0
        public void RunGame(Game game)
        {
            bool gameFinished = false;
            bool tokenChosed  = false;

            while (!gameFinished)
            {
                Console.Clear();
                GameMessages.PrintAllPlayerAndTokensValue(game.Players);
                GameMessages.PrintPlayerTurn(game.Players[game.PlayerTurn]);
                string exitOrContinue = Console.ReadLine().ToLower();
                if (exitOrContinue != "x")
                {
                    var die = engine.ThrowDie();

                    GameMessages.PrintDieResult(die);

                    var movableTokens = engine.MovableTokens(game.Players[game.PlayerTurn], die);

                    if (movableTokens.Count > 0)
                    {
                        GameMessages.PrintMovableTokens(movableTokens);
                        tokenChosed = false;
                        while (!tokenChosed)
                        {
                            try
                            {
                                int movableTokensIndex = int.Parse(Console.ReadLine());
                                var tokenToMove        = engine.ChooseToken(game.Players[game.PlayerTurn].Tokens, movableTokens[movableTokensIndex]);
                                engine.RunPlayerTurn(tokenToMove, die, game, game.Players[game.PlayerTurn]);
                                if (engine.tokenToKnockOut != null)
                                {
                                    Console.WriteLine($"{tokenToMove.TokenColor} {tokenToMove.TokenNumber} knocked out {engine.tokenToKnockOut.TokenColor} {engine.tokenToKnockOut.TokenNumber}");
                                    Console.WriteLine("Press any key to continue");
                                    Console.ReadKey();
                                }
                                tokenChosed = true;
                            }
                            catch
                            {
                                Console.WriteLine("Invalid token, try again");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("You need to throw 1 or 6 to leave the nest");
                        Console.ReadKey();
                        engine.RunGameUpdate(game);
                    }
                    engine.SaveGameToDataBase(game);
                    gameFinished = game.Finished;
                }
                else
                {
                    engine.SaveGameToDataBase(game);
                    MainMenu.Menu();
                }
            }
            Console.Clear();
            GameMessages.PrintAllPlayerAndTokensValue(game.Players);
            GameMessages.PrintWinner(game.GetVictoriousPlayer());
            Console.WriteLine("Press any key to retun to main menu");
            Console.ReadKey();
        }
Example #2
0
        public void ShowPreviousGamesFromDataBase()
        {
            var loadGames = engine.LoadAllFinishedGamesFromDataBase();

            GameMessages.PrintPreviousGameResult(loadGames);
        }