예제 #1
0
        public void RemovePlayer(string connectionId)
        {
            var player = PlayerService.Get(connectionId);

            if (player == null)
            {
                return;
            }
            PlayerService.Remove(player);
            Duel duel;

            if ((duel = DuelService.GetDuelForPlayer(player.ConnectionId)) != null)
            {
                var duelPlayer = duel.Players.First(i => i.Player == player);
                duelPlayer.Disconnected = true;

                if (duel.Players.All(i => i.Disconnected))
                {
                    DuelService.FinishAndRemove(duel);
                }
            }
        }
예제 #2
0
        public void ReadyToPlay(string connectionId)
        {
            var player = PlayerService.Get(connectionId);

            if (player == null)
            {
                return;
            }
            var duel = DuelService.GetDuelForPlayer(player.ConnectionId);

            if (duel == null)
            {
                return;
            }
            player.Status = PlayerStatus.ReadyToPlay;
            var opponents = duel.GetOpponents(player.ConnectionId).ToList();
            var allready  = opponents.Any() && opponents.All(t => t.Status == PlayerStatus.ReadyToPlay);

            if (allready)
            {
                StartDuel(duel);
            }
        }
예제 #3
0
        public void RecordStep(string connectionId, Step step)
        {
            Player player = PlayerService.Get(connectionId);

            if (player == null)
            {
                return;
            }
            Duel duel = DuelService.GetDuelForPlayer(player.ConnectionId);

            if (duel == null || duel.IsGameOver)
            {
                return;
            }

            Player opponent = duel.GetOpponent(player.ConnectionId);

            GetContext().Clients.Client(opponent.ConnectionId).receiveStep(step);

            if (duel.IsGameOverStep(step))
            {
                TryWinDuel(duel, player);
            }
        }