public void UpdateBattleShipsSave(BattleShipsSave save)
        {
            string player1Json = JsonSerializer.Serialize(Player1);
            string player2Json = JsonSerializer.Serialize(Player2);

            save.Player1JsonString = player1Json;
            save.Player2JsonString = player2Json;

            save.Player1Turn = Player1Turn;
        }
        public BattleShips(BattleShipsSave battleShipsSave)
        {
            Player1 = JsonSerializer.Deserialize <Player>(battleShipsSave.Player1JsonString);
            Player2 = JsonSerializer.Deserialize <Player>(battleShipsSave.Player2JsonString);

            Width  = battleShipsSave.Width;
            Height = battleShipsSave.Height;

            GameType    = battleShipsSave.GameType;
            Player1Turn = battleShipsSave.Player1Turn;
        }
Exemple #3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BattleShipsSave = await _context.BattleShipsSaves.FirstOrDefaultAsync(m => m.Id == id);

            if (BattleShipsSave == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BattleShipsSave = await _context.BattleShipsSaves.FindAsync(id);

            if (BattleShipsSave != null)
            {
                _context.BattleShipsSaves.Remove(BattleShipsSave);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemple #5
0
 public string CreateDisplayName(BattleShipsSave save)
 {
     return($"{save.SaveName} - {save.Height}x{save.Width} - {(save.Player1Turn ? "Player 1" : "Player 2")} " +
            $"- {(save.GameType == GameType.HumanVsAi ? "Vs Computer" : "Vs Human")}");
 }