Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Threading;
- using UITimer = System.Windows.Forms.Timer;
- namespace Client
- {
- public partial class Form1 : Form
- {
- // note !-> all the consts' values mean this.width (OR height) / value
- private const int ALLIGMENT_FROM_TOP = 20; // the alligment from the top of the screen
- private const int ALLIGMENT_FROM_LEFT = 20; // the alligment from the Left of the screen
- private const int LOG_IN_FORM_TXT_X_SIZE = 4; // the size of the text boxes in x axis which will be shown on the screen
- private const int LOG_IN_FORM_TEXT_SECTOR_HEIGHT = 2; // the height of the username password and email text boxes
- private const int LOG_IN_FORM_ALLGIMENT_FROM_TEXT_TO_LABEL = 50; // alligment from label to textbox
- private const int LOG_IN_FORM_PICBOX_HEIGHT = 4; // the height of the buttons (width / 4)
- private const int SIGN_OUT_FORM_BACK_HEIGHT_WIDTH = 6; // the height and width of the back button
- private const int CLOSE_GAME_BUTTON_WIDTH = 7; // the width of the close button
- private const int CLOSE_GAME_BUTTON_HEIGHT = 16; // the height of the close button
- private const int MAIN_FORM_PICBOX_HEIGHT = 10; // the height of the picture boxes in main form
- private const int MAIN_FORM_PICBOX_WIDTH = 5; // the width of the picture boxes in the main form
- private const int MAIN_FORM_LOG_OUT_HEIGHT = 12; // the height of the log out button
- private const int MAIN_FORM_LOG_OUT_WIDTH = 7; // the width of the log out button
- private const int BEST_SCORES_FORM_PB_HEIGHT = 4; // the height of the best scores pictures
- private const int BEST_SCORES_FORM_PB_WIDTH = 5; // the width of the best scores picture
- private const int JOIN_ROOM_FORM_ROOMS_LB_WIDTH = 4; // the width of the rooms list
- private const int JOIN_ROOM_FORM_USERS_LB_WIDTH = 5; // the width of the users list
- private const int JOIN_ROOM_FORM_BUTTON_SECTOR_Y = 4; // the height of the button sector
- private const int JOIN_ROOM_FORM_REFRESH_HEIGHT = 2; // the height of the refresh button
- private const int JOIN_ROOM_FORM_REFRESH_WIDTH = 8; // the width of the refresh button
- private const int JOIN_ROOM_FORM_JOIN_HEIGHT = 8; // the height of the join button
- private const int JOIN_ROOM_FORM_JOIN_WIDTH = 4; // the width of the join button
- private const int IN_ROOM_FORM_BUTTON_SECTOR_Y = 6; // the height of the button sector
- private const int IN_ROOM_FORM_BUTTON_HEIGHT = 8; // the height of the button
- private const int IN_ROOM_FORM_BUTTON_WIDTH = 3; // the width of the button
- private const int IN_ROOM_FORM_LB_WIDTH = 4; // the width of the list box
- private const int CREATE_ROOM_FORM_BUTTON_HEIGHT = 10; // the height of create button
- private const int CREATE_ROOM_FORM_BUTTON_WIDTH = 3; // the width of the create button
- private const int IN_GAME_FORM_LEAVE_BUTTON_WIDTH = 3; // the width of the leave button
- private const int IN_GAME_FORM_LEAVE_BUTTON_HEIGHT = 10; // the height of the leave button
- private const int IN_GAME_FORM_ANSWER_BUTTON_HEIGHT = 8; // the height of the answers buttons
- private const int IN_GAME_FORM_ANSWER_BUTTON_WIDTH = 3; // the width of the answer buttons
- //private static int yAxisSpace; // the space remains after the alligment is substracted in y axis
- //private static int xAxisSpace; // the space remains after the alligment is substracted in x axis
- private MyPictureBox PBClose; // the close button, <> needs to be disposed
- private Thread t; // Thread to handle messages from the server
- private Stream stream; // creates a connection with the server by ip and port
- private int alligmentFromSubjectY; // the alligment in y axis from the subject
- private string uid; // the username of the signed in user
- private string roomName; // the name of the room the user is currently at
- private List<string> roomProperties; // the properties of the room the user is currently at
- private List<string> roomsID; // all the rooms id which the user can connect them
- private UITimer gameTimer; // the time for the current question
- private string buttonAnswer;
- private string questionTime; // the time a client has to answer a question
- private string maxQuestion; // the question the current games has
- public Form1()
- {
- InitializeComponent();
- this.Width = Screen.PrimaryScreen.Bounds.Width;
- this.Height = Screen.PrimaryScreen.Bounds.Height;
- InitStaticVars();
- //InitGameScreen(null, EventArgs.Empty);
- //changeQuestion(new List<string> { "WHO IS Dolev", "Retard", "0", "IDIOT", "hmor" });
- //InitCreateRoom(null, EventArgs.Empty);
- //InitInsideRoom(null, EventArgs.Empty);
- //ChangeLabels(new List<string> { "4", "5" });
- //ChangeLBpart(new List<string> { "tal", "dolev" });
- //InitPersonalStatus(null, EventArgs.Empty);
- //ChangePersonalStatus(new string[4] { "4", "10", "5", "3" });
- InitLoginScreen(null, EventArgs.Empty);
- //InitSignUp(null, EventArgs.Empty);
- //InitMainScreen(null, EventArgs.Empty);
- //InitBestScores(null, EventArgs.Empty);
- //KeyValuePair<string, string>[] arr = new KeyValuePair<string, string>[3];
- //arr[0] = new KeyValuePair<string, string>("tal", "100");
- //arr[1] = new KeyValuePair<string, string>("Dolev", "0");
- //arr[2] = new KeyValuePair<string, string>("yarin", "10");
- //changeBestScores(arr);
- //CleanAllControlers();
- }
- /// <summary>
- /// initializes all static variables of custom classes, and current class
- /// </summary>
- public void InitStaticVars()
- {
- this.roomsID = new List<string>();
- this.roomProperties = new List<string>();
- this.stream = new Stream("127.0.0.1", 8686);
- t = new Thread(handleMessage);
- t.Start();
- gameTimer = new UITimer();
- // MyTxtBox Class:
- // the default width of the text box
- MyTxtBox._width = (this.Width / LOG_IN_FORM_TXT_X_SIZE);
- // current class:
- // sets the close button
- PBClose = new MyPictureBox("PBClose", "close", new Size(this.Width / CLOSE_GAME_BUTTON_WIDTH, this.Height / CLOSE_GAME_BUTTON_HEIGHT));
- PBClose.Location = new Point(this.Width / 2 - PBClose.Width / 2, this.Height - PBClose.Height - this.Height / ALLIGMENT_FROM_TOP);
- PBClose.Click += PBClose_Click;
- this.Controls.Add(PBClose);
- // sets the alligment from top of screen
- alligmentFromSubjectY = this.Height / ALLIGMENT_FROM_TOP;
- uid = "tal";
- }
- /// <summary>
- /// makes the login is screen
- /// </summary>
- public void InitLoginScreen(object sender, EventArgs args)
- {
- int reminingY = this.Height;
- int nextYPos = 0;
- int xOfTextBoxes = 0;
- int sizeOfPictureBox = 0;
- int alligmentFromPictureBox = 0;
- int alligmentFromTextBoxes = 0;
- int alligmentFromTextBoxesToLabels = this.Width / LOG_IN_FORM_ALLGIMENT_FROM_TEXT_TO_LABEL;
- int xOfPicBoxes = 0;
- List<Control> cont = new List<Control>();
- // sets the background of the page
- this.BackgroundImage = Client.Properties.Resources.loginBG;
- // sets the color of the letters
- this.ForeColor = Color.White;
- // sets the subject label
- Label LBLSubject = new MyLabel("Please Log In", "LBLSubject"); // i create a label to know the width of its text
- LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
- cont.Add(LBLSubject);
- nextYPos = LBLSubject.Location.Y + alligmentFromSubjectY + LBLSubject.Height; // begining of details section
- reminingY -= nextYPos; // sets the space of details section
- // sets the text box of username
- TextBox TXTuserName = new MyTxtBox("TXTusername"); // i create a label to know the height of its font
- alligmentFromTextBoxes = ((reminingY / LOG_IN_FORM_TEXT_SECTOR_HEIGHT) - (TXTuserName.Height * 2)) / 3; // generates the needed alligment
- nextYPos += alligmentFromTextBoxes;
- reminingY -= reminingY / LOG_IN_FORM_TEXT_SECTOR_HEIGHT; // sets the space of buttons section
- TXTuserName.Location = new Point((this.Width / 2) - (TXTuserName.Width / 2), nextYPos);
- cont.Add(TXTuserName);
- // sets the label of username
- Label LBLusername = new MyLabel("UserName: ", "LBLusername"); // sets the label of the userName
- LBLusername.Location = new Point(TXTuserName.Location.X - LBLusername.Width - alligmentFromTextBoxesToLabels, nextYPos);
- cont.Add(LBLusername);
- nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the position of the next textBox
- xOfTextBoxes = TXTuserName.Location.X;
- // sets the text box of password
- TextBox TXTpsw = new MyTxtBox(new Point(xOfTextBoxes, nextYPos), "TXTpsw");
- cont.Add(TXTpsw);
- // sets the label of password
- Label LBLpsw = new MyLabel("password: ", "LBLpsw"); // sets the password label
- LBLpsw.Location = new Point(xOfTextBoxes - LBLpsw.Width - alligmentFromTextBoxesToLabels, nextYPos);
- cont.Add(LBLpsw);
- nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the begining of the buttons sector
- // sets the buttons section
- sizeOfPictureBox = reminingY / LOG_IN_FORM_PICBOX_HEIGHT;
- reminingY -= (sizeOfPictureBox * 2);
- alligmentFromPictureBox = reminingY / 2;
- // sets the sign in button
- PictureBox PBSignIn = new MyPictureBox("PBSignIn", "SignIn", new Size(TXTuserName.Width, sizeOfPictureBox));
- xOfPicBoxes = (this.Width / 2) - (PBSignIn.Width / 2); // sets the x of picture boxes
- PBSignIn.Location = new Point(xOfPicBoxes, nextYPos);
- PBSignIn.Click += (EventHandler)PBSign_In_Click;
- cont.Add(PBSignIn);
- nextYPos += alligmentFromPictureBox;
- // sets the signup button
- PictureBox PBSignUp = new MyPictureBox("PBSignUp", "SignUp", new Size(PBSignIn.Width, sizeOfPictureBox));
- PBSignUp.Location = new Point(xOfPicBoxes, nextYPos);
- PBSignUp.Click += (EventHandler)(CleanAllControlers);
- PBSignUp.Click += (EventHandler)InitSignUp;
- cont.Add(PBSignUp);
- this.Controls.AddRange(cont.ToArray());
- }
- /// <summary>
- /// sets the form to be sign up page
- /// </summary>
- public void InitSignUp(object sender, EventArgs args)
- {
- int reminingY = this.Height;
- int nextYPos = 0;
- int xOfTextBoxes = 0;
- int sizeOfPictureBox = 0;
- int alligmentFromPictureBox = 0;
- int alligmentFromTextBoxes = 0;
- int alligmentFromTextBoxesToLabels = this.Width / LOG_IN_FORM_ALLGIMENT_FROM_TEXT_TO_LABEL;
- int xOfPicBoxes = 0;
- List<Control> cont = new List<Control>();
- // sets the background
- this.BackgroundImage = Properties.Resources.signUpBG;
- // sets the color of the letters
- this.ForeColor = Color.Black;
- // sets the subject label
- Label LBLSubject = new MyLabel("Please Sign Up", "LBLSubject"); // i create a label to know the width of its text
- LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
- cont.Add(LBLSubject);
- nextYPos = LBLSubject.Location.Y + alligmentFromSubjectY + LBLSubject.Height; // begining of details section
- reminingY -= nextYPos; // sets the space of details section
- // sets the text box of username
- TextBox TXTuserName = new MyTxtBox("TXTusername"); // i create a label to know the height of its font
- alligmentFromTextBoxes = ((reminingY / LOG_IN_FORM_TEXT_SECTOR_HEIGHT) - (TXTuserName.Height * 3)) / 4; // generates the needed alligment
- nextYPos += alligmentFromTextBoxes;
- reminingY -= reminingY / LOG_IN_FORM_TEXT_SECTOR_HEIGHT; // sets the space of buttons section
- TXTuserName.Location = new Point((this.Width / 2) - (TXTuserName.Width / 2), nextYPos);
- cont.Add(TXTuserName);
- // sets the label of username
- Label LBLusername = new MyLabel("UserName: ", "LBLusername"); // sets the label of the userName
- LBLusername.Location = new Point(TXTuserName.Location.X - LBLusername.Width - alligmentFromTextBoxesToLabels, nextYPos);
- cont.Add(LBLusername);
- nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the position of the next textBox
- xOfTextBoxes = TXTuserName.Location.X;
- // sets the text box of password
- TextBox TXTpsw = new MyTxtBox(new Point(xOfTextBoxes, nextYPos), "TXTpsw");
- cont.Add(TXTpsw);
- // sets the label of password
- Label LBLpsw = new MyLabel("password: ", "LBLpsw"); // sets the password label
- LBLpsw.Location = new Point(xOfTextBoxes - LBLpsw.Width - alligmentFromTextBoxesToLabels, nextYPos);
- cont.Add(LBLpsw);
- nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the position of the next textBox
- // sets the text box of email
- TextBox TXTemail = new MyTxtBox(new Point(xOfTextBoxes, nextYPos), "TXTemail");
- cont.Add(TXTemail);
- // sets the label of email
- Label LBLemail = new MyLabel("email: ", "LBLemail");
- LBLemail.Location = new Point(xOfTextBoxes - LBLemail.Width - alligmentFromTextBoxesToLabels, nextYPos);
- cont.Add(LBLemail);
- nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the begining of the buttons sector
- // sets the buttons section
- sizeOfPictureBox = reminingY / LOG_IN_FORM_PICBOX_HEIGHT;
- reminingY -= (sizeOfPictureBox * 2);
- alligmentFromPictureBox = reminingY / 2;
- // sets the sign up button
- PictureBox PBSignUp = new MyPictureBox("PBSignUp", "SignUp", new Size(TXTemail.Width, sizeOfPictureBox));
- xOfPicBoxes = (this.Width / 2) - (PBSignUp.Width / 2); // sets the x of picture boxes
- PBSignUp.Location = new Point(xOfPicBoxes, nextYPos);
- PBSignUp.Click += (EventHandler)PBSign_Up_Click;
- //PBSignUp.Click += (EventHandler)CleanAllControlers;
- cont.Add(PBSignUp);
- // sets the back button
- int PCHeight = this.Height / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- int PCWidth = this.Width / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- PictureBox PBBack = new MyPictureBox("PBBack", "back", new Size(PCWidth, PCHeight));
- PBBack.Location = new Point(this.Width - PCWidth, this.Height / ALLIGMENT_FROM_TOP);
- PBBack.Click += (EventHandler)CleanAllControlers;
- PBBack.Click += (EventHandler)InitLoginScreen;
- cont.Add(PBBack);
- this.Controls.AddRange(cont.ToArray());
- }
- /// <summary>
- /// builds the main screen
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="args"></param>
- public void InitMainScreen(object sender, EventArgs args)
- {
- int nextYPos = 0;
- int reminingY = PBClose.Location.Y;
- int heightOfPB = this.Height / MAIN_FORM_PICBOX_HEIGHT;
- int widthOfPB = this.Width / MAIN_FORM_PICBOX_WIDTH;
- int alligmentFromButtonsY = 0;
- int alligmentFromButtonsX = 0;
- // sets the background of the screen
- this.BackgroundImage = Properties.Resources.mainScreenBG;
- // sets the font color to black
- this.ForeColor = Color.Black;
- // sets the subject label
- Label LBLSubject = new MyLabel("Hello " + uid, "LBLSubject"); // i create a label to know the width of its text
- LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
- this.Controls.Add(LBLSubject);
- // configures all the propeties needed for the button
- nextYPos = LBLSubject.Location.Y + alligmentFromSubjectY;
- reminingY -= (nextYPos - heightOfPB * 2);
- alligmentFromButtonsY = reminingY / 3;
- nextYPos += (alligmentFromButtonsY / 2);
- alligmentFromButtonsX = (this.Width - widthOfPB * 3) / 3;
- // sets the Join room button
- Button BTNJoin = new MyButton("BTNJoin", new Size(widthOfPB, heightOfPB), "Join Room");
- BTNJoin.Location = new Point(alligmentFromButtonsX, nextYPos);
- BTNJoin.Click += (EventHandler)CleanAllControlers;
- BTNJoin.Click += (EventHandler)InitJoinRoom;
- BTNJoin.Click += (EventHandler)BTNJoin_Click;
- this.Controls.Add(BTNJoin);
- // sets the Create room button
- Button BTNCreate = new MyButton("BTNCreate", new Size(widthOfPB, heightOfPB), "Create Room");
- BTNCreate.Location = new Point(this.Width - widthOfPB - alligmentFromButtonsX, nextYPos);
- BTNCreate.Click += (EventHandler)CleanAllControlers;
- BTNCreate.Click += (EventHandler)InitCreateRoom;
- this.Controls.Add(BTNCreate);
- nextYPos += alligmentFromButtonsY;
- // sets the best scores button
- Button BTNBest = new MyButton("BTNBest", new Size(widthOfPB, heightOfPB), "Best Scores");
- BTNBest.Location = new Point(alligmentFromButtonsX, nextYPos);
- BTNBest.Click += (EventHandler)CleanAllControlers;
- BTNBest.Click += (EventHandler)InitBestScores;
- BTNBest.Click += (EventHandler)BTNBest_Click;
- this.Controls.Add(BTNBest);
- // sets the personal status
- Button BTNPersonal = new MyButton("BTNPersonal", new Size(widthOfPB, heightOfPB), "My Status");
- BTNPersonal.Location = new Point(this.Width - widthOfPB - alligmentFromButtonsX, nextYPos);
- BTNPersonal.Click += (EventHandler)CleanAllControlers;
- BTNPersonal.Click += (EventHandler)InitPersonalStatus;
- BTNPersonal.Click += (EventHandler)BTNPersonal_Click;
- this.Controls.Add(BTNPersonal);
- // sets the logout button
- PictureBox PBLogOut = new MyPictureBox("PBLogOut", "signOut", new Size(this.Height / MAIN_FORM_LOG_OUT_WIDTH, this.Width / MAIN_FORM_LOG_OUT_HEIGHT));
- PBLogOut.Location = new Point(this.Width / ALLIGMENT_FROM_LEFT, this.Height / ALLIGMENT_FROM_TOP);
- PBLogOut.Click += (EventHandler)CleanAllControlers;
- PBLogOut.Click += (EventHandler)InitLoginScreen;
- PBLogOut.Click += (EventHandler)PBLogOut_Click;
- this.Controls.Add(PBLogOut);
- }
- /// <summary>
- /// inits the join room screen
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="args"></param>
- private void InitJoinRoom(object sender, EventArgs args)
- {
- int nextYPos = 0;
- int alligmentFromClose = this.Height - this.PBClose.Location.Y - this.PBClose.Height;
- int alligmentFromButtonsY = 0;
- int alligmentFromButtonsX = 0;
- int buttonSectorY = 0;
- int alligmentFromListsX = 0;
- int refreshY = 0;
- int joinY = 0;
- int reminingY = this.PBClose.Location.Y;
- // sets the form to join room bg
- this.BackgroundImage = Properties.Resources.joinRoomBG;
- // changes the fore color to black
- this.ForeColor = Color.Black;
- // sets the subject label
- Label LBLSubject = new MyLabel("Choose Room", "LBLSubject"); // i create a label to know the width of its text
- LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
- this.Controls.Add(LBLSubject);
- nextYPos = LBLSubject.Location.Y + LBLSubject.Height + alligmentFromSubjectY;
- reminingY -= nextYPos;
- // configures the button sector properties
- buttonSectorY = reminingY / JOIN_ROOM_FORM_BUTTON_SECTOR_Y;
- refreshY = buttonSectorY / JOIN_ROOM_FORM_REFRESH_HEIGHT;
- joinY = buttonSectorY / JOIN_ROOM_FORM_JOIN_HEIGHT;
- alligmentFromButtonsY = (buttonSectorY - refreshY - joinY) / 2;
- alligmentFromButtonsX = (this.Width - this.Width / JOIN_ROOM_FORM_REFRESH_WIDTH - this.Width / JOIN_ROOM_FORM_JOIN_WIDTH) / 3;
- // configures and adds the refresh button
- PictureBox PBRefresh = new MyPictureBox("PBRefresh", "refresh", new Size(this.Width / JOIN_ROOM_FORM_REFRESH_WIDTH, refreshY));
- PBRefresh.Location = new Point(alligmentFromButtonsX, PBClose.Location.Y - alligmentFromButtonsY - refreshY);
- PBRefresh.Click += (EventHandler)PBRefresh_Click;
- this.Controls.Add(PBRefresh);
- // configures and adds the join button
- PictureBox PBJoin = new MyPictureBox("PBJoin", "joinBTN", new Size(this.Width / JOIN_ROOM_FORM_JOIN_WIDTH, this.Height / JOIN_ROOM_FORM_JOIN_HEIGHT));
- PBJoin.Location = new Point(this.Width - PBJoin.Width - alligmentFromButtonsX, PBRefresh.Location.Y);
- PBJoin.Click += (EventHandler)PBJoin_Click;
- //PBJoin.Click += (EventHandler)CleanAllControlers;
- //PBJoin.Click += (EventHandler)InitInsideRoom;
- this.Controls.Add(PBJoin);
- reminingY = PBRefresh.Location.Y - LBLSubject.Location.Y - LBLSubject.Height - alligmentFromSubjectY;
- ListBox LBRooms = new MyListBox("LBRooms", new Size(this.Width / JOIN_ROOM_FORM_ROOMS_LB_WIDTH, reminingY / 4));
- ListBox LBUsers = new MyListBox("LBUsers", new Size(this.Width / JOIN_ROOM_FORM_USERS_LB_WIDTH, reminingY / 4));
- alligmentFromListsX = (this.Width - LBRooms.Width - LBUsers.Width) / 3;
- Label LBLRooms = new MyLabel("Rooms:", "LBLRooms");
- Label LBLUsers = new MyLabel("Users:", "LBLUsers");
- // adds the rooms list box
- LBRooms.Location = new Point(this.Width / 2 - LBRooms.Width / 2, nextYPos + LBLRooms.Height);
- LBRooms.SelectedIndexChanged += (EventHandler)LBRooms_SelectedIndexChanged;
- this.Controls.Add(LBRooms);
- // sets the users list box
- LBUsers.Location = new Point(alligmentFromListsX, nextYPos + LBLUsers.Height);
- LBUsers.Visible = false;
- this.Controls.Add((LBUsers));
- // configures and adds the label of rooms
- LBLRooms.Location = new Point(LBRooms.Location.X + LBRooms.Width / 2 - LBLRooms.Width / 2, nextYPos);
- this.Controls.Add(LBLRooms);
- // configures and adds the label of users
- LBLUsers.Location = new Point(LBUsers.Location.X + LBUsers.Width / 2 - LBLRooms.Width / 2, nextYPos);
- LBLUsers.Visible = false;
- this.Controls.Add(LBLUsers);
- // sets the back button
- int PCHeight = this.Height / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- int PCWidth = this.Width / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- PictureBox PBBack = new MyPictureBox("PBBack", "back", new Size(PCWidth, PCHeight));
- PBBack.Location = new Point(this.Width - PCWidth, this.Height / ALLIGMENT_FROM_TOP);
- PBBack.Click += (EventHandler)CleanAllControlers;
- PBBack.Click += (EventHandler)InitMainScreen;
- this.Controls.Add(PBBack);
- }
- /// <summary>
- /// changes the room list in the join room form
- /// should be called when the join room button or refresh button were clicked
- /// </summary>
- /// <param name="roomsNames">the names of the rooms that will be shown on the list box</param>
- private void changeRoomsList(List<string> roomsNames)
- {
- if (roomsNames.Count < 1) // so that the list will still be shown even if there are no available rooms
- {
- roomsNames.Add("");
- roomsID.Add("-1"); // so the user cant join this fake room
- }
- ListBox LBUsers = this.Controls.Find("LBUsers", false).FirstOrDefault() as ListBox;
- Label LBLUsers = this.Controls.Find("LBLUsers", false).FirstOrDefault() as Label;
- // makes the users lists to disapear
- LBUsers.Visible = false;
- LBLUsers.Visible = false;
- ListBox LBRooms = this.Controls.Find("LBRooms", false).FirstOrDefault() as ListBox;
- if (LBRooms != null)
- {
- LBRooms.Items.Clear();
- foreach (string name in roomsNames)
- {
- LBRooms.Items.Add(name);
- }
- Label LBLRooms = this.Controls.Find("LBLRooms", false).FirstOrDefault() as Label;
- PictureBox PBRefresh = this.Controls.Find("PBRefresh", false).FirstOrDefault() as PictureBox;
- // sets the height of the list box
- if (LBLRooms != null && PBRefresh != null)
- {
- int maxHeight = PBRefresh.Location.Y - LBLRooms.Location.Y - LBLRooms.Height - alligmentFromSubjectY;
- int height = LBRooms.ItemHeight;
- int maxObj = maxHeight / height;
- LBRooms.Height = roomsNames.Count > maxObj ? height * maxObj : roomsNames.Count * height;
- }
- // moves the list box to its proper place
- LBRooms.Location = new Point(this.Width / 2 - LBRooms.Width / 2, LBRooms.Location.Y);
- LBLRooms.Location = new Point(LBRooms.Location.X + LBRooms.Width / 2 - LBLRooms.Width / 2, LBLRooms.Location.Y);
- this.Update();
- }
- }
- /// <summary>
- /// changes the users in room list box
- /// should be called when an item on the rooms list is clicked
- /// </summary>
- /// <param name="users">the users that will be presented on the users list</param>
- private void changeUsersInRoom(List<string> users)
- {
- if (users.Count < 1)
- {
- users.Add("");
- }
- ListBox LBUsers = this.Controls.Find("LBUsers", false).FirstOrDefault() as ListBox;
- Label LBLUsers = this.Controls.Find("LBLUsers", false).FirstOrDefault() as Label;
- Label LBLRooms = this.Controls.Find("LBLRooms", false).FirstOrDefault() as Label;
- PictureBox PBRefresh = this.Controls.Find("PBRefresh", false).FirstOrDefault() as PictureBox;
- ListBox LBRooms = this.Controls.Find("LBRooms", false).FirstOrDefault() as ListBox;
- // sets the height of the list box
- if (LBLUsers != null && PBRefresh != null && LBUsers != null)
- {
- int maxHeight = PBRefresh.Location.Y - LBLUsers.Location.Y - LBLUsers.Height - alligmentFromSubjectY;
- int height = LBUsers.ItemHeight;
- int maxObj = maxHeight / height;
- // changes the items in the list box
- LBUsers.Items.Clear();
- foreach (string user in users)
- {
- LBUsers.Items.Add(user);
- }
- LBUsers.Height = users.Count > maxObj ? height * maxObj : users.Count * height;
- // sets the rooms stuff to their proper place
- LBRooms.Location = new Point(this.Width - LBRooms.Width - LBUsers.Location.X, LBRooms.Location.Y);
- LBLRooms.Location = new Point(LBRooms.Location.X + LBRooms.Width / 2 - LBLRooms.Width / 2, LBLRooms.Location.Y);
- LBUsers.Visible = true;
- LBLUsers.Visible = true;
- }
- }
- private void InitCreateRoom(object sender, EventArgs args)
- {
- int alligmentFromCloseButton = this.Height - this.PBClose.Location.Y - this.PBClose.Height;
- int nextYPos = 0;
- int buttonHeight = this.Height / CREATE_ROOM_FORM_BUTTON_HEIGHT;
- int buttonWidth = this.Width / CREATE_ROOM_FORM_BUTTON_WIDTH;
- int reminingY = 0;
- int alligmentFromTextBoxes = 0;
- this.BackgroundImage = Properties.Resources.createRoom;
- this.ForeColor = Color.Black;
- // sets the subject label
- Label LBLSubject = new MyLabel("Create New Room:", "LBLSubject"); // i create a label to know the width of its text
- LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
- this.Controls.Add(LBLSubject);
- // configures and adds the create room button
- Button BTNCreateRoom = new MyButton("BTNCreateRoom", new Size(buttonWidth, buttonHeight), "Create");
- BTNCreateRoom.Location = new Point(this.Width / 2 - buttonWidth / 2, this.PBClose.Location.Y - alligmentFromCloseButton - buttonHeight);
- BTNCreateRoom.Click += (EventHandler)BTNCreateRoom_Click;
- this.Controls.Add(BTNCreateRoom);
- // sets all the required properties for textbox sector
- nextYPos = LBLSubject.Location.Y + alligmentFromSubjectY + LBLSubject.Height;
- reminingY = BTNCreateRoom.Location.Y - nextYPos;
- TextBox TXTRoomName = new MyTxtBox("TXTRoomName"); // i create a text box so i can know its height and width
- alligmentFromTextBoxes = (reminingY - TXTRoomName.Height * 4) / 4 + TXTRoomName.Height;
- // configures and adds the room name textbox
- TXTRoomName.Location = new Point(this.Width / 2 - TXTRoomName.Width / 2, nextYPos);
- this.Controls.Add(TXTRoomName);
- // configures and adds the room name label
- Label LBLRoomName = new MyLabel("Room Name: ", "LBLRoomName");
- LBLRoomName.Location = new Point(TXTRoomName.Location.X - LBLRoomName.Width, nextYPos);
- this.Controls.Add(LBLRoomName);
- nextYPos += alligmentFromTextBoxes;
- // configures and adds the number of players text box
- TextBox TXTNumOfPlayers = new MyTxtBox(new Point(TXTRoomName.Location.X, nextYPos), "TXTNumOfPlayers");
- this.Controls.Add(TXTNumOfPlayers);
- // configures and adds the number of players label
- Label LBLNumOfPlayers = new MyLabel("Number of players: ", "LBLNumOfPlayers");
- LBLNumOfPlayers.Location = new Point(TXTNumOfPlayers.Location.X - LBLNumOfPlayers.Width, nextYPos);
- this.Controls.Add(LBLNumOfPlayers);
- nextYPos += alligmentFromTextBoxes;
- // configures and adds the number of questions text box
- TextBox TXTNumOfQuestions = new MyTxtBox(new Point(TXTRoomName.Location.X, nextYPos), "TXTNumOfQuestions");
- this.Controls.Add(TXTNumOfQuestions);
- // configures and adds the number of question label
- Label LBLNumOfQuestions = new MyLabel("Number of questions: ", "LBLNumOfQuestions");
- LBLNumOfQuestions.Location = new Point(TXTNumOfQuestions.Location.X - LBLNumOfQuestions.Width, nextYPos);
- this.Controls.Add(LBLNumOfQuestions);
- nextYPos += alligmentFromTextBoxes;
- // configures and adds the number of questions text box
- TextBox TXTTimePerAns = new MyTxtBox(new Point(TXTRoomName.Location.X, nextYPos), "TXTTimePerAns");
- this.Controls.Add(TXTTimePerAns);
- // configures and adds the time per answer label
- Label LBLTimePerAns = new MyLabel("Time Per answer: ", "LBLTimePerAns");
- LBLTimePerAns.Location = new Point(TXTTimePerAns.Location.X - LBLTimePerAns.Width, nextYPos);
- this.Controls.Add(LBLTimePerAns);
- // sets the back button
- int PCHeight = this.Height / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- int PCWidth = this.Width / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- PictureBox PBBack = new MyPictureBox("PBBack", "back", new Size(PCWidth, PCHeight));
- PBBack.Location = new Point(this.Width - PCWidth, this.Height / ALLIGMENT_FROM_TOP);
- PBBack.Click += (EventHandler)CleanAllControlers;
- PBBack.Click += (EventHandler)InitMainScreen;
- this.Controls.Add(PBBack);
- }
- /// <summary>
- /// changes the form to inside room performance
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="args"></param>
- private void InitInsideRoom(object sender, EventArgs args)
- {
- int reminingY = this.Height;
- int nextYPos = 0;
- int buttonSectorY = 0;
- int buttonsHeight = this.Height / IN_ROOM_FORM_BUTTON_HEIGHT;
- int buttonWidth = this.Width / IN_ROOM_FORM_BUTTON_WIDTH;
- int alligmentFromButtonsY = 0;
- int alligmentFromLabelsY = 0;
- List<Label> labels = new List<Label>();
- // sets the background to be inside room background
- this.BackgroundImage = Properties.Resources.inRoom;
- // sets the font color to black
- this.ForeColor = Color.Black;
- this.PBClose.Visible = false;
- // sets the subject label
- Label LBLSubject = new MyLabel("You are in " + this.roomName + " room", "LBLSubject"); // i create a label to know the width of its text
- LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
- this.Controls.Add(LBLSubject);
- nextYPos = LBLSubject.Location.Y + LBLSubject.Height + alligmentFromSubjectY;
- reminingY -= nextYPos;
- buttonSectorY = reminingY / IN_ROOM_FORM_BUTTON_SECTOR_Y;
- reminingY -= buttonSectorY;
- alligmentFromButtonsY = (buttonSectorY - buttonsHeight) / 2;
- if (sender is PictureBox) // in case its a user presentation
- {
- Button BTNLeave = new MyButton("BTNLeave", new Size(buttonWidth, buttonsHeight), "Leave Room");
- BTNLeave.Location = new Point(this.Width / 2 - buttonWidth / 2, this.Height - buttonsHeight - alligmentFromButtonsY);
- BTNLeave.Click += (EventHandler)BTNLeave_Click;
- this.Controls.Add(BTNLeave);
- }
- else if (sender is Button) // in case its admin presentation
- {
- int alligmentFromButtonsX = (this.Width - buttonWidth * 2) / 3;
- // configures and adds the close room button
- Button BTNCloseRoom = new MyButton("BTNCloseRoom", new Size(buttonWidth, buttonsHeight), "Close Room");
- BTNCloseRoom.Location = new Point(alligmentFromButtonsX, this.Height - BTNCloseRoom.Height - alligmentFromButtonsY);
- BTNCloseRoom.Click += (EventHandler)BTNCloseRoom_Click;
- this.Controls.Add(BTNCloseRoom);
- // configures and adds the start game button
- Button BTNStartGame = new MyButton("BTNStartGame", new Size(buttonWidth, buttonsHeight), "Start Game");
- BTNStartGame.Location = new Point(this.Width - buttonWidth - alligmentFromButtonsX, BTNCloseRoom.Location.Y);
- BTNStartGame.Click += (EventHandler)BTNStartGame_Click;
- this.Controls.Add(BTNStartGame);
- labels.Add(new MyLabel("Max number of users: ", "LBLMaxUsers"));
- }
- Label LBLparticipates = new MyLabel("current participates are: ", "LBLparticipates");
- // configures and adds the participates list box
- ListBox LBpart = new MyListBox("LBpart", new Size(this.Width / IN_ROOM_FORM_LB_WIDTH, reminingY / 4));
- LBpart.Location = new Point(this.Width / 2 - LBpart.Width / 2, nextYPos + LBLparticipates.Height);
- this.Controls.Add(LBpart);
- // configures and adds the label of participates
- LBLparticipates.Location = new Point(LBpart.Location.X + LBpart.Width / 2 - LBLparticipates.Width / 2, nextYPos);
- this.Controls.Add(LBLparticipates);
- // sets the room properties labels
- labels.Add(new MyLabel("Number of questions: ", "LBLNumOfQuestions"));
- labels.Add(new MyLabel("Time per question: ", "LBLTimePerQuestion"));
- // calculates the needed alligment
- alligmentFromLabelsY = (reminingY - labels[0].Height * labels.Count) / (labels.Count + 1);
- nextYPos += alligmentFromLabelsY;
- foreach (Label l in labels)
- {
- l.Location = new Point(0, nextYPos);
- nextYPos += alligmentFromLabelsY;
- this.Controls.Add(l);
- }
- }
- /// <summary>
- /// changes the list box of participates
- /// </summary>
- /// <param name="users">the users to be added to the list box</param>
- private void ChangeLBpart(List<string> users)
- {
- Label LBLparticipates = this.Controls.Find("LBLparticipates", false).FirstOrDefault() as Label;
- ListBox LBpart = this.Controls.Find("LBpart", false).FirstOrDefault() as ListBox;
- if (users.Count < 1)
- {
- users.Add("");
- }
- if (LBLparticipates != null && LBpart != null)
- {
- int maxHeight = this.Height - this.Height / IN_ROOM_FORM_BUTTON_SECTOR_Y - LBLparticipates.Location.Y - LBLparticipates.Height;
- int height = LBpart.ItemHeight;
- int maxObj = maxHeight / height;
- // changes the height of the list box according to the items in it
- LBpart.Height = users.Count > maxObj ? height * maxObj : height * users.Count;
- LBpart.Items.Clear();
- foreach (string user in users)
- {
- LBpart.Items.Add(user);
- }
- }
- }
- /// <summary>
- /// changes the labels of in room properties
- /// in case of user presentation the properties param should be made out of the string the server sent
- /// in case of admin presentation the properties param should be the global parameter roomProperties
- /// </summary>
- /// <param name="properties">the properties that would be in the labels, the order should be maxusers(if exists), numberOfQuestions, time per questions</param>
- private void ChangeLabels(List<string> properties)
- {
- Label[] labels = new Label[properties.Count];
- if (properties.Count > 2)
- {
- labels[0] = this.Controls.Find("LBLMaxUsers", false).FirstOrDefault() as Label;
- }
- labels[labels.Length - 2] = this.Controls.Find("LBLNumOfQuestions", false).FirstOrDefault() as Label;
- labels[labels.Length - 1] = this.Controls.Find("LBLTimePerQuestion", false).FirstOrDefault() as Label;
- MessageBox.Show("[1] = " + labels[labels.Length - 1].Text + "\n[2] = " + labels[labels.Length - 2].Text);
- this.questionTime = int.Parse(properties[properties.Count - 1]).ToString();
- this.maxQuestion = int.Parse(properties[properties.Count - 2]).ToString();
- for (int i = 0; i < labels.Length; i++)
- {
- if (labels[i] != null)
- {
- labels[i].Text += (int.Parse(properties[i]).ToString());
- labels[i].Width = TextRenderer.MeasureText(labels[i].Text, labels[i].Font).Width;
- }
- }
- }
- private void InitGameScreen(object sender, EventArgs args)
- {
- int nextYPos = 0;
- int reminingY = 0;
- int alligmentFromButtonsY = 0;
- int alligmentFromButtonsX = 0;
- int buttonHeight = this.Height / IN_GAME_FORM_ANSWER_BUTTON_HEIGHT;
- int buttonWidth = this.Width / IN_GAME_FORM_ANSWER_BUTTON_WIDTH;
- this.PBClose.Visible = false;
- this.BackgroundImage = Properties.Resources.gameBG;
- this.ForeColor = Color.Black;
- // sets the subject label
- Label LBLSubject = new MyLabel("You are in game", "LBLSubject"); // i create a label to know the width of its text
- LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
- this.Controls.Add(LBLSubject);
- // configures and sets a new button
- Button BTNLeaveGame = new MyButton("BTNLeaveGame", new Size(this.Width / IN_GAME_FORM_LEAVE_BUTTON_WIDTH, this.Height / IN_GAME_FORM_LEAVE_BUTTON_HEIGHT), "Leave Game");
- BTNLeaveGame.Location = new Point(this.Width / 2 - BTNLeaveGame.Width / 2, this.Height - BTNLeaveGame.Height - this.Height / ALLIGMENT_FROM_TOP);
- BTNLeaveGame.Click += BTNLeaveGame_Click;
- this.Controls.Add(BTNLeaveGame);
- nextYPos = LBLSubject.Location.Y + LBLSubject.Height + alligmentFromSubjectY;
- reminingY = BTNLeaveGame.Location.Y;
- // configures and sets the question label
- Label LBLQuestion = new MyLabel("Question", "LBLQuestion");
- LBLQuestion.Location = new Point(0, nextYPos);
- this.Controls.Add(LBLQuestion);
- nextYPos += LBLQuestion.Height;
- reminingY -= nextYPos;
- alligmentFromButtonsY = (reminingY - buttonHeight * 2) / 3;
- alligmentFromButtonsX = (this.Width - buttonWidth * 2) / 3;
- nextYPos += alligmentFromButtonsY;
- // configures and sets the time left label
- Label LBLTime = new MyLabel(this.questionTime, "LBLTime");
- LBLTime.Location = new Point(this.Width / 2 - LBLTime.Width / 2, nextYPos - (nextYPos - LBLQuestion.Location.Y) / 2 - LBLTime.Height / 2);
- this.Controls.Add(LBLTime);
- // configures and adds the first answer button
- Button BTN1st = new MyButton("BTN1st", new Size(buttonWidth, buttonHeight), "");
- BTN1st.Location = new Point(alligmentFromButtonsX, nextYPos);
- BTN1st.Click += BTN1st_Click;
- this.Controls.Add(BTN1st);
- // configures and adds the second answer button
- Button BTN2nd = new MyButton("BTN2nd", new Size(buttonWidth, buttonHeight), "");
- BTN2nd.Location = new Point(this.Width - buttonWidth - alligmentFromButtonsX, nextYPos);
- BTN2nd.Click += BTN2nd_Click;
- this.Controls.Add(BTN2nd);
- nextYPos += BTN2nd.Height + alligmentFromButtonsY;
- // configures and adds the third answer button
- Button BTN3rd = new MyButton("BTN3rd", new Size(buttonWidth, buttonHeight), "");
- BTN3rd.Location = new Point(alligmentFromButtonsX, nextYPos);
- BTN3rd.Click += BTN3rd_Click;
- this.Controls.Add(BTN3rd);
- // configures and adds the fourth answer button
- Button BTN4th = new MyButton("BTN4th", new Size(buttonWidth, buttonHeight), "");
- BTN4th.Location = new Point(BTN2nd.Location.X, nextYPos);
- BTN4th.Click += BTN4th_Click;
- this.Controls.Add(BTN4th);
- // configures and adds the current answer count
- Label LBLCount = new MyLabel("5/6", "LBLCount");
- LBLCount.Location = new Point(this.Width / 2 - LBLCount.Width / 2, nextYPos + alligmentFromButtonsY / 2 - LBLCount.Height / 2 + BTN4th.Height);
- this.Controls.Add(LBLCount);
- gameTimer.Interval = 1000; // 1 sec
- gameTimer.Tick += (EventHandler)delegate
- {
- Label time = this.Controls.Find("LBLTime", false).FirstOrDefault() as Label;
- //MessageBox.Show(time.Text);
- time.Text = ((int.Parse(time.Text) - 1).ToString());
- time.Width = TextRenderer.MeasureText(time.Text, time.Font).Width;
- time.Location = new Point(this.Width / 2 - time.Width / 2, time.Location.Y);
- // in case half of the time passed the background of the time turns to red
- if(int.Parse(time.Text) <= int.Parse(this.questionTime) / 2)
- {
- time.BackColor = Color.Red;
- }
- if (time.Text == "0")
- {
- Button[] buttons = new Button[4];
- buttons[0] = this.Controls.Find("BTN1st", false).FirstOrDefault() as Button;
- buttons[1] = this.Controls.Find("BTN2nd", false).FirstOrDefault() as Button;
- buttons[2] = this.Controls.Find("BTN3rd", false).FirstOrDefault() as Button;
- buttons[3] = this.Controls.Find("BTN4th", false).FirstOrDefault() as Button;
- for (int i = 0; i < 4; i++ )
- {
- buttons[i].BackColor = Color.Red;
- }
- stream.sendData(string.Format("2195{0:00}", this.questionTime));
- gameTimer.Stop(); // the time is up
- }
- };
- }
- /// <summary>
- /// changes the game page to contain a question
- /// </summary>
- /// <param name="lst">a list which contains a question and 4 answers</param>
- private void changeQuestion(List<string> lst)
- {
- Button[] buttons = new Button[4];
- Label LBLQuestion = this.Controls.Find("LBLQuestion", false).FirstOrDefault() as Label;
- Label LBLTime = this.Controls.Find("LBLTime", false).FirstOrDefault() as Label;
- buttons[0] = this.Controls.Find("BTN1st", false).FirstOrDefault() as Button;
- buttons[1] = this.Controls.Find("BTN2nd", false).FirstOrDefault() as Button;
- buttons[2] = this.Controls.Find("BTN3rd", false).FirstOrDefault() as Button;
- buttons[3] = this.Controls.Find("BTN4th", false).FirstOrDefault() as Button;
- if(LBLTime != null)
- {
- LBLTime.BackColor = Color.Transparent;
- }
- if(lst.Count > 4)
- {
- if(LBLQuestion != null)
- {
- LBLQuestion.Text = lst[0];
- LBLQuestion.Width = TextRenderer.MeasureText(LBLQuestion.Text, LBLQuestion.Font).Width;
- LBLQuestion.Location = new Point(this.Width / 2 - LBLQuestion.Width / 2, LBLQuestion.Location.Y);
- }
- for(int i = 1; i < 5; i++)
- {
- buttons[i - 1].Text = lst[i];
- }
- }
- gameTimer.Start();
- }
- /// <summary>
- /// changes the form to personal status
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="args"></param>
- private void InitPersonalStatus(object sender, EventArgs args)
- {
- int reminingY = this.PBClose.Location.Y;
- int nextYPos = 0;
- int alligmentFromLabelsY = 0;
- // sets the background of the form to personal status background
- this.BackgroundImage = Properties.Resources.personalStatusBG;
- // sets the font of the form to black
- this.ForeColor = Color.Black;
- // sets the subject label
- Label LBLSubject = new MyLabel("My Performance: ", "LBLSubject"); // i create a label to know the width of its text
- LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
- this.Controls.Add(LBLSubject);
- nextYPos = LBLSubject.Location.Y + LBLSubject.Height + alligmentFromSubjectY;
- reminingY -= nextYPos;
- Label LBLnumOfGames = new MyLabel("number of Games: ", "LBLnumOfGames"); // i create a label so i can know the height of it
- alligmentFromLabelsY = (reminingY - LBLnumOfGames.Height * 4) / 5;
- nextYPos += alligmentFromLabelsY;
- // configures and adds the number of games label
- LBLnumOfGames.Location = new Point(0, nextYPos); // i put 0 in x of all labels because i change it to the middle when the real text arrives from server
- this.Controls.Add(LBLnumOfGames);
- nextYPos += alligmentFromLabelsY;
- // configures and adds the number of right answers label
- Label LBLnumOfRightAns = new MyLabel("number of right answers: ", "LBLnumOfRightAns");
- LBLnumOfRightAns.Location = new Point(0, nextYPos);
- this.Controls.Add(LBLnumOfRightAns);
- nextYPos += alligmentFromLabelsY;
- // configures and adds the number of wrong answers label
- Label LBLnumOfWrongAns = new MyLabel("number of wrong answers: ", "LBLnumOfWrongAns");
- LBLnumOfWrongAns.Location = new Point(0, nextYPos);
- this.Controls.Add(LBLnumOfWrongAns);
- nextYPos += alligmentFromLabelsY;
- // configures and adds the average time per answer
- Label LBLavgTimePerAns = new MyLabel("average time for answer: ", "LBLavgTimePerAns");
- LBLavgTimePerAns.Location = new Point(0, nextYPos);
- this.Controls.Add(LBLavgTimePerAns);
- // sets the back button
- int PCHeight = this.Height / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- int PCWidth = this.Width / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- PictureBox PBBack = new MyPictureBox("PBBack", "back", new Size(PCWidth, PCHeight));
- PBBack.Location = new Point(this.Width - PCWidth, this.Height / ALLIGMENT_FROM_TOP);
- PBBack.Click += (EventHandler)CleanAllControlers;
- PBBack.Click += (EventHandler)InitMainScreen;
- this.Controls.Add(PBBack);
- }
- /// <summary>
- /// changes the labels of personal status' form, has to be be used after InitPersonalStatus function used
- /// </summary>
- /// <param name="arr">an array that contains the values of the fields example { 4, 5, 10, 3 }</param>
- private void ChangePersonalStatus(string[] arr)
- {
- if (arr.Length > 3)
- {
- Label[] labels = new Label[4];
- labels[0] = this.Controls.Find("LBLnumOfGames", false).FirstOrDefault() as Label;
- labels[1] = this.Controls.Find("LBLnumOfRightAns", false).FirstOrDefault() as Label;
- labels[2] = this.Controls.Find("LBLnumOfWrongAns", false).FirstOrDefault() as Label;
- labels[3] = this.Controls.Find("LBLavgTimePerAns", false).FirstOrDefault() as Label;
- for (int i = 0; i < 4; i++)
- {
- if (labels[i] != null)
- {
- if (i == 3)
- {
- arr[i] = String.Format("{0}.{1}", (int.Parse(arr[i]) / 100).ToString(), (int.Parse(arr[i]) % 100).ToString());
- Invoke((MethodInvoker)(() => labels[i].Text += arr[i]));
- }
- else
- {
- Invoke((MethodInvoker)(() => labels[i].Text += (int.Parse(arr[i])).ToString()));
- }
- Invoke((MethodInvoker)(() => labels[i].Width = TextRenderer.MeasureText(labels[i].Text, labels[i].Font).Width));
- Invoke((MethodInvoker)(() => labels[i].Location = new Point(this.Width / 2 - labels[i].Width / 2, labels[i].Location.Y)));
- }
- }
- }
- }
- /// <summary>
- /// changes the form to show the best scores
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="args"></param>
- private void InitBestScores(object sender, EventArgs args)
- {
- int reminingY = PBClose.Location.Y;
- int nextYPos = 0;
- int pictureBoxHeight = 0;
- int pictureBoxWidth = 0;
- int alligmentFromPicturesY = 0;
- int alligmentFromPictureX = 0;
- // sets the background image to best scores BG
- this.BackgroundImage = Properties.Resources.winners;
- // sets the font of the form to black
- this.ForeColor = Color.Black;
- // sets the subject label
- Label LBLSubject = new MyLabel("Best Scores: ", "LBLSubject"); // i create a label to know the width of its text
- LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
- this.Controls.Add(LBLSubject);
- // creates the label that contains the first player's scores
- Label LBL1st = new MyLabel("ABCD", "LBL1st"); // i put text in the label so i can know its properties
- // sets the next position for the picture boxes sector
- nextYPos += (LBLSubject.Location.Y + LBLSubject.Height + alligmentFromSubjectY);
- reminingY -= nextYPos;
- // configures the properties of the picture boxes
- pictureBoxHeight = reminingY / BEST_SCORES_FORM_PB_HEIGHT;
- pictureBoxWidth = this.Width / BEST_SCORES_FORM_PB_WIDTH;
- // configures the picture box sector
- alligmentFromPicturesY = (reminingY - pictureBoxHeight * 2 - LBL1st.Height * 2) / 2;
- alligmentFromPictureX = (this.Width - pictureBoxWidth * 3) / 4;
- nextYPos += alligmentFromPicturesY;
- // sets the first place picture box
- PictureBox PB1st = new MyPictureBox("PB1st", "_1st", new Size(pictureBoxWidth, pictureBoxHeight));
- PB1st.Location = new Point(alligmentFromPictureX * 2 + pictureBoxWidth, nextYPos);
- this.Controls.Add(PB1st);
- LBL1st.Location = new Point(PB1st.Location.X + PB1st.Width / 2, nextYPos - LBL1st.Height);
- this.Controls.Add(LBL1st);
- // sets the postion to the next picture box
- nextYPos += alligmentFromPicturesY;
- // sets the second best score picture box
- PictureBox PB2nd = new MyPictureBox("PB2nd", "_2nd", new Size(pictureBoxWidth, pictureBoxHeight));
- PB2nd.Location = new Point(alligmentFromPictureX, nextYPos);
- this.Controls.Add(PB2nd);
- // sets the label of the second best score
- Label LBL2nd = new MyLabel("ABCD", "LBL2nd"); // i put text in the label so i can know its properties
- LBL2nd.Location = new Point(PB2nd.Location.X + PB2nd.Width / 2, PB2nd.Location.Y - LBL2nd.Height);
- this.Controls.Add(LBL2nd);
- // sets the picture box of the second best score
- PictureBox PB3rd = new MyPictureBox("PB3rd", "_3rd", new Size(pictureBoxWidth, pictureBoxHeight));
- PB3rd.Location = new Point(this.Width - alligmentFromPictureX - PB3rd.Width, nextYPos);
- this.Controls.Add(PB3rd);
- // sets the label of th ethird best score
- Label LBL3rd = new MyLabel("ABCD", "LBL3rd"); // i put text in the label so i can know its properties
- LBL3rd.Location = new Point(PB3rd.Location.X + PB3rd.Width / 2, nextYPos - LBL3rd.Height);
- this.Controls.Add(LBL3rd);
- // sets the back button
- int PCHeight = this.Height / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- int PCWidth = this.Width / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
- PictureBox PBBack = new MyPictureBox("PBBack", "back", new Size(PCWidth, PCHeight));
- PBBack.Location = new Point(this.Width - PCWidth, this.Height / ALLIGMENT_FROM_TOP);
- PBBack.Click += (EventHandler)CleanAllControlers;
- PBBack.Click += (EventHandler)InitMainScreen;
- this.Controls.Add(PBBack);
- }
- /// <summary>
- /// changes the best scores labels
- /// should be used when clicked on get best scores button, after InitBestScores was called
- /// </summary>
- /// <param name="arr">an array of pairs in which the key is the name of the user and the value is his score</param>
- private void changeBestScores(KeyValuePair<string, string>[] arr)
- {
- Label[] labels = new Label[3];
- labels[0] = this.Controls.Find("LBL1st", false).FirstOrDefault() as Label;
- labels[1] = this.Controls.Find("LBL2nd", false).FirstOrDefault() as Label;
- labels[2] = this.Controls.Find("LBL3rd", false).FirstOrDefault() as Label;
- for (int i = 0; i < 3; i++)
- {
- if (labels[i] != null)
- {
- labels[i].Text = arr[i].Key + ": " + arr[i].Value;
- labels[i].Width = TextRenderer.MeasureText(labels[i].Text, labels[i].Font).Width;
- labels[i].Location = new Point(labels[i].Location.X - labels[i].Width / 2, labels[i].Location.Y);
- }
- }
- }
- /// <summary>
- /// cleans the screen from all the controls on it
- /// </summary>
- private void CleanAllControlers(object sender, EventArgs args)
- {
- //foreach (Control c in this.Controls)
- //{
- // MessageBox.Show(c.GetType().ToString());
- // this.Controls.Remove(c);
- //}
- this.Controls.Clear();
- this.Controls.Add(PBClose);
- }
- private void PBClose_Click(object sender, EventArgs args)
- {
- this.Close();
- }
- private void BTNBest_Click(object sender, EventArgs args)
- {
- stream.sendData("223");
- }
- private void PBLogOut_Click(object sender, EventArgs args)
- {
- stream.sendData("201");
- }
- private void BTNPersonal_Click(object sender, EventArgs args)
- {
- stream.sendData("225");
- }
- private void BTNJoin_Click(object sender, EventArgs args)
- {
- stream.sendData("205");
- }
- private void PBRefresh_Click(object sender, EventArgs args)
- {
- stream.sendData("205");
- }
- private void BTNCreateRoom_Click(object sender, EventArgs args)
- {
- TextBox[] txtBoxes = new TextBox[3];
- TextBox TXTRoomName = this.Controls.Find("TXTRoomName", false).FirstOrDefault() as TextBox;
- txtBoxes[0] = this.Controls.Find("TXTNumOfPlayers", false).FirstOrDefault() as TextBox;
- txtBoxes[1] = this.Controls.Find("TXTNumOfQuestions", false).FirstOrDefault() as TextBox;
- txtBoxes[2] = this.Controls.Find("TXTTimePerAns", false).FirstOrDefault() as TextBox;
- // changes the room name to the wanted room name
- if (TXTRoomName != null && TXTRoomName.Text != "")
- {
- this.roomName = TXTRoomName.Text;
- }
- else
- {
- return;
- }
- // adds the properties of the new room to the roomProperties, which then will be used to initializa the inroom form
- this.roomProperties.Clear();
- foreach (TextBox t in txtBoxes)
- {
- if (t != null && t.Text != "")
- {
- this.roomProperties.Add(t.Text);
- }
- else
- {
- this.roomName = "";
- return;
- }
- }
- stream.sendData(String.Format("213{0:00}{1}{2}{3:00}{4:00}", this.roomName.Length, this.roomName, roomProperties[0], int.Parse(roomProperties[1]), int.Parse(roomProperties[2])));
- }
- private void PBJoin_Click(object sender, EventArgs args)
- {
- ListBox LBRooms = this.Controls.Find("LBRooms", false).FirstOrDefault() as ListBox;
- if (LBRooms.SelectedIndex >= 0 && int.Parse(roomsID[LBRooms.SelectedIndex]) >= 0)
- {
- this.roomName = LBRooms.Items[LBRooms.SelectedIndex] as string;
- this.stream.sendData("209" + this.roomsID[LBRooms.SelectedIndex]);
- }
- }
- private void LBRooms_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- ListBox LBRooms = this.Controls.Find("LBRooms", false).FirstOrDefault() as ListBox;
- if (int.Parse(this.roomsID[LBRooms.SelectedIndex]) >= 0)
- {
- this.stream.sendData("207" + this.roomsID[LBRooms.SelectedIndex]);
- }
- }
- /// <summary>
- /// sends the username, password and email to server according to the format for sign up
- /// </summary>
- private void PBSign_Up_Click(object sender, EventArgs args)
- {
- TextBox txtUserName = (TextBox)this.Controls.Find("TXTusername", false).FirstOrDefault();
- TextBox txtPassword = (TextBox)this.Controls.Find("TXTpsw", false).FirstOrDefault();
- TextBox txtEmail = (TextBox)this.Controls.Find("TXTemail", false).FirstOrDefault();
- if (txtUserName != null && txtPassword != null && txtEmail != null)
- {
- this.stream.sendData(String.Format("203{0:00}{1}{2:00}{3}{4:00}{5}", txtUserName.Text.Length, txtUserName.Text, txtPassword.Text.Length, txtPassword.Text, txtEmail.Text.Length, txtEmail.Text));
- }
- }
- /// <summary>
- /// sends the username and password to server according to the format for sign in
- /// </summary>
- private void PBSign_In_Click(object sender, EventArgs e)
- {
- TextBox txtUserName = (TextBox)this.Controls.Find("TXTusername", false).FirstOrDefault();
- TextBox txtPassword = (TextBox)this.Controls.Find("TXTpsw", false).FirstOrDefault();
- if (txtUserName != null && txtPassword != null)
- {
- this.stream.sendData(String.Format("200{0:00}{1}{2:00}{3}", txtUserName.Text.Length, txtUserName.Text, txtPassword.Text.Length, txtPassword.Text));
- }
- }
- private void BTN1st_Click(object sender, EventArgs args)
- {
- this.buttonAnswer = "BTN1st";
- this.BTNCliclk(1);
- }
- private void BTN2nd_Click(object sender, EventArgs args)
- {
- this.buttonAnswer = "BTN2nd";
- this.BTNCliclk(2);
- }
- private void BTN3rd_Click(object sender, EventArgs args)
- {
- this.buttonAnswer = "BTN3rd";
- this.BTNCliclk(3);
- }
- private void BTN4th_Click(object sender, EventArgs args)
- {
- this.buttonAnswer = "BTN4th";
- this.BTNCliclk(4);
- }
- private void BTNCliclk(int answerNo)
- {
- this.gameTimer.Stop();
- Label time = this.Controls.Find("LBLTime", false).FirstOrDefault() as Label;
- stream.sendData(string.Format("219{0}{1:00}", answerNo, int.Parse(this.questionTime) - int.Parse(time.Text)));
- }
- private void BTNLeave_Click(object sender, EventArgs args)
- {
- stream.sendData("211");
- }
- private void BTNLeaveGame_Click(object sender, EventArgs args)
- {
- this.gameTimer.Stop();
- Invoke((MethodInvoker)(() => CleanAllControlers(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => InitMainScreen(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => this.PBClose.Visible = true));
- stream.sendData("222");
- }
- private void BTNCloseRoom_Click(object sender, EventArgs args)
- {
- stream.sendData("215");
- }
- private void BTNStartGame_Click(object sender, EventArgs args)
- {
- stream.sendData("217");
- }
- /// <summary>
- /// handles the messags from server
- /// </summary>
- private void handleMessage()
- {
- string msg = "";
- while (true)
- {
- msg = this.stream.recvData(); // the message from the server
- switch (int.Parse(msg.Substring(0, 3)))
- {
- case 102:
- this.HandleSignIn(msg.Substring(3, 4)); // in case of sign in
- break;
- case 104:
- this.HandleSignUp(msg.Substring(3, 4)); // in case of sign up
- break;
- case 124:
- this.HandleBestScores(msg.Substring(3)); // in case of best scores
- break;
- case 126:
- this.HandlePersonalStatus(msg.Substring(3)); // in case of personal status
- break;
- case 106:
- this.HandleGetRooms(msg.Substring(3)); // in case of get rooms
- break;
- case 108:
- this.HandleGetUsers(msg.Substring(3)); // in case of get users
- break;
- case 110:
- this.HandleJoinRoon(msg.Substring(3)); // in case of join room
- break;
- case 112:
- this.HandleLeaveRoom(msg.Substring(3, 1)); // in case of leave room
- break;
- case 116:
- this.HandleCloseRoom(); // in case of close room
- break;
- case 118:
- this.HandleStartGame(msg.Substring(3)); // in case of start game
- break;
- case 114:
- this.handleCreateRoom(msg.Substring(3, 1)); // in case of create room
- break;
- case 120:
- this.HandleAnswer(msg.Substring(3, 1)); // in case of gets answer
- break;
- case 121:
- this.HandleFinishGame(msg.Substring(3)); // in case of finish game
- break;
- }
- }
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- this.t.Abort();
- this.stream.sendData("299");
- this.stream.CloseStream();
- this.PBClose.Dispose();
- }
- /// <summary>
- /// handles sign in request
- /// </summary>
- /// <param name="msg"> the message from the server </param>
- private void HandleSignIn(string msg)
- {
- switch (int.Parse(msg))
- {
- case 0:
- uid = ((TextBox)this.Controls.Find("TXTusername", false).FirstOrDefault()).Text; // to show his username in main screen
- Invoke((MethodInvoker)(() => CleanAllControlers(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => InitMainScreen(null, EventArgs.Empty)));
- break;
- case 1:
- MessageBox.Show("Wrong Details");
- break;
- case 2:
- MessageBox.Show("User is already connected");
- break;
- }
- }
- /// <summary>
- /// handles sign up request
- /// </summary>
- /// <param name="msg"> message from the server </param>
- private void HandleSignUp(string msg)
- {
- switch (int.Parse(msg))
- {
- case 0:
- Invoke((MethodInvoker)(() => CleanAllControlers(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => this.InitLoginScreen(null, EventArgs.Empty)));
- break;
- case 1:
- MessageBox.Show("Pass illegal");
- break;
- case 2:
- MessageBox.Show("Username is already exists");
- break;
- case 3:
- MessageBox.Show("Username is illegal");
- break;
- case 4:
- MessageBox.Show("Other");
- break;
- }
- }
- /// <summary>
- /// handles best scores request
- /// </summary>
- /// <param name="msg"> message from the server </param>
- private void HandleBestScores(string msg)
- {
- List<string> elem = new List<string>();
- int[] arr = new int[6] { 2, -6, 2, -6, 2, -6 };
- Helper.convertBytes(arr, elem, msg);
- KeyValuePair<string, string>[] arrPairs = new KeyValuePair<string, string>[3];
- if (elem.Count > 5)
- {
- for (int i = 0; i < 3; i++)
- {
- // arrPpairs is array of pairs that key is the name of the user and the value is his score
- arrPairs[i] = new KeyValuePair<string, string>(elem[i * 2], (int.Parse(elem[i * 2 + 1])).ToString());
- }
- }
- Invoke((MethodInvoker)(() => this.changeBestScores(arrPairs)));
- }
- /// <summary>
- /// handles personal status request
- /// </summary>
- /// <param name="msg"> message from the server </param>
- private void HandlePersonalStatus(string msg)
- {
- List<string> elem = new List<string>();
- int[] arr = new int[4] { -4, -6, -6, -4 };
- Helper.convertBytes(arr, elem, msg);
- this.ChangePersonalStatus(elem.ToArray());
- }
- /// <summary>
- /// handle get rooms
- /// </summary>
- /// <param name="msg"> the message from the server </param>
- private void HandleGetRooms(string msg)
- {
- List<string> elem = new List<string>();
- int numberOfRooms = int.Parse(msg.Substring(0, 4));
- int[] arr = new int[numberOfRooms * 2]; // because there are 2 parameters of each room (id and name)
- for (int i = 0; i < numberOfRooms; i++)
- {
- arr[i * 2] = -4;
- arr[i * 2 + 1] = 2;
- }
- Helper.convertBytes(arr, elem, msg.Substring(4));
- roomsID.Clear();
- for (int i = 0; i < elem.Count; i += 2)
- {
- /* the variable elem consists of id and name, for exemple {5, Room1, 5, Room2} that is why i only added to
- * the variable roomsID only the items in even places and remove them for the variable elem becase the
- * function how get the variable elem needs only the names
- */
- this.roomsID.Add(elem[i]);
- elem.RemoveAt(i);
- }
- Invoke((MethodInvoker)(() => this.changeRoomsList(elem)));
- }
- /// <summary>
- /// handle get users
- /// </summary>
- /// <param name="msg"> the message from the server</param>
- private void HandleGetUsers(string msg)
- {
- if (msg == "0") // in case of the game already start
- {
- MessageBox.Show("The game already start, please refresh");
- return;
- }
- List<string> elem = new List<string>();
- int numberOfUsers = int.Parse(msg.Substring(0, 1));
- int[] arr = new int[numberOfUsers];
- for (int i = 0; i < numberOfUsers; i++)
- {
- arr[i] = 2;
- }
- Helper.convertBytes(arr, elem, msg.Substring(1));
- /* the can be called from choosing room and inside room that why the condition (the if)
- * if the condition != null its mean that we are inside room and we souhld call the function ChangeLBpart
- * else mean that we are chossing room and we should call function changeUsersInRoom
- */
- if (this.Controls.Find("LBLparticipates", false).FirstOrDefault() as Label != null)
- {
- Invoke((MethodInvoker)(() => this.ChangeLBpart(elem)));
- }
- else
- {
- Invoke((MethodInvoker)(() => this.changeUsersInRoom(elem)));
- }
- }
- /// <summary>
- /// handle join room
- /// </summary>
- /// <param name="msg"> the message from the server</param>
- private void HandleJoinRoon(string msg)
- {
- if (msg.Substring(0, 1) == "0") // in case of succses
- {
- Invoke((MethodInvoker)(() => this.CleanAllControlers(null, EventArgs.Empty)));
- // i create new button so i can identify whether the page should be admin or user presentation
- Invoke((MethodInvoker)(() => this.InitInsideRoom(new PictureBox(), EventArgs.Empty)));
- List<string> elem = new List<string>();
- int[] arr = new int[2] { -2, -2 };
- Helper.convertBytes(arr, elem, msg.Substring(1));
- Invoke((MethodInvoker)(() => this.ChangeLabels(elem)));
- }
- else if (msg.Substring(0, 1) == "1") // in case of full room
- {
- MessageBox.Show("failed - room is full");
- }
- else // in case of room not exist or other reason
- {
- MessageBox.Show("failed - room not exist or other reason");
- }
- }
- /// <summary>
- /// handle leave room by clean all the controlers in the form and call InitMainScreen
- /// </summary>
- /// <param name="msg"> the message from the server</param>
- private void HandleLeaveRoom(string msg)
- {
- if (msg == "0")
- {
- this.roomName = ""; // delete the name of room
- Invoke((MethodInvoker)(() => CleanAllControlers(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => InitMainScreen(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => this.PBClose.Visible = true)); // turns on the close picture box
- }
- }
- /// <summary>
- /// handle close room by clean all the controlers in the form and call InitMainScreen
- /// </summary>
- private void HandleCloseRoom()
- {
- Button BTNCloseRoom = this.Controls.Find("BTNCloseRoom", false).FirstOrDefault() as Button;
- if(BTNCloseRoom == null)
- {
- MessageBox.Show("The admin close the room");
- }
- this.roomName = ""; // delete the name of room
- Invoke((MethodInvoker)(() => CleanAllControlers(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => InitMainScreen(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => this.PBClose.Visible = true)); // turns on the close picture box
- }
- /// <summary>
- /// handle create room
- /// </summary>
- /// <param name="msg"> the message from the server </param>
- private void handleCreateRoom(string msg)
- {
- if (msg == "0")
- {
- Invoke((MethodInvoker)(() => CleanAllControlers(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => InitInsideRoom(new Button(), EventArgs.Empty)));
- Invoke((MethodInvoker)(() => ChangeLabels(this.roomProperties)));
- Invoke((MethodInvoker)(() => ChangeLBpart(new List<string> { uid }))); // adds the current user to the users list
- }
- else
- {
- MessageBox.Show("Could not open the room");
- }
- }
- /// <summary>
- /// handle start game
- /// </summary>
- /// <param name="msg"> the message from the server </param>
- private void HandleStartGame(string msg)
- {
- if (msg == "0")
- {
- MessageBox.Show("An error occurred");
- }
- else
- {
- this.roomName = "";
- List<string> elem = new List<string>();
- int[] arr = new int[5] { 3, 3, 3, 3, 3 };
- Helper.convertBytes(arr, elem, msg);
- Invoke((MethodInvoker)(() => this.CleanAllControlers(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => this.InitGameScreen(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => this.changeQuestion(elem)));
- }
- }
- /// <summary>
- /// handle answer from the user
- /// </summary>
- /// <param name="msg"> the message from the server </param>
- private void HandleAnswer(string msg)
- {
- Button btnAnswer = this.Controls.Find(this.buttonAnswer, false).FirstOrDefault() as Button; // gets the button
- // which i press on
- if (msg == "0") // in case of wrong answer
- {
- btnAnswer.BackColor = Color.Red;
- }
- else
- {
- btnAnswer.BackColor = Color.LightGreen;
- }
- }
- /// <summary>
- /// handle finish game
- /// </summary>
- /// <param name="msg"> the message from the server </param>
- private void HandleFinishGame(string msg)
- {
- string scores = "";
- string line = "";
- List<string> elem = new List<string>();
- int numberOfUsers = int.Parse(msg.Substring(0, 1));
- int[] arr = new int[numberOfUsers * 2];
- for (int i = 0; i < numberOfUsers; i++)
- {
- arr[i * 2] = 2;
- arr[i * 2 + 1] = -2;
- }
- Helper.convertBytes(arr, elem, msg.Substring(1));
- for (int i = 0; i < elem.Count / 2; i+=2 )
- {
- line = "Name : " + elem[i] + ", " + "Score : " + elem[i + 1] + "\n";
- scores += line;
- }
- MessageBox.Show(scores);
- Invoke((MethodInvoker)(() => this.CleanAllControlers(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => this.InitMainScreen(null, EventArgs.Empty)));
- Invoke((MethodInvoker)(() => this.PBClose.Visible = true));
- }
- }
- }
- // TODO:
- // set font according to resulution
- // remove the size of the Close button from the login and signup pages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement