private static void LoadData() { using (var context = new GameDataContext()) { var heroes = context.Heroes.ToList(); } }
public List <Game> all() { using var gameDataContext = new GameDataContext(); var gameDatas = gameDataContext.GameDatas; using var matchContext = new MatchContext(); var matchesByGameId = matchContext .Matches .AsEnumerable() .GroupBy(m => m.GameId) .ToDictionary(g => g.Key, g => g.ToList()); using var scoreContext = new ScoreContext(); var scores = scoreContext.Scores.ToDictionary(g => g.Id, g => g); var games = new List <Game>(); foreach (var gameData in gameDatas) { var id = gameData.Id; var score = scores[id]; var matches = matchesByGameId[id]; DateTime date = DateTime.ParseExact(gameData.Date, "u", System.Globalization.CultureInfo.InvariantCulture); games.Add(createGame(matches, score?.Result, id, date)); } return(games); }
public ChallengeService( ILogger <ChallengeService> logger, IOptions <Options> options, IGameRepository repository, GameDataContext dataContext ) : base(logger, options, repository) { _dataContext = dataContext; }
public ActionResult <Game> Update(Game game) { using var gameDataContext = new GameDataContext(); var gameData = gameDataContext.GameDatas.Where(g => g.Id == game.Id).SingleOrDefault(); gameData.Date = game.Date; gameDataContext.SaveChanges(); using var matchContext = new MatchContext(); var matches = matchContext.Matches.Where(m => m.GameId == game.Id); matchContext.Matches.RemoveRange(matches); foreach (var player in game.Team1) { matchContext.Add(new Match { GameId = game.Id, Player = player, Team = 1, }); } foreach (var player in game.Team2) { matchContext.Add(new Match { GameId = game.Id, Player = player, Team = 2, }); } matchContext.SaveChanges(); using var scoreContext = new ScoreContext(); var score = scoreContext.Scores.Where(s => s.GameId == game.Id).Single(); if (game.Score == '1') { score.Result = 1f; } else if (game.Score == '2') { score.Result = 0f; } else if (game.Score == 'D') { score.Result = 0.5f; } else if (game.Score == 'C') { score.Result = -1f; } else { score.Result = null; } scoreContext.SaveChanges(); return(CreatedAtAction(nameof(GetById), new { id = game.Id }, game)); }
public void FinishGame(int gameId, int myScore, int opponentsScore, Result myResult, Result opponentsResult) { var game = CurrentGames[gameId]; var other = game.GetOther(ClientCallback); var me = game.GetMe(ClientCallback); other.Client.FinishGame(); game.Stop(); CurrentGames.Remove(gameId); me.Playing = false; other.Playing = false; using (var db = new GameDataContext()) { GamePlayer dbMe = db.GamePlayers.Find(me.NickName); GamePlayer dbOther = db.GamePlayers.Find(other.NickName); var dbGame = new Game() { CardCount = game.CardTypes.Count, GameDuration = game.GameDuration }; db.Games.Add(dbGame); db.SaveChanges(); var dbMyGameRound = new GameRound() { GamePlayer = dbMe, Game = dbGame, GameId = dbGame.Id, MovesCount = me.MovesCount, PlayerNickName = me.NickName, Result = myResult }; var dbOpponentRound = new GameRound() { GamePlayer = dbOther, Game = dbGame, GameId = dbGame.Id, MovesCount = other.MovesCount, PlayerNickName = other.NickName, Result = opponentsResult }; db.GameRounds.Add(dbMyGameRound); //add rounds db.GameRounds.Add(dbOpponentRound); dbGame.PlayedRounds.Add(dbMyGameRound); //add games reference dbGame.PlayedRounds.Add(dbOpponentRound); dbMe?.PlayerRounds.Add(dbMyGameRound); //add players reference dbOther?.PlayerRounds.Add(dbOpponentRound); db.SaveChanges(); //save } }
private static void InitiateMonsters() { using (var context = new GameDataContext()) { context.Monsters.ToList().ForEach(monster => { _monsters.Add(monster); }); } }
private static void InitializeSkills() { using (var context = new GameDataContext()) { context.Skill.ToList().ForEach(skill => { _skills.Add(skill); }); } }
private static void InitializeSaveFiles() { using (var context = new GameDataContext()) { context.SaveFile.ToList().ForEach(saveFile => { _saveFiles.Add(saveFile); }); } }
public ChallengeController( IChallengeService challengeService, IOptions <Options> options, GameDataContext dataContext ) { _challengeService = challengeService; Options = options.Value; GameDataContext = dataContext; }
private List <string> GetAllPlayers(bool ascending) { using (var db = new GameDataContext()) { if (ascending) { return(db.GamePlayers.OrderBy(player => player.NickName).Select(player => player.NickName).ToList()); } return(db.GamePlayers.OrderByDescending(player => player.NickName).Select(player => player.NickName).ToList()); } }
public async Task <IActionResult> Reload() { GameDataContext.Reload(); foreach (string client in Clients) { var http = HttpClientFactory.CreateClient(client.Untagged()); await http.PostAsync("reload", null); } return(Ok()); }
private static bool NoSaveFiles() { using (var context = new GameDataContext()) { if (context.SaveFile.Any()) { return(false); } } return(true); }
private static void InitiateHeroes() { using (var context = new GameDataContext()) { context.Heroes.ToList().ForEach(hero => { _heroes.Add(hero); }); _selectedHero = _heroes.FirstOrDefault(); } }
public static IGameRepository SetUpRepository(string connectionString) { DbContextOptions <GameDataContext> options = new DbContextOptionsBuilder <GameDataContext>() .UseSqlServer(connectionString) .Options; var dataContext = new GameDataContext(options); EnsureDatabase(dataContext); IGameRepository repository = new EfGameRepository(dataContext); EnsureInitialData(repository); return(repository); }
public GameController( IGameRepository gameRepository, StatsService statsService, IOptions <Options> options, IOptions <EngineClients> clients, GameDataContext dataContext, IHttpClientFactory httpClientFactory ) { Repository = gameRepository; Stats = statsService; Options = options.Value; Clients = clients.Value; GameDataContext = dataContext; HttpClientFactory = httpClientFactory; }
public bool LoginPlayer(string playerNick) { if (LoggedPlayers.Contains(playerNick)) { return(false); } using (var db = new GameDataContext()) { GamePlayer p = db.GamePlayers.Find(playerNick); if (p != null) { LoggedPlayers.Add(playerNick); } return(p != null); } }
public ActionResult <Game> GetById(int id) { using var gameDataContext = new GameDataContext(); var gameData = gameDataContext.GameDatas.Where(x => x.Id == id).FirstOrDefault(); if (gameData == null) { return(NotFound()); } using var matchContext = new MatchContext(); var matches = matchContext.Matches.Where(x => x.GameId == id); using var scoreContext = new ScoreContext(); var score = scoreContext.Scores.Where(x => x.GameId == id).FirstOrDefault(); DateTime date = DateTime.ParseExact(gameData.Date, "u", System.Globalization.CultureInfo.InvariantCulture); return(createGame(matches, score?.Result, id, date)); }
public bool RegisterPlayer(string playerNick) { using (var db = new GameDataContext()) { if (db.GamePlayers.Count(player => player.NickName == playerNick) == 0) { var pl = new GamePlayer() { NickName = playerNick }; db.GamePlayers.Add(pl); db.SaveChanges(); return(true); } else { return(false); } } }
private List <GameRound> GetAllGames(PlayerNameModel model) { using (var db = new GameDataContext()) { //nechutne var query = db.GameRounds.Include(round => round.Game).Include(round => round.GamePlayer); if ((model.Name == null || model.Name.IsEmpty()) && model.GameID == 0) { return(query.Take(60).OrderBy(round => round.Game.Id).ToList()); } if (model.Name != null && !model.Name.IsEmpty() && model.GameID != 0) { return(query.Where(round => round.Game.Id == model.GameID).Where(round => round.GamePlayer.NickName.ToLower().Contains(model.Name.ToLower())).ToList()); } if (model.Name != null && !model.Name.IsEmpty()) { return(query.Where(round => round.GamePlayer.NickName.ToLower().Contains(model.Name.ToLower())).OrderBy(round => round.Game.Id).ToList()); } return(query.Where(round => round.Game.Id == model.GameID).ToList()); } }
private static void EnsureDatabase(GameDataContext dataContext) { }
private static void SeedDb() { using (var context = new GameDataContext()) { #region SaveFiles var saveFile = new SaveFile { Id = new Guid(), LastSavedOn = DateTime.Now, }; context.Add(saveFile); #endregion SaveFiles #region Heroes var basicAttackSkill = new Skill { Id = new Guid(), Name = "Basic Attack", Cost = 0, Damage = 2, Accuracy = 1, SaveFile = saveFile, }; context.Add(basicAttackSkill); var fireballSkill = new Skill { Id = new Guid(), Name = "Fireball", Cost = 2, Damage = 4, Accuracy = 1, SaveFile = saveFile, }; context.Add(fireballSkill); var waitSkill = new Skill { Id = new Guid(), Name = "Wait", Cost = 0, Damage = 0, Accuracy = 1, SaveFile = saveFile, }; context.Add(waitSkill); var endgameSkill = new Skill { Id = new Guid(), Name = "Endgame", Cost = 0, Damage = 200, Accuracy = 1, SaveFile = saveFile, }; context.Add(endgameSkill); var hero = new Heroes { Id = new Guid(), SaveFile = saveFile, Name = "Roland", Health = 10, Mana = 5, Skill1Navigation = basicAttackSkill, Skill2Navigation = fireballSkill, Skill3Navigation = waitSkill, Skill4Navigation = endgameSkill }; context.Add(hero); #endregion Heroes #region Monsters var stab = new Skill { Name = "Stab", Cost = 0, Damage = 6, Accuracy = .9, SaveFile = saveFile, }; context.Add(stab); var goblin = new Monsters { Id = new Guid(), Name = "Goblin", Health = 3, Skill1Navigation = stab, }; context.Add(goblin); var rockSlam = new Skill { Name = "Rock Slam", Cost = 0, Damage = 2, Accuracy = .7, SaveFile = saveFile, }; context.Add(rockSlam); var golem = new Monsters { Id = new Guid(), Name = "Golem", Health = 9, Skill1Navigation = rockSlam, }; context.Add(golem); var slash = new Skill { Name = "Slash", Cost = 0, Damage = 3, Accuracy = .8, SaveFile = saveFile, }; context.Add(slash); var skeleton = new Monsters { Id = new Guid(), Name = "Skeleton", Health = 7, Skill1Navigation = slash, }; context.Add(skeleton); #endregion Monsters context.SaveChanges(); } }
public TblGamesController(GameDataContext context) { _context = context; }
public ActionResult <Game> Create(Game game) { using var gameDataContext = new GameDataContext(); using var matchContext = new MatchContext(); long id = (gameDataContext.GameDatas.Max(m => (int?)m.Id) ?? 0) + 1; game.Id = id; if (game.Date == null) { game.Date = DateTime.Now.ToString("u", System.Globalization.CultureInfo.InvariantCulture); } gameDataContext.Add(new GameData { Id = id, Date = game.Date, }); gameDataContext.SaveChanges(); var matches = new List <Match>(); foreach (var player in game.Team1) { matches.Add(new Match { GameId = id, Player = player, Team = 1, }); } foreach (var player in game.Team2) { matches.Add(new Match { GameId = id, Player = player, Team = 2, }); } matchContext.AddRange(matches); matchContext.SaveChanges(); using var scoreContext = new ScoreContext(); float?result = null; if (game.Score == '1') { result = 1; } else if (game.Score == '2') { result = 0; } else if (game.Score == 'D') { result = 0.5f; } else if (game.Score == 'C') { result = -1; } scoreContext.Add(new Score { GameId = id, Result = result, }); scoreContext.SaveChanges(); return(CreatedAtAction(nameof(GetById), new { id = id }, game)); }
public CountGamesPerPlayer(GameDataContext context, PlayerDataContext Pcontext) { _context = context; _Pcontext = Pcontext; }
//constructing those based off of injections public HomeController(ILogger <HomeController> logger, GameDataContext gamedatacontext, UserContext usercontext) { _logger = logger; _gamedatacontext = gamedatacontext; _usercontext = usercontext; }
public HomeController(ILogger <HomeController> logger, ICodeAnalyzer codeAnalyzer, GameDataContext context) { _logger = logger; _codeAnalyzer = codeAnalyzer; _context = context; }
public IndexModel(GameDataContext context) { _context = context; }
public Query1Model(Server.Data.GameDataContext context, PlayerDataContext pcontext) { _context = context; _pcontext = pcontext; }
public PersistentPlayerData(GameDataContext ctx) { _ctx = ctx; }
public RepositorioJogo(GameDataContext contexto) : base(contexto) { }