コード例 #1
0
        public async Task Leave(IPlayerGrain player)
        {
            logger.LogInformation($"Player {player.GetPrimaryKeyString()} left the game");

            info.Players.Remove(player);

            logger.LogInformation($"Game {info.Key} now has {info.Players.Count} players");

            // TODO: This can fail, update with correct error handling
            await stream.OnNextAsync(new PlayerLeftMessage()
            {
                PlayerId = player.GetPrimaryKeyString()
            });
        }
コード例 #2
0
        public async Task Join(IPlayerGrain player)
        {
            logger.LogInformation($"Player {player.GetPrimaryKeyString()} joined the game");

            if (info.Players.Contains(player))
            {
                logger.LogInformation($"Player {player.GetPrimaryKeyString()} was already in the game!");
                throw new Exception("Player was already in this game!");
            }

            info.Players.Add(player);

            logger.LogInformation($"Game {info.Key} now has {info.Players.Count} players");

            // TODO: This can fail, update with correct error handling
            await stream.OnNextAsync(new PlayerJoinedMessage()
            {
                PlayerId = player.GetPrimaryKeyString()
            });
        }