public static BattleShipDbContext Create() { var config = new DbContextOptionsBuilder <BattleShipDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; var _battleShipDbContext = new BattleShipDbContext(config); _battleShipDbContext.Database.EnsureCreated(); var match = new Match() { MatchId = 1 }; _battleShipDbContext.Matches.Add(match); var board = new Board() { Match = match, X = 10, Y = 10 }; _battleShipDbContext.Boards.Add(board); var bs = new BattleShip() { Board = board }; _battleShipDbContext.BattleShips.Add(bs); _battleShipDbContext.BattleShipCoordinates.Add(new BattleShipCoordinate() { BattleShip = bs, X = 2, Y = 2 }); _battleShipDbContext.BattleShipCoordinates.Add(new BattleShipCoordinate() { BattleShip = bs, X = 2, Y = 3 }); _battleShipDbContext.SaveChanges(); return(_battleShipDbContext); }
public BoardRepo(BattleShipDbContext battleShipDbContext) { _battleShipDbContext = battleShipDbContext; }
public static void Destroy(BattleShipDbContext context) { context.Database.EnsureDeleted(); context.Dispose(); }
public LoadGame(BattleShipDbContext context) { _context = context; }
public OriginalSettingsGame(BattleShipDbContext context) { _context = context; GameBrain = new SeaBattle(_context); }
public ShipRepo(BattleShipDbContext battleShipDbContext) { _battleShipDbContext = battleShipDbContext; }
public Settings(BattleShipDbContext context) { _context = context; }
public SeaBattle(BattleShipDbContext context) { _context = context; }
public BoardRepository(BattleShipDbContext context, ILogger <BoardRepository> logger) { _context = context; _logger = logger; }
public MatchRepo(BattleShipDbContext battleShipDbContext) { _battleShipDbContext = battleShipDbContext; }
public Start(BattleShipDbContext context) { _context = context; }
public PlayerRepo(BattleShipDbContext battleShipDbContext) { _battleShipDbContext = battleShipDbContext; }
static string SeaBattle() { var dbOptions = new DbContextOptionsBuilder <BattleShipDbContext>().UseSqlServer( "Server = (localdb)\\mssqllocaldb; Database = BattleShipDbContext; Trusted_Connection = True; MultipleActiveResultSets = true" ).Options; using var dbCtx = new BattleShipDbContext(dbOptions); SeaBattle?game = new SeaBattle(dbCtx); Menu? menu = new Menu(MenuLevel.Level0); if (game != null) { menu.AddMenuItem(new MenuItem( $"Player Place a ship", userChoice: "p", () => { if (game.Game != null) { var(x, y) = GetMoveCordinates(game); game.CreateShip(GetshipType(), true); game.MoveShip(x, y, true, isRotate()); if (game.SelectedShip != null) { game.CreateFieldForBot(game.SelectedShip); game.Save(); SeabBattleConsoleUI.DrawBoard(game.Game.Cells.Where(g => g.IsPlayer).ToList(), game); } else { Console.WriteLine("Do not working("); } } else { Console.WriteLine("Please Create Game or load"); } return(""); }) ); menu.AddMenuItem(new MenuItem( $"Random", userChoice: "random", () => { if (game.Game != null) { game.DoRandom(true); if (game.SelectedShip != null) { game.CreateFieldForBot(game.SelectedShip); game.Save(); SeabBattleConsoleUI.DrawBoard(game.Game.Cells.Where(g => g.IsPlayer).ToList(), game); } } else { Console.WriteLine("Please Create Game or load"); } return(""); }) ); menu.AddMenuItem(new MenuItem( $"Play game", userChoice: "play", () => { if (game.Game != null) { return(PlayBattle(game)); } else { Console.WriteLine("Please Create Game or load"); return(""); } }) ); menu.AddMenuItem(new MenuItem( $"Create game with original settings", userChoice: "s", () => { game.CreateGame(); return(""); }) ); menu.AddMenuItem(new MenuItem( $"Load game", userChoice: "l", () => { game = LoadGameAction(game); return(""); }) ); menu.AddMenuItem(new MenuItem( $"Create game with custom settings", userChoice: "e", () => { Game gameToCreate = new Game(); gameToCreate.Game_Name = "CustomGame_" + game.GetGames().Count(); gameToCreate.Width = GetData("Width", V); gameToCreate.Heigth = GetData("Heigth", V); gameToCreate.BattleshipCount = GetData("Battleship", V); gameToCreate.CruiserCount = GetData("Cruiser", V); gameToCreate.SubmarineCount = GetData("Submarine", V); gameToCreate.PatrolCount = GetData("Patrol", V); gameToCreate.CarrierCount = GetData("Carrier", V); gameToCreate.CanGoToAnother = IsShipsCanGo(); game.SaveGame(gameToCreate); game.Game = gameToCreate; game.Game.Cells = game.GenerateField(); Ship shipTocreate; foreach (var shiptype in game.ShipsTypes) { for (int i = 0; i < 2; i++) { shipTocreate = game.CreateCustomShip(shiptype); shipTocreate.Length = GetData(shiptype, 2); shipTocreate.IsPlayer = i == V; game.SaveShip(shipTocreate); } } game.LoadGame(game.Game.Id); return(""); }) ); var userChoice = menu.RunMenu(); return(userChoice); } return(""); }
public TestBase() { _battleShipDbContext = BattleShipDbContextCreator.Create(); }