/// <summary> /// Gets the ui elements / controls for the main menu /// </summary> /// <returns>List of UI Elements</returns> List <UIElement> GetMainControls() { // Declare list of ui controls to later return List <UIElement> controls = new List <UIElement>(); // Declare a new textblock TextBlock main_Text = UIElementConstructors.TextBlockConstructor("CHESS", "main_tb", 40, TextAlignment.Center, HorizontalAlignment.Center, VerticalAlignment.Top, 0, 1, 3); controls.Add(main_Text); // Add to controls list // Declare a new textblock TextBlock author_Text = UIElementConstructors.TextBlockConstructor("By: Tim Rundström", "autor_tb", 15, TextAlignment.Center, HorizontalAlignment.Center, VerticalAlignment.Bottom, 0, 1, 3); controls.Add(author_Text); // Add to controls list // Declare a new button Button single_Btn = UIElementConstructors.ButtonContructor("Play", "single_btn", 20, 5, Play_Single_Btn_Click, 1, 3, 1); controls.Add(single_Btn); // Add to controls list // Declare a new button Button online_Btn = UIElementConstructors.ButtonContructor("Online", "online_btn", 20, 5, Online_Btn_Click, 1, 4, 1); controls.Add(online_Btn); // Add to controls list // Declare a new button Button quit_Btn = UIElementConstructors.ButtonContructor("Quit", "quit_btn", 20, 5, Quit_Btn_Click, 1, 5, 1); controls.Add(quit_Btn); // Add to controls list // Return controls return(controls); }
/// <summary> /// Gets the ui elements / controls for the game over menu /// </summary> /// <returns>List of UI Elements</returns> List <UIElement> GetGameOverControls() { // Declare list of ui controls to later return List <UIElement> controls = new List <UIElement>(); // Declare a new textblock TextBlock tb = UIElementConstructors.TextBlockConstructor(MainWindow.board.GetVictory(), "victoryTb", 50, TextAlignment.Center, HorizontalAlignment.Center, VerticalAlignment.Center, 1, 1, 3); controls.Add(tb); // Add to controls // Declare a new button Button btn = UIElementConstructors.ButtonContructor("Main menu", "mainMenuBtn", 20, 0, Menu_Btn_Click, 2, 2, 1); controls.Add(btn); // Add to controls // return list of controls return(controls); }
/// <summary> /// Gets the ui elements / controls for the join menu /// </summary> /// <returns>List of UI Elements</returns> List <UIElement> GetJoinControls() { // Declare list of ui controls to later return List <UIElement> controls = new List <UIElement>(); // Declare a new textbox TextBox address_Text = UIElementConstructors.TextBoxConstructor("address_Text", 20, 5, 5, 1, 1, 2); controls.Add(address_Text); // Add textbox to controls // Address info textblock, for easier understanding what is what TextBlock address_info = UIElementConstructors.TextBlockConstructor("IPv4 Address", "address_info", 15, TextAlignment.Left, HorizontalAlignment.Center, VerticalAlignment.Bottom, 1, 0, 1); controls.Add(address_info); // Declare a new textbox TextBox port_Text = UIElementConstructors.TextBoxConstructor("port_Text", 20, 5, 5, 3, 1, 1); controls.Add(port_Text); // Add textbox of controls // Port info textblock, for easier understanding on what is what TextBlock port_info = UIElementConstructors.TextBlockConstructor("Port", "port_info", 15, TextAlignment.Left, HorizontalAlignment.Center, VerticalAlignment.Bottom, 3, 0, 1); controls.Add(port_info); // Declare a new button Button connect_Btn = UIElementConstructors.ButtonContructor("Connect", "connectBtn", 20, 5, Connect_Btn_Click, 1, 2, 1); controls.Add(connect_Btn); // Add button to controls // Info messagebox button Button info_Btn = UIElementConstructors.ButtonContructor("?", "infoBtn", 20, 5, Info_Btn_Click, 4, 1, 1); info_Btn.Width = 40; info_Btn.HorizontalAlignment = HorizontalAlignment.Left; controls.Add(info_Btn); // Declare a new button Button back_Btn = UIElementConstructors.ButtonContructor("Back", "backBtn", 20, 5, Online_Btn_Click, 2, 2, 2); controls.Add(back_Btn); // Add button to controls return(controls); }
/// <summary> /// Gets the ui elements / controls for the online menu /// </summary> /// <returns>List of UI Elements</returns> List <UIElement> GetOnlineControls() { // Declare list of ui controls to later return List <UIElement> controls = new List <UIElement>(); // Declare a new button Button host_Btn = UIElementConstructors.ButtonContructor("Host", "hostBtn", 20, 5, Host_Btn_Click, 1, 1, 1); controls.Add(host_Btn); // Add to controls // Declare a new button Button join_Btn = UIElementConstructors.ButtonContructor("Join", "join_Btn", 20, 5, Join_Btn_Click, 2, 1, 1); controls.Add(join_Btn); // Add to controls // Declare a new button Button back_Btn = UIElementConstructors.ButtonContructor("Back", "back_Btn", 20, 5, Menu_Btn_Click, 1, 2, 2); controls.Add(back_Btn); // Add to controls // Return the list of controls return(controls); }
/// <summary> /// Gets the ui elements / controls for the host menu /// </summary> /// <returns>List of UI Elements</returns> List <UIElement> GetHostControls() { // Declare list of ui controls to later return List <UIElement> controls = new List <UIElement>(); string ip = MainWindow.server.IP; // Get hosting ip string port = MainWindow.server.port.ToString(); // Get hosting port // Declare a new textblock TextBlock address_tb = new TextBlock(); address_tb.Name = "address_TextBlock"; // Set name address_tb.Text = ip; // Set text address_tb.FontSize = 20; // Set fontsize address_tb.Margin = new Thickness(5); // Give a margin of thickness 5 // Declare a new border for address_Text Border address_border = UIElementConstructors.BorderConstructor(Colors.Black, 1, 5, 1, 1); address_border.Child = address_tb; // Add address_tb as child of border element controls.Add(address_border); // Add border to controls; // Address info textblock, for easier understanding what is what TextBlock address_info = UIElementConstructors.TextBlockConstructor("IPv4 Address", "address_info", 15, TextAlignment.Left, HorizontalAlignment.Center, VerticalAlignment.Bottom, 1, 0, 1); controls.Add(address_info); // Declare a new textblock TextBlock port_tb = new TextBlock(); address_tb.Name = "port_TextBlock"; // Set name port_tb.Text = port; // Set text port_tb.FontSize = 20; // Set fontsize port_tb.Margin = new Thickness(5); // Give a margin of thickness 5 // Declare a new border for address_Text Border port_border = UIElementConstructors.BorderConstructor(Colors.Black, 1, 5, 2, 1); port_border.Child = port_tb; // Add port_tb as child of border element controls.Add(port_border); // Add border to controls; // Port info textblock, for easier understanding on what is what TextBlock port_info = UIElementConstructors.TextBlockConstructor("Port", "port_info", 15, TextAlignment.Left, HorizontalAlignment.Center, VerticalAlignment.Bottom, 2, 0, 1); controls.Add(port_info); // Info messagebox button Button info_Btn = UIElementConstructors.ButtonContructor("?", "infoBtn", 20, 5, Info_Btn_Click, 3, 1, 1); info_Btn.Width = 40; info_Btn.HorizontalAlignment = HorizontalAlignment.Left; controls.Add(info_Btn); // Declare a new button Button back_Btn = UIElementConstructors.ButtonContructor("Back", "backBtn", 20, 5, Online_Btn_Click, 1, 2, 2); controls.Add(back_Btn); // Add button to controls // return list of controls return(controls); }
/// <summary> /// Gets the ui elements / controls for the game /// </summary> /// <returns>List of UI Elements</returns> List <UIElement> GetGameControls() { // Declare list of ui controls to later return List <UIElement> controls = new List <UIElement>(); // Declare a new textblock TextBlock whitePointsTb = UIElementConstructors.TextBlockConstructor("", "whitePointsTb", 15, TextAlignment.Center, HorizontalAlignment.Center, VerticalAlignment.Center, 0, 0, 3); controls.Add(whitePointsTb); // Add to controls list // Declare a new textblock TextBlock blackPointsTb = UIElementConstructors.TextBlockConstructor("", "blackPointsTb", 15, TextAlignment.Center, HorizontalAlignment.Center, VerticalAlignment.Center, 7, 0, 3); controls.Add(blackPointsTb); // Add to controls list // Declare a new textblock TextBlock turnTb = UIElementConstructors.TextBlockConstructor("", "turnTb", 20, TextAlignment.Center, HorizontalAlignment.Center, VerticalAlignment.Center, 3, 0, 4); controls.Add(turnTb); // Add to controls list // Declare a new textblock TextBlock colorTb = UIElementConstructors.TextBlockConstructor("", "colorTb", 12, TextAlignment.Center, HorizontalAlignment.Center, VerticalAlignment.Bottom, 3, 0, 4); controls.Add(colorTb); // Add to controls list // Create row numbers and column letters (8x8) for (int i = 0; i < 8; i++) { // Declare a new horizontal textblock TextBlock horizontalTb = UIElementConstructors.TextBlockConstructor((i + 1).ToString(), "horizontalTb", 12, TextAlignment.Center, HorizontalAlignment.Right, VerticalAlignment.Center, 0, 8 - i, 1); controls.Add(horizontalTb); // Add to controls list // Declare a new vertical textblock TextBlock verticalTb = UIElementConstructors.TextBlockConstructor(((char)(65 + i)).ToString(), "verticalTb", 12, TextAlignment.Center, HorizontalAlignment.Center, VerticalAlignment.Top, i + 1, 9, 1); controls.Add(verticalTb); // Add to controls list } MainWindow.board.buttons.Clear(); // Clear buttons list (clear up leftovers of last game) // Bool for determining whether the button should have a white or black background bool white = true; // Create chessboard (8x8 grid of buttons) for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Position pos = new Position(j + 1, 8 - i); // Get its position Button btn = UIElementConstructors.ButtonContructor("", pos.btnName, 40, 2, null, j + 1, i + 1, 1); if (white) { btn.Background = new SolidColorBrush(Colors.White); // Set background white } else { btn.Background = new SolidColorBrush(Colors.Gray); // Set background black (gray) } white = !white; // Switch so next button is another colour btn.BorderBrush = new SolidColorBrush(Colors.Black); // Set a black border btn.BorderThickness = new Thickness(3); // Set a border thickness of 3 btn.Padding = new Thickness(0, -5, 0, 0); // Give a negative padding on top (lift up text) btn.Style = btnStyle; // Set the style MainWindow.board.buttons.Add(pos.name, btn); // Add to buttons dictionary in board object controls.Add(btn); // Add to controls } white = !white; // Switch background colour order, so that the next rows colour is adjacent } SetGameButtonEvents(); // Set all the events to the buttons return(controls); // return controls }