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 Character_IntroductionMessageIsSetAtConstruction() { String expectedIntroductionMessage = "I am the powerful Queen!"; Character character = new Queen("Mike"); Assert.AreEqual(character.IntroductionMessage, expectedIntroductionMessage); }
public void ToStringQueen_CharactedThatsDefaultInstationtion_returnsTostringWithDefaultWeapon() { Character testCharacter = new Queen("Bob"); String expectedString = "My name is Bob! I am the powerful Queen! I shoot with my bow!"; 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; } }