/// <summary> /// Initializes a new instance of the <see cref="BattleFieldViewModel"/> class. /// </summary> /// <param name="viewShell">The shell of the view model.</param> public BattleFieldViewModel(ViewShellBaseViewModel viewShell) : base(viewShell) { ViewShellViewModel viewShellVM = (ViewShellViewModel)viewShell; this.client = viewShellVM.Client; this.client.StopSendingLobbyRequests(); this.ShipPositionsSent = false; this.ShipToPlace = new ShipToPlaceViewModel(); this.UserBattleFieldArea = new BattleFieldAreaViewModel(10, 10); this.UserBattleFieldArea.SetSquareCommands(new AddShipPositionCommand(this, this.UserBattleFieldArea, this.client)); this.UserBattleFieldArea.HighlightSquaresCommand = new HighlightSquaresCommand(this.UserBattleFieldArea, this); this.UserBattleFieldArea.EnableSquares(); this.OpponentBattleFieldArea = new BattleFieldAreaViewModel(10, 10); SendMoveCommand sendMoveCommand = new SendMoveCommand(viewShellVM.Client, this.OpponentBattleFieldArea); this.OpponentBattleFieldArea.SetSquareCommands(sendMoveCommand); this.Toolbar = new ToolbarViewModel(); this.ToolbarVisible = true; this.client.MoveRequestReceived += this.Client_MoveRequestReceived; this.client.OpponentMoveReceived += this.Client_OpponentMoveReceived; this.client.MoveReportReceived += this.Client_MoveReportReceived; this.client.GameLost += this.Client_GameLost; this.client.GameWon += this.Client_GameWon; }
/// <summary> /// Initializes a new instance of the <see cref="LobbyViewModel"/> class. /// </summary> /// <param name="viewShell">The view shell.</param> public LobbyViewModel(ViewShellBaseViewModel viewShell) : base(viewShell) { this.shell = (ViewShellViewModel)this.ViewShell; this.BattleListVM = new BattleListViewModel(this.shell.Client); this.shell.Client.ChallengerFound += this.Client_ChallengerFound; this.shell.Client.InitiateBattleReceived += this.Client_InitiateBattleReceived; this.shell.Client.ConnectionLost += this.Client_ConnectionLost; this.shell.Client.OpponentDeclined += this.Client_OpponentDeclined; this.Modal = new BattleFieldModalViewModel(string.Empty); }
/// <summary> /// Initializes a new instance of the <see cref="ServerModeViewModel"/> class. /// </summary> /// <param name="viewShell">The view shell.</param> public ServerModeViewModel(ViewShellBaseViewModel viewShell) : base(viewShell) { ViewShellViewModel shell = (ViewShellViewModel)this.ViewShell; TcpConnectionManager tcpConnectionManager = new TcpConnectionManager(shell.TcpListener, 1600); this.server = new Server(tcpConnectionManager); shell.Server = this.server; this.server.Start(); }
/// <summary> /// Executes the command. /// </summary> /// <param name="parameter">Possible specified command arguments.</param> public override void Execute(object parameter) { ViewShellViewModel shell = (ViewShellViewModel)this.ViewShell; string ip = (string)parameter; try { shell.Client.ServerIP = IPAddress.Parse(ip); shell.Client.Connect(); } catch { MessageBox.Show("The entered IP Address is either invalid or the server is down!", "Failed to connect.", MessageBoxButton.OK); shell.View = new MainMenuViewModel(shell); return; } shell.View = new LobbyViewModel(shell); }
/// <summary> /// Initializes a new instance of the <see cref="EnterServerIPViewModel"/> class. /// </summary> /// <param name="viewShell">The view shell.</param> public EnterServerIPViewModel(ViewShellBaseViewModel viewShell) : base(viewShell) { ViewShellViewModel shell = (ViewShellViewModel)viewShell; shell.Client = new Client(new TcpConnection()); }