public async Task<GameResult> LoadGameResult(Guid gameId, string playerName)
		{
			var gameResult = await _contestDao.FindGameResult(gameId);
			this.Shots = GenerateShots(gameResult, playerName);
			this.CurrentShotNumber = gameResult == null ? 1 : gameResult.Scores.Where(x => x.PlayerName.Equals(playerName)).Count() + 1;
			this.PlayerTotalScore = gameResult == null ? 0 : gameResult.TotalScore;

			if (_startGameOnLoading)
			{
				await StartGame(this.CurrentGame);

				List<Events.Live.Shot> eventShots = new List<Events.Live.Shot>();
				foreach (var shot in gameResult.Scores)
					eventShots.Add(new Events.Live.Shot() { PlayerName = shot.PlayerName, ShotNumber = shot.ShotNumber, Score = shot.Points });
				var @event = new GameStarted
				{
					GameId = gameId,
					PlayerName = this.CurrentGame.PlayerName,
					TeamName = this.CurrentGame.TeamName,
					Shots = eventShots
				};

				_liveBus.Publish(@event);

				_startGameOnLoading = false;
			}

			this.ShotNumberToEdit = 0; // Reset edit mode

			return gameResult;
		}
Ejemplo n.º 2
0
		private void OnGameStarted(GameStarted e)
		{
			this.CurrentGameId = e.GameId;
			this.CurrentPlayerName = e.PlayerName;
			this.CurrentTeamName = e.TeamName;
			_scores.Clear();
			if (e.Shots != null)
			{
				foreach (var shot in e.Shots.Where(x => e.PlayerName.Equals(x.PlayerName)))
				{
					_scores.Add(shot.ShotNumber, shot.Score);
				}
			}
			this.OnPropertyChanged("Scores");
			this.OnPropertyChanged("PlayerTotalScore");
			if (e.Shots != null)
				_totalTeamScoreWithoutPlayer = e.Shots.Where(x => !e.PlayerName.Equals(x.PlayerName)).Sum(x => x.Score);
			else
				_totalTeamScoreWithoutPlayer = 0;
			this.OnPropertyChanged("TeamTotalScore");
			this.OnPropertyChanged("IsTeamGame");

			this.Items = new ObservableCollection<LeaderboardItem>();

			this.Leaderboard = new NotifyTaskCompletion<Leaderboard>(this.GetLeaderboard());
			this.OnPropertyChanged("Leaderboard");

			for (int i = 1; i <= 9; i++)
				this.RaiseScoreChanged(i);

		}