예제 #1
0
        //// This is part of a failed attempt to use Binding. Binding currently does not work because non-UI threads cannot change the contents of
        //// observable collections. We should keep this code here in case we want to revisit binding in the future.
        //public event PropertyChangedEventHandler PropertyChanged;

        //public ObservableCollection<Player> PlayerList
        //{
        //    get
        //    {
        //        if ( playerList != null )
        //        {
        //            return new ObservableCollection<GameObjects.Player>(playerList);
        //        }
        //        else
        //        {
        //            return null;
        //        }
        //    }
        //    set
        //    {
        //        playerList.Clear();
        //        foreach ( Player player in value )
        //        {
        //            playerList.Add(player);
        //        }
        //        OnPropertyChanged("PlayerList");
        //    }
        //}

        //// Create the OnPropertyChanged method to raise the event
        //protected void OnPropertyChanged( string name )
        //{
        //    PropertyChangedEventHandler handler = PropertyChanged;
        //    if ( handler != null )
        //    {
        //        handler(this, new PropertyChangedEventArgs(name));
        //    }
        //}

        public RoomWindow(string ipAddress, int portNumber, string playerName)
        {
            InitializeComponent();
            this.DataContext        = this;
            this.ServerIP           = ipAddress;
            this.PortNumber         = portNumber;
            this.BeginCommunication = false;
            this.PlayerName         = playerName;

            InitializeClient(ipAddress, portNumber);

            // Do not continue until the client has successfully established communication with the server.
            WaitMessage = new MessageDialog(this, ResourceList.PleaseWaitWindowTitle, "Waiting to establish communication with server...", isModal: false);
            if (!this.BeginCommunication)
            {
                WaitMessage.ShowDialog();
            }

            // Create a Wait dialog to stop the creation of the room window until the player list is retrieved from the server.
            WaitMessage = new MessageDialog(this, ResourceList.PleaseWaitWindowTitle, "Waiting for player list...", isModal: false);

            // Receive a list of the players already on the server.
            ServerUtilities.SendMessage(Client, Datatype.RequestPlayerList);

            // Do not continue until the client receives the Player List from the server.
            WaitMessage.ShowDialog();

            // If the PlayerList is still null, the player must have closed the window manually.
            if (null == this.PlayerList)
            {
                this.ShowWindow = false;
            }
            else
            {
                // Verify that the value of 'playerName' does not exist in the list of Player names.
                // If it does, modify the name so that it no longer matches one on the list.
                this.PlayerName = VerifyPlayerName(this.PlayerName);

                // Instantiate the player.
                this.Player = new Player(this.PlayerName);

                // Send the player's information to the server.
                ServerUtilities.SendMessage(Client, Datatype.UpdatePlayer, Player);
            }
        }
예제 #2
0
 private void PublishEvent(string eventLogline)
 {
     ServerUtilities.SendMessage(this.netClient, Datatype.GameEvent, eventLogline);
 }
예제 #3
0
 private void LaunchGameButton_Click(object sender, RoutedEventArgs e)
 {
     ServerUtilities.SendMessage(Client, Datatype.LaunchGame);
 }