private void ButtonCreate_OnClick(object sender, RoutedEventArgs e) { if (ComboBoxIP.SelectedItem == null || TextBoxGameName.Text == "" || TextBoxPort.Text == "" || TextBoxPseudo.Text == "") { _mainWindow.ShowMessageAsync("Paramètres incorrects", "Veuillez remplir tout les champs."); return; } Uri uri = new Uri("net.tcp://" + ComboBoxIP.SelectedItem + ":" + TextBoxPort.Text + "/" + TextBoxGameName.Text + TextBoxPseudo.Text); WaitJoinWindow waitJoinWindow = new WaitJoinWindow(uri, GetComboBoxColor()); if (waitJoinWindow.ShowDialog() == true) { GameFactory gameFactory = new GameFactory(); BoardView boardView = new BoardView(_container); Core.Game game = gameFactory.CreateGame(Mode.Network, _container, boardView, GetComboBoxColor(), null); _mainWindow.MainControl.Content = new GameView(_mainWindow, game, boardView); } else { // Attention : pratique choquante try { NetworkServiceHost.Close(); } catch (Exception) { ; //Rien à faire (technique de pro) } _mainWindow.ShowMessageAsync("Erreur réseau", "Il y a eu un problème lors de la connexion avec l'autre joueur... Vueillez réessayer."); } }
public NetworkPlayerController(NetworkServiceHost networkServiceHost) { NetworkServiceHost = networkServiceHost; Client = NetworkServiceClient.Channel(); /** Quand notre service reçoit le mouvement du joueur graphique de l'autre jeu dans ce cas, * on l'envoie comme notre mouvment étant donné qu'on représente ce joueur dans notre partie */ networkServiceHost.NetworkGameService.MoveReceived += NetworkGameServiceOnMoveReceived; }
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"; }
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); }
public Game CreateGame(Container container, BoardView boardView, NetworkServiceHost networkServiceHost, Color color) { Engine.Engine engine = new RealEngine(container); Game game; // Si le joueur local est blanc if (color == Color.White) { PlayerControler whitePlayerControler = new BoardViewPlayerController(boardView); PlayerControler blackPlayerControler = new NetworkPlayerController(networkServiceHost); Player whitePlayer = new Player(Color.White, whitePlayerControler); Player blackPlayer = new Player(Color.Black, blackPlayerControler); game = new Game(engine, whitePlayer, blackPlayer, container); whitePlayer.Game = game; blackPlayer.Game = game; whitePlayerControler.Player = whitePlayer; blackPlayerControler.Player = blackPlayer; boardView.BoardViewPlayerControllers.Add((BoardViewPlayerController)whitePlayerControler); } else { PlayerControler whitePlayerControler = new NetworkPlayerController(networkServiceHost); PlayerControler blackPlayerControler = new BoardViewPlayerController(boardView); Player whitePlayer = new Player(Color.White, whitePlayerControler); Player blackPlayer = new Player(Color.Black, blackPlayerControler); game = new Game(engine, whitePlayer, blackPlayer, container); whitePlayer.Game = game; blackPlayer.Game = game; whitePlayerControler.Player = whitePlayer; blackPlayerControler.Player = blackPlayer; boardView.BoardViewPlayerControllers.Add((BoardViewPlayerController)blackPlayerControler); } SMTPLogger smtpLogger = new SMTPLogger(game); return(game); }
public override Core.Game CreateGame(Container container, BoardView boardView, Color color, GameCreatorParameters parameters) { IEngine engine = new RealEngine(container); Core.Game game; // Si le joueur local est blanc if (color == Color.White) { PlayerControler whitePlayerControler = new BoardViewPlayerController(boardView); PlayerControler blackPlayerControler = new NetworkPlayerController(NetworkServiceHost.GetNetworkServiceHost()); Player whitePlayer = new Player(Color.White, whitePlayerControler); Player blackPlayer = new Player(Color.Black, blackPlayerControler); game = new Core.Game(engine, whitePlayer, blackPlayer, container, false); whitePlayer.Game = game; blackPlayer.Game = game; whitePlayerControler.Player = whitePlayer; blackPlayerControler.Player = blackPlayer; boardView.BoardViewPlayerControllers.Add((BoardViewPlayerController)whitePlayerControler); } else { PlayerControler whitePlayerControler = new NetworkPlayerController(NetworkServiceHost.GetNetworkServiceHost()); PlayerControler blackPlayerControler = new BoardViewPlayerController(boardView); Player whitePlayer = new Player(Color.White, whitePlayerControler); Player blackPlayer = new Player(Color.Black, blackPlayerControler); game = new Core.Game(engine, whitePlayer, blackPlayer, container, false); whitePlayer.Game = game; blackPlayer.Game = game; whitePlayerControler.Player = whitePlayer; blackPlayerControler.Player = blackPlayer; boardView.BoardViewPlayerControllers.Add((BoardViewPlayerController)blackPlayerControler); } //SMTPLogger smtpLogger = new SMTPLogger(game); return(game); }
private void NetworkGameServiceOnClientUriReceived(string uri) { LabelWait.Content = "Configuration de la partie"; EndpointAddress endpointAddress = new EndpointAddress(uri); try { NetworkServiceClient.Create(endpointAddress); } catch (Exception) { NetworkServiceHost.Close(); DialogResult = false; } LabelWait.Content = "Tentative de connexion avec le client"; DialogResult = true; }
private bool Ping() { string testMessage = "42"; NetworkServiceClient.Channel().Echo(testMessage); try { string received = NetworkServiceClient.Channel().Echo(testMessage); if (received != testMessage) { NetworkServiceHost.Close(); return(false); } return(true); } catch (Exception) { NetworkServiceHost.Close(); return(false); } }
public Game CreateNetworkGame(Container container, BoardView boardView, NetworkServiceHost networkServiceHost, Color color) { NetworkGameCreator networkGameCreator = new NetworkGameCreator(); return(networkGameCreator.CreateGame(container, boardView, networkServiceHost, color)); }