Exemplo n.º 1
0
        public void AddOrUpdatePlayer(Player player)
        {
            var existing = Players.FirstOrDefault((p) => p.Id == player.Id);

            if (existing != null)
            {
                existing.Name = player.Name;
                OnPlayerUpdated?.Invoke(
                    this,
                    new PlayerEventArgs {
                    EventType = "player-updated", Player = existing
                }
                    );
            }
            else
            {
                player.Score = 0;
                Players.Add(player);
                OnPlayerCreated?.Invoke(
                    this,
                    new PlayerEventArgs {
                    EventType = "player-created", Player = player
                }
                    );
            }
        }
Exemplo n.º 2
0
        public void UpdatePlayerScore(Player player)
        {
            var existing = Players.FirstOrDefault((p) => p.Id == player.Id);

            if (existing != null)
            {
                existing.Score = player.Score;
                OnPlayerUpdated?.Invoke(
                    this,
                    new PlayerEventArgs {
                    EventType = "player-updated", Player = existing
                }
                    );
            }
        }
Exemplo n.º 3
0
        private void HandleGameEnding(object sender, GameEventArgs args)
        {
            var winner = CurrentGame.Winner;

            OnGameEnded?.Invoke(this, new GameEventArgs("game-ended")
            {
                Winner = winner
            });
            if (winner != null)
            {
                winner.Score += GameConfig.GameValue;
                OnPlayerUpdated?.Invoke(this, new PlayerEventArgs {
                    EventType = "player-updated", Player = winner
                });
            }
        }