Пример #1
0
        public void UpdatePlayers()
        {
            foreach (var playerInfo in Players)
            {
                if (playerInfo.Id == 0)
                {
                    playerInfo.Id = Players.Select(x => x.Id).Max() + 1;
                }
            }

            var medianScore = !PlayerScores.Any() ? 0 : PlayerScores.Values.Aggregate(0, (x, y) => x + y) / PlayerScores.Count;

            var removedPlayers = PlayerScores.Keys.ToList();

            foreach (var playerInfo in Players)
            {
                if (!PlayerScores.ContainsKey(playerInfo.Id))
                {
                    PlayerScores.Add(playerInfo.Id, medianScore);
                }
                else
                {
                    removedPlayers.Remove(playerInfo.Id);
                }
            }

            foreach (var removedPlayer in removedPlayers)
            {
                PlayerScores.Remove(removedPlayer);
            }
        }
Пример #2
0
        private void AddPlayerScoreToList(Player player)
        {
            PlayerScore item = new PlayerScore();

            item.PlayerScoreId = Guid.NewGuid().ToString();
            item.MarkerId      = Preferences.Get("PlayerId", null);
            item.RoundId       = Round.RoundId;
            item.HCAP          = player.LastHCAP;
            item.PlayerId      = player.PlayerId;
            PlayerScores.Add(item);
        }
Пример #3
0
    public void AddResultForPlayer(Player player, int score, int pins)
    {
        if (PlayerScores.ContainsKey(player.Id) == false)
        {
            PlayerScores.Add(player.Id, new PlayerScore(player.Id, player.Name));
        }

        PlayerScore playerScore = PlayerScores[player.Id];

        playerScore.Score += score;
        playerScore.Pins  += pins;
        playerScore.Series++;
    }
Пример #4
0
        public CompPlayersViewModel()
        {
            azureService = DependencyService.Get <AzureService>();

            Title = "Players in Round ";

            // implement the ICommands
            AddPlayerCommand = new Command(() =>
            {
                if (SelectedPlayer == null)
                {
                    return;
                }
                IsBusy = true;
                // create new playerscore object, unless exists
                if (PlayerScores.FirstOrDefault(x => x.PlayerId == SelectedPlayer.PlayerId) == null)
                {
                    AddPlayerScoreToList(SelectedPlayer);
                }
                IsBusy = false;
            });

            RemovePlayerCommand = new Command <PlayerScore>((playerScore) =>
            {
                IsBusy = true;
                // mark as deleted
                //await azureService.DeletePlayerScoreAsync(playerScore);
                // remove from list, set deleted on and add back to force binding change on list
                PlayerScores.Remove(playerScore);
                playerScore.DeletedYN = (!playerScore.DeletedYN);
                PlayerScores.Add(playerScore);

                IsBusy = false;
            });

            AddMembersCommand = new Command(async() =>
            {
                // add all members of society
                IsBusy = true;
                foreach (Player player in PlayersPicker)
                {
                    if (PlayerScores.FirstOrDefault(x => x.PlayerId == player.PlayerId) == null)
                    {
                        AddPlayerScoreToList(player);
                    }
                }

                IsBusy = false;
            });

            SavePlayersCommand = new Command(async() =>
            {
                // save/delete players
                IsBusy = true;
                foreach (PlayerScore playerScore in PlayerScores)
                {
                    if (playerScore.DeletedYN)
                    {
                        await azureService.DeletePlayerScoreAsync(playerScore);
                    }
                    else
                    {
                        await azureService.SavePlayerScoreAsync(playerScore);
                    }
                }

                await Shell.Current.Navigation.PushAsync(new ScoreEntryPage(_round));
                IsBusy = false;
            });
        }