Exemple #1
0
 private void ChangeShipsTouch()
 {
     Console.Clear();
     MyGame.ShipsCanTouch = !MyGame.ShipsCanTouch;
     Console.WriteLine($"Ships can touch set to: {MyGame.ShipsCanTouch}");
     ConsoleView.WaitForUser();
 }
Exemple #2
0
        private void PlaceShipsOnBoard()
        {
            Console.WriteLine($"{MyGame.PlayerOne}, place your ships!");
            ConsoleView.WaitForUser();
            ConsoleView.PlacePlayerShipsOnBoard(MyGame);
            if (MyGame.Ai)
            {
                ShipPlacement.RandomPlacement(MyGame, true);
            }
            else
            {
                Console.Clear();
                Console.WriteLine($"{MyGame.PlayerTwo}, place your ships!");
                ConsoleView.WaitForUser();
                MyGame.PlayerOneTurn = false;
                ConsoleView.PlacePlayerShipsOnBoard(MyGame);
                MyGame.PlayerOneTurn = true;
            }
            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseMySQL(
                "server=localhost;database=battleship;user=root;password=toor");
            Ctx = new AppDbContext(optionsBuilder.Options);
            Ctx.Add(MyGame);
            ActionMenu.BombingMenu(MyGame, Ctx);
        }
Exemple #3
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);
        }
Exemple #4
0
 private void CurrentSettings()
 {
     Console.WriteLine($"Player 1: {MyGame.PlayerOne}\n" +
                       $"Player 2: {MyGame.PlayerTwo}\n" +
                       $"Board size: {MyGame.Rows}x{MyGame.Cols}\n" +
                       $"Ships can touch: {MyGame.ShipsCanTouch}");
     ConsoleView.WaitForUser();
 }
Exemple #5
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();
 }
Exemple #6
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();
        }