Ejemplo n.º 1
0
        public void ApplySettings(int token, ServerSettingsDto settings)
        {
            pingQueue.Enqueue(1);
            GameLobbyLock.EnterWriteLock();
            if (!state.Players.ContainsKey(token))
            {
                Callback.SendLog("Gracz nie jest członkiem tej gry!");
                return;
            }
            if (state.AdminToken != token)
            {
                Callback.SendLog("Gracz nie ma uprawnień do zmiany ustawień.");
                return;
            }

            if (state.State != State.Lobby)
            {
                Callback.SendLog("Zmiana ustawień nie jest możliwa po rozpoczęciu gry.");
            }

            this.Config.AcceptSettings(settings);
            var gameInfo = new GameInfo(state.Players[token].Name, this.Config);

            ExecuteForAllPlayers(player =>
            {
                try {
                    player.Callback.SendLog(string.Format("Administrator pokoju {0} zmienił kilka ustawień.", state.Players[token].Name));
                    player.Callback.SendGameInfo(gameInfo);
                } catch (Exception e) {
                    Console.WriteLine("Przechwyciłem wyjątek: {0}", e.Message);
                }
            });
            GameLobbyLock.ExitWriteLock();
        }
Ejemplo n.º 2
0
 public void InitGame()
 {
     GameLobbyLock.EnterWriteLock();
     lock (state) {
         if (IsRequiredNumberOfPlayers() && IsEveryoneReady() && this.state.State == State.Lobby)
         {
             StartGame();
         }
         else if (IsRequiredNumberOfPlayers() && IsEveryoneReady() && this.state.State == State.WaitForReadiness)
         {
             this.state.State = State.WaitForCard;
             BroadcastMessage(string.Format("Rozpoczynanie rundy za {0} sekund...\n", Config.RoundIntervalMS / 1000));
             NotifyEveryoneAboutRoundStart(state.RoundNumber + 1);
             this.state.NextRoundTimer = new Timer(InitializeRound, null, Config.RoundIntervalMS, 0);
         }
     }
     GameLobbyLock.ExitWriteLock();
 }
Ejemplo n.º 3
0
        public void DeclareReadiness(int token, bool readiness)
        {
            if (!state.Players.ContainsKey(token))
            {
                Callback.SendLog("Nie jesteś przyłączony do lobby.");
                return;
            }

            GameLobbyLock.EnterWriteLock();

            this.state.Players[token].IsReady = readiness;
            int readyPlayersCount = (from players in state.PlayerList where players.IsReady select players).Count();

            BroadcastMessage(string.Format("{0} zgłosił gotowość! ({1}/{2})", state.Players[token].Name, readyPlayersCount, state.PlayerList.Count));

            GameLobbyLock.ExitWriteLock();
            BroadcastPlayerList();
            InitGame();
        }