private void btn_register_Click(object sender, EventArgs e) { PlayerInformation exsistingPlayer = collectPlayer.GetPlayer(txt_username.Text); lbl_passwordError.Visible = false; lbl_usernameError.Visible = false; //Validating a new player if (string.IsNullOrWhiteSpace(this.txt_username.Text)) { lbl_usernameError.Text = "This field is required"; lbl_usernameError.Visible = true; } else if (string.IsNullOrWhiteSpace(this.txt_password.Text)) { lbl_passwordError.Text = "This field is required"; lbl_passwordError.Visible = true; } else if (exsistingPlayer != null) { lbl_usernameError.Text = "Sorry this username has already been taken"; lbl_usernameError.Visible = true; } else if (txt_username.TextLength < 4 || txt_username.TextLength > 12) { lbl_usernameError.Text = "Usernames must be between 4-12 characters"; lbl_usernameError.Visible = true; } else if (txt_password.TextLength < 4) { lbl_passwordError.Text = "Password is too short... Try again"; lbl_passwordError.Visible = true; } else { //Registering the user newPlayer.Username = txt_username.Text; newPlayer.Password = txt_password.Text; collectPlayer.AddPlayer(ref newPlayer); Program.SaveObject(collectPlayer); //move to the next form Form nextForm = new frm_MainMenu(ref newPlayer); this.Hide(); nextForm.Show(); } }
public frm_Login() { InitializeComponent(); try { Program.LoadObject(ref collectPlayer); } catch { collectPlayer = new PlayerCollection(); } newPlayer = new PlayerInformation(); }
public int FindIndex(string username) { //Returns players index number PlayerInformation p = null; bool found = false; int i = playerCount - 1; while (i >= 0 && found == false) { p = playerlist[i]; if (p.Username == username) { found = true; } else { i = i - 1; } } return(i); }
private void button1_Click(object sender, EventArgs e) { PlayerInformation exsistingPlayer = collectPlayer.GetPlayer(txt_username.Text); lbl_passwordError.Visible = false; lbl_usernameError.Visible = false; if (string.IsNullOrWhiteSpace(this.txt_username.Text)) { lbl_usernameError.Text = "This field is required"; lbl_usernameError.Visible = true; } else if (string.IsNullOrWhiteSpace(this.txt_password.Text)) { lbl_passwordError.Text = "This field is required"; lbl_passwordError.Visible = true; } else if (exsistingPlayer == null) { lbl_usernameError.Text = "This username does not exist"; lbl_usernameError.Visible = true; } else if (exsistingPlayer.Password != txt_password.Text) { lbl_passwordError.Text = ("Incorrect password... Try again"); lbl_passwordError.Visible = true; txt_password.Text = ""; } else { //move to the next form Form nextForm = new frm_MainMenu(ref exsistingPlayer); this.Hide(); nextForm.Show(); } }
public void AddPlayer(ref PlayerInformation newplayer) { //Adds a player to the list playerlist.Add(newplayer); }
public frm_MainMenu(ref PlayerInformation tempNewPlayer) { InitializeComponent(); newPlayer = tempNewPlayer; Program.LoadObject(ref collectPlayer); }
public frm_MainMenu() { InitializeComponent(); newPlayer = new PlayerInformation(); }