Ejemplo n.º 1
0
        public WaitJoinWindow(Uri uri, Color color)
        {
            InitializeComponent();
            LabelWait.Content = "Création de la partie";

            NetworkServiceHost.Create(uri);
            NetworkServiceHost.GetService().PlayerColor = color;
            NetworkServiceHost.Open();

            NetworkServiceHost.GetService().ClientUriReceived += NetworkGameServiceOnClientUriReceived;
            LabelWait.Content = "Attente d'un autre joueur";
        }
Ejemplo n.º 2
0
        private void ButtonJoin_OnClick(object sender, RoutedEventArgs e)
        {
            if (ComboBoxIP.SelectedItem == null ||
                TextBoxGameName.Text == "" ||
                TextBoxPort.Text == "" ||
                TextBoxPseudo.Text == "" ||
                TextBoxHostIP.Text == "" ||
                TextBoxHostPort.Text == "" ||
                TextBoxHostPseudo.Text == "")
            {
                _mainWindow.ShowMessageAsync("Paramètres incorrects", "Veuillez remplir tout les champs");
                return;
            }


            //Création du service
            Uri uri =
                new Uri("net.tcp://" + ComboBoxIP.SelectedItem + ":" + TextBoxPort.Text + "/" + TextBoxGameName.Text +
                        TextBoxPseudo.Text);

            NetworkServiceHost.Create(uri);
            NetworkServiceHost.Open();

            //On créer le client et on informe l'autre service de l'adresse de notre service
            Uri hostUri =
                new Uri("net.tcp://" + TextBoxHostIP.Text + ":" + TextBoxHostPort.Text + "/" + TextBoxGameName.Text +
                        TextBoxHostPseudo.Text);
            EndpointAddress endpointAddress = new EndpointAddress(hostUri);

            NetworkServiceClient.Create(endpointAddress);
            try
            {
                NetworkServiceClient.Channel().SendClientAdress(uri.ToString());
            }
            catch (Exception)
            {
                _mainWindow.ShowMessageAsync("Erreur réseau",
                                             "Il y a eu un problème lors de la connexion avec l\'autre joueur, cela peut provenir des paramètres que vous avez saisis.");
                return;
            }

            Color distantPlayerColor = NetworkServiceClient.Channel().GetColor() == "White" ? Color.White : Color.Black;
            Color color = distantPlayerColor == Color.White ? Color.Black : Color.White;

            NetworkServiceHost.GetService().PlayerColor = color;

            GameFactory gameFactory = new GameFactory();
            BoardView   boardView   = new BoardView(_container);

            Core.Game game = gameFactory.CreateGame(Mode.Network, _container, boardView, color, null);
            _mainWindow.MainControl.Content = new GameView(_mainWindow, game, boardView);
        }