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); }
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); }
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); }