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_NameIsSetInConstuctor() { String characterName = "Jeff"; Character character = new Troll(characterName); Assert.AreEqual(character.Name, characterName); }
public void ToStringTroll_CharactedThatsDefaultInstationtion_returnsTostringWithDefaultWeapon() { Character testCharacter = new Troll("Bob"); String expectedString = "My name is Bob! Trolls don't have time to chat! 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(); } // End of Add
//Methods // Adds character to the list and outputs to the listbox public void addCharacters() { //Declare character called classType Character classType; // Checks which one of the radio buttons has been checked // If no radio buttons has been clicked then a messageBox will appear if (rdKing.Checked) { classType = new King(txtName.Text); charactersList.Add(classType); } else if (rdQueen.Checked) { classType = new Queen(txtName.Text); charactersList.Add(classType); } else if (rdKnight.Checked) { classType = new Knight(txtName.Text); charactersList.Add(classType); } else if (rdTroll.Checked) { classType = new Troll(txtName.Text); charactersList.Add(classType); } else { MessageBox.Show("You have not selected any class type yet!"); } // foreach through the list and add them to the checkedListBoxes with the character names foreach (Character chr in charactersList) { checkedListBox1.Items.Add(chr.Name); checkedListBox2.Items.Add(chr.Name); } setRadioButtonToFalse(); }
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; } }