using System.Security.Cryptography; using API.Models.DataClasses; using API.Models.Game; namespace API.Repository.GameRepo; public class GameRepository : IGameRepository { private List _games = []; public List GetAll() { return _games; } public Game? GetOne(string id) { return _games.FirstOrDefault(g => g.Id == id); } public Game? GetOne(SixDigitInt gameCode) { return _games.FirstOrDefault(g => g.GameCode == gameCode); } public Game Create(Coordinates gameFieldSize, Player player) { Game newGame = new(gameFieldSize, GenerateGameCode()); _games.Add(newGame); newGame.AddPlayer(player); return newGame; } public void Destroy(string id) { _games.RemoveAll(g => g.Id == id); } private SixDigitInt GenerateGameCode() { while (true) { int value = RandomNumberGenerator.GetInt32(100000, 1000000); bool exists = _games.Any(g => g.GameCode.Value == value); if (!exists) { return new SixDigitInt(value); } } } }