Exemplo n.º 1
0
        public async Task <Tuple <bool, string> > onEndGame(Game game)
        {
            if (game.scores.All(u => u.scores.Count(s => s.HasValue) == 7))
            {
                CurrentGame.isCompleted = true;

                try
                {
                    var winner = CurrentGame.scores.Aggregate((curMin, s) => curMin == null || (s.scores.Sum() ?? 0) <
                                                              curMin.scores.Sum() ? s : curMin);

                    var looser = CurrentGame.scores.Aggregate((curMax, s) => curMax == null || (s.scores.Sum() ?? 0) >
                                                              curMax.scores.Sum() ? s : curMax);

                    CurrentGame.winnerId = winner.userId;
                    WinnerId             = winner.userId;
                    CurrentGame.looserId = looser.userId;

                    await _scoreboardRepository.UpdateGame(_groupDocId, CurrentGame);

                    MessagingCenter.Send(this, "gameCompleted");

                    return(new Tuple <bool, string>(true, $"Match won by {winner.user?.name}"));
                }
                catch (Exception ex)
                {
                    await _page.DisplayAlert(ex.Message);

                    return(new Tuple <bool, string>(false, ex.Message));
                }
            }
            else
            {
                return(new Tuple <bool, string>(false, "Please enter scores for all sets"));
            }
        }
Exemplo n.º 2
0
 public Task DisplayAlert(string title, string message, string cancel)
 {
     return(_page.DisplayAlert(title, message, cancel));
 }