public MultiplayerGameState(GraphicsDevice device, String name, String ip, int port)
 {
     Players          = new List <Player>();
     Listeners        = new List <GameListener>();
     Deck             = Deck.CreateFullDeck((device.Viewport.Bounds.Width / 2) - Deck.DECK_WIDTH, (device.Viewport.Bounds.Height / 2) - Deck.DECK_HEIGHT);
     CardPile         = new CardPile(Deck.Position.X + 60, Deck.Position.Y);
     CurrentPlayState = PlayState.DEAL;
     try
     {
         NetworkMediator mediator = new NetworkMediator();
         networkThread = new NetworkThread(mediator);
         thread        = new Thread(new ThreadStart(networkThread.Run));
         mediator.Connect(ip, port);
         mediator.SendMessage(name);
         String handshake = mediator.ReceiveMessageBlocking()[0];
         if (!handshake.Equals("NOT_OK"))
         {
             Players.Add(new LocalPlayer(PlayerPositions.South, name));
             List <String> usernames = MessageParser.ToPlayersConnected(handshake);
             if (usernames != null)
             {
                 foreach (String username in usernames)
                 {
                     AddPlayer(username);
                 }
             }
             thread.IsBackground = true;
             thread.Start();
         }
         else
         {
             Screens.ScreenManager.GotoScreen("menu", "Handshaking failed");
         }
     }
     catch (Exception ex)
     {
         Screens.ScreenManager.GotoScreen("menu", ex.Message);
     }
 }
예제 #2
0
 public NetworkThread(NetworkMediator nm)
 {
     mediator             = nm;
     ReceivedMessageQueue = new Queue <String>();
     MessageQueue         = new Queue <String>();
 }