Esempio n. 1
0
        private void LoadGame()
        {
            Console.Clear();
            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseMySQL(
                "server=localhost;database=battleship;user=root;password=toor");
            var ctx = new AppDbContext(optionsBuilder.Options);
            int gameId;

            do
            {
                Console.WriteLine("Enter previous game id!");
                gameId = ConsoleView.IntegerInputHelper("Game ID", 0);
                try
                {
                    MyGame = ctx.Games.First(g => g.GameId == gameId);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
                if (MyGame.GameOver)
                {
                    Console.WriteLine($"Game has already ended, please load other game!");
                    ConsoleView.WaitForUser();
                    continue;
                }

                break;
            } while (true);
            ActionMenu.BombingMenu(MyGame, ctx);
        }
Esempio n. 2
0
 private void ChangeBoardSize()
 {
     Console.Clear();
     MyGame.Rows = ConsoleView.IntegerInputHelper("rows", MyGame.Rows);
     Console.Clear();
     MyGame.Cols = ConsoleView.IntegerInputHelper("cols", MyGame.Cols);
     Console.WriteLine($"Board set to: {MyGame.Rows}x{MyGame.Cols}");
     ConsoleView.WaitForUser();
 }
Esempio n. 3
0
        private void ChangeShipsCount()
        {
            int input;

            do
            {
                Console.Clear();
                input = ConsoleView.IntegerInputHelper("ships", MyGame.NumberOfShips);
                if (input > MyGame.Rows && input > MyGame.Cols)
                {
                    Console.WriteLine("There cannot be more ships than there are rows and columns on board!");
                    ConsoleView.WaitForUser();
                    continue;
                }
                break;
            } while (true);

            MyGame.NumberOfShips = input;
            Console.WriteLine($"No of ships set to: {MyGame.NumberOfShips}");
            ConsoleView.WaitForUser();
            MyGame.GameShips = new List <Ship>();

            for (int i = 1; i <= MyGame.NumberOfShips; i++)
            {
                Console.Clear();
                Console.Write($"Enter size of {i}. ship: ");
                do
                {
                    input = ConsoleView.IntegerInputHelper("ship size", MyGame.NumberOfShips);
                    if (input > MyGame.Cols && input > MyGame.Rows)
                    {
                        Console.WriteLine("Ship cannot be bigger than board!\nPlease try again:");
                        continue;
                    }
                    break;
                } while (true);
                MyGame.GameShips.Add(new Ship(input));
            }
            ShipPlacementMenu.RunMenu();
        }