public MainWindow(BattleshipClient battleshipClient, string sessionName, string sessionId, bool isHost) { InitializeComponent(); this.Title = UserLogin.Username; //this.isClosed = false; this.battleshipClient = battleshipClient; this.battleshipClient.SetMessageReceiver(this); this.sessionName = sessionName; this.sessionId = sessionId; this.isHost = isHost; this.game = new Game(Application.Current.Dispatcher, ref vwp, this.battleshipClient, this.isHost); //this.Closing += MainWindow_Closing; this.game.Start(); this.KeyDown += MainWindow_KeyDown; this.KeyUp += MainWindow_KeyUp; this.MouseDown += MainWindow_MouseDown; this.MouseUp += MainWindow_MouseUp; this.MouseMove += MainWindow_MouseMove; //grid = new Battleship.GameObjects.Grid(this.game); //this.Cursor = Cursors.None; this.Closing += MainWindow_Closing; //this.Closed += MainWindow_Closed; txb_ChatMessage.GotFocus += Txb_ChatMessage_GotFocus; txb_ChatMessage.LostKeyboardFocus += Txb_ChatMessage_LostKeyboardFocus; this.mediaPlayer = new MediaPlayer(); }
public GameBrowser(BattleshipClient battleshipClient) { InitializeComponent(); this.battleshipClient = battleshipClient; this.battleshipClient.SetMessageReceiver(this); this.joinSessionIdCache = ""; this.battleshipClient.Transmit(new Message(Message.ID.GET_SESSIONS, Message.State.NONE, null)); }
static void Main(string[] args) { var success = false; var host = ""; int port = 0; Player player; do { Console.Clear(); Console.WriteLine("BattleShip 1.0"); var shipGen = new ShipGenerator(); player = shipGen.GenerateShips(); foreach (var boat in player.Boats) { Console.WriteLine("\n" + boat.Name + " "); foreach (var boatCoordinates in boat.Coordinates) { Console.Write(boatCoordinates.Name + " "); } } Console.WriteLine("\n\nDina Försök(rött är miss, grönt är träff): \n"); Console.WriteLine("\nAnge host: "); host = Console.ReadLine(); Console.WriteLine("Ange port: "); success = int.TryParse(Console.ReadLine(), out port); Console.WriteLine("Namn: "); player.Name = Console.ReadLine(); } while (!success); if (string.IsNullOrEmpty(host)) { var server = new BattleshipServer(); server.StartListening(port, player); } else { var client = new BattleshipClient(); client.ConnectingToServer(host, port, player); } }
public AuthorizationWindow(BattleshipClient battleshipClient) { InitializeComponent(); //if (battleshipClient == null) // this.battleshipClient = new BattleshipClient(ClientSettings.Ip, ClientSettings.Port, this); //else // this.battleshipClient.SetMessageReceiver(this); if (battleshipClient != null) { this.battleshipClient?.SetMessageReceiver(this); } this.slideAnimation = new ThicknessAnimation(); this.slideAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); Storyboard.SetTargetProperty(slideAnimation, new PropertyPath(Grid.MarginProperty)); Storyboard.SetTargetProperty(slideAnimation, new PropertyPath(Grid.MarginProperty)); this.storyBoard = new Storyboard(); this.storyBoard.Children.Add(this.slideAnimation); this.isRegistering = false; }
public LobbyWindow(BattleshipClient battleshipClient, string sessionName, string sessionId, bool isHost) { InitializeComponent(); this.battleshipClient = battleshipClient; this.battleshipClient.SetMessageReceiver(this); this.sessionName = sessionName; this.sessionId = sessionId; this.isHost = isHost; con_Players.Header += this.sessionName; this.isReady = false; if (!isHost) { btn_StartGame.Visibility = Visibility.Collapsed; } this.battleshipClient.Transmit(new Message(Message.ID.GET_PLAYERS, Message.State.NONE, null)); }
private void Connect_Click(object sender, RoutedEventArgs e) { if (!String.IsNullOrEmpty(txb_Ip.Text) || !String.IsNullOrEmpty(txb_Port.Text)) { this.battleshipClient = new BattleshipClient(txb_Ip.Text, int.Parse(txb_Port.Text), this); if (!this.battleshipClient.Connect()) { lbl_Error.Content = "Connection failed!"; lbl_Error.Visibility = Visibility.Visible; } else { stk_Connect.Visibility = Visibility.Collapsed; stk_Content.Visibility = Visibility.Visible; } } else { lbl_Error.Content = "Ip and port cannot be empty!"; lbl_Error.Visibility = Visibility.Visible; } }