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); } } }
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); } }
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); } }