Пример #1
0
 public void PlayGame(Game g)
 {
     lock (this.statusLock)
     {
         this.game = g;
         Debug.Assert(this.game == g && this.Status == ConnectionStatus.RespondingToGameProposal);
         this.Status = ConnectionStatus.PlayingGame;
     }
 }
Пример #2
0
 public void EndGame()
 {
     lock (this.statusLock)
     {
         this.game = null;
         Debug.Assert(this.Status == ConnectionStatus.PlayingGame);
         this.Status = ConnectionStatus.Ready;
     }
 }
Пример #3
0
        public void ProposeGameWithUsers(Connection source, List<string> players, GameSpecificationInfo gameSpecification, Lobby lobby)
        {
            List<Connection> gameConnections = new List<Connection>();
            lock (this.serverLock)
            {
                foreach (string target in players)
                {
                    User user = lobby.Users.FirstOrDefault(u => u.Name == target);
                    if (user == null)
                    {
                        NetworkMessage message = new NetworkMessage();
                        message.MessageCategory = SystemMessages.SystemPrefix;
                        message.MessageType = SystemMessages.DeclineGame;
                        source.SendMessage(message);
                        return;
                    }
                    else
                    {
                        gameConnections.Add(user.Connection);
                    }
                }

                for (int i = 0; i < gameConnections.Count; i++)
                {
                    bool ok = gameConnections[i].TryProposeGame();
                    if (!ok)
                    {
                        for (int j = 0; j < i; j++)
                        {
                            gameConnections[j].CancelGame();
                        }
                        return;
                    }
                }
            }
            Game game = new Game(gameConnections, this, lobby, gameSpecification);
            Thread thread = new Thread(new ThreadStart(game.NegotiateGame));
            thread.Start();
        }