Ejemplo n.º 1
0
        public GameResult Start()
        {
            RunGame();

            var result = new GameResult
            {
                GameWinner = state.GameWinner,
                Results = players.Select(p => new PlayerResult
                {
                    DidFail = didFail[p],
                    Player = p,
                    Score = state.FinalScore[p]
                }).ToArray(),
                Successful = true,
                Ticks = state.CurrentTick
            };

            return result;
        }
Ejemplo n.º 2
0
        private void PersistResults(GameResult gameResults)
        {
            log.Debug("Saving results");

            using (var ctx = new Data.HackathonArenaEntities())
            {
                var round = ctx.Rounds.Find(RoundId);
                var game = ctx.Games.Add(new Data.Game());

                var resultsByPlayer = gameResults.Results.ToDictionary(r => r.Player);
                var teams = resultsByPlayer.Keys.ToDictionary(p => p, p => ctx.Teams.First(t => t.Alias == p.Name));

                foreach (var kvp in resultsByPlayer)
                {
                    var dbRresult = ctx.TeamResults.Add(new Data.TeamResult());
                    var result = kvp.Value;

                    dbRresult.DidFail = result.DidFail;
                    dbRresult.Score = (short)result.Score;
                    dbRresult.Team = teams[kvp.Key];

                    game.TeamResults.Add(dbRresult);
                }

                game.Round = round;
                game.Timestamp = DateTime.Now;

                if (gameResults.GameWinner != null)
                    game.Winner = teams[gameResults.GameWinner];

                ctx.SaveChanges();
            }
        }