Exemple #1
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 #2
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 #3
0
        private void PlaceShipsRandomly()
        {
            InitBoard.InitializeBoard(MyGame);
            ShipPlacement.RandomPlacement(MyGame, false);
            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);
        }