private void btnAddCharacter_Click(object sender, EventArgs e) { string name; if (txtName.Text.Length == 0) { MessageBox.Show("Please enter a name"); name = "Blank"; } else { name = txtName.Text.ToString(); } Character newCharacter = null; if (rdKing.Checked) { newCharacter = new King(listBox1, name); } if (rdQueen.Checked) { newCharacter = new Queen(listBox1, name); } if (rdKnight.Checked) { newCharacter = new Knight(listBox1, name); } if (rdTroll.Checked) { newCharacter = new Troll(listBox1, name); } charactersList.Add(newCharacter); refreshCharacterListBoxes(); txtName.Clear(); }
public void addNewCharacter() { //Begin creating a character Character newCharacter; //Create a different class depending on the checked rdo button. //Then adds the character to checklists on the form. if (rdKnight.Checked == true) { newCharacter = new Knight(txtName.Text); charList.Add(newCharacter); } else if (rdBandit.Checked == true) { newCharacter = new Bandit(txtName.Text); charList.Add(newCharacter); } else if (rdCleric.Checked == true) { newCharacter = new Bandit(txtName.Text); charList.Add(newCharacter); } else if (rdSorc.Checked == true) { newCharacter = new Knight(txtName.Text); charList.Add(newCharacter); } else { MessageBox.Show("You have not selected a Character class."); } }
public void ToStringKnight_CharactedThatsDefaultInstationtion_returnsTostringWithDefaultWeapon() { Character testCharacter = new Knight("Bob"); String expectedString = "My name is Bob! I am a chivalrous Knight! I Stab with my knife!"; String actualString = testCharacter.ToString(); Assert.AreEqual(expectedString, actualString); }
private void btnAddCharacter_Click(object sender, EventArgs e) { string name = txtName.Text; Character newCharacter; try { if (name != "") { if (rdKing.Checked) { newCharacter = new King(name); Character.characterList.Add(newCharacter); } else if (rdKnight.Checked) { newCharacter = new Knight(name); Character.characterList.Add(newCharacter); } else if (rdQueen.Checked){ newCharacter = new Queen(name); Character.characterList.Add(newCharacter); } else if (rdTroll.Checked){ newCharacter = new Troll(name); Character.characterList.Add(newCharacter); } else MessageBox.Show("Please choose a title for your character."); } else MessageBox.Show("Please enter a name for your character."); } catch (NullReferenceException) { MessageBox.Show("Name cannot be null."); } PopulateListBoxes(); }
/* * Add character button click handler */ private void btnAddCharacter_Click(object sender, EventArgs e) { String name = txtName.Text; Character characterToAdd = null; if (name.Length > 0) { // Get the selected character type if (rdKing.Checked) characterToAdd = new King(name); else if (rdQueen.Checked) characterToAdd = new Queen(name); else if (rdKnight.Checked) characterToAdd = new Knight(name); else if (rdTroll.Checked) characterToAdd = new Troll(name); else MessageBox.Show("Please select a character type"); } else { MessageBox.Show("Please enter a name for the new character"); } if (characterToAdd != null) { // Add new character gameManager.AddCharacter(characterToAdd); // Update the Checked List Boxes to include the new character populateCharacterCheckedListBoxes(); // Clear the character name tet box and set the default character type to King txtName.Clear(); rdKing.Checked = true; } }