private void StartStop_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; if (button.Content.ToString() == "Start") { if (!String.IsNullOrEmpty(txb_Ip.Text) || !String.IsNullOrEmpty(txb_Port.Text)) { this.battleshipServer = new BattleshipServer(txb_Ip.Text, int.Parse(txb_Port.Text)); this.battleshipServer.Start(); txb_Ip.IsEnabled = false; txb_Port.IsEnabled = false; button.Content = "Stop"; lbl_Error.Visibility = Visibility.Hidden; } else { lbl_Error.Content = "Ip and port cannot be empty!"; lbl_Error.Visibility = Visibility.Visible; } } else { this.battleshipServer.Stop(); this.battleshipServer = null; txb_Ip.IsEnabled = true; txb_Port.IsEnabled = true; button.Content = "Start"; } }
public Game(GamePlayer player1, GamePlayer player2, Session session, BattleshipServer battleshipServer) { this.state = GameState.SETUP; this.players = new GamePlayer[2] { player1, player2 }; this.currentTurnIndex = 0; this.session = session; this.battleshipServer = battleshipServer; }
private void BTN_StartStop_Click(object sender, EventArgs e) { if (null == this._server || !this._server.IsRunning) { this._server = new BattleshipServer(4242, this._log); this._server.Start(); if (this._server.IsRunning) { this.BTN_StartStop.Text = "STOP"; } } else { this._server.Stop(); if (!this._server.IsRunning) { this.BTN_StartStop.Text = "START"; } } }