示例#1
0
 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_DefaultWeaponIsSetAtConstruction()
        {
            IWeaponBehaviour expectedDefaultWeapon = new Sword();

            Character character = new King("Johnny");

            Assert.AreEqual(character.UseWeapon(), expectedDefaultWeapon.UseWeapon());
        }
        public void Character_CanChangeWeaponAtRunTime()
        {
            Character character = new King("Johnny");
            IWeaponBehaviour newWeapon = new Bow();

            character.Weapon = newWeapon;

            Assert.AreEqual(character.UseWeapon(), newWeapon.UseWeapon());
        }
示例#4
0
        public void ToStringKing_CharactedThatsDefaultInstationtion_returnsTostringWithDefaultWeapon()
        {
            Character testCharacter = new King("Bob");

            String expectedString = "My name is Bob! I am the most mighty King! I slice with my sword!";

            String actualString = testCharacter.ToString();

            Assert.AreEqual(expectedString, actualString);
        }
示例#5
0
        public void CharacterAddTestOnKing()
        {
            ListBox listBox = new ListBox();
            List<Character> CharacterList = new List<Character>();
            King king = new King(listBox, "TestName");
            CharacterList.Add(king);
            int expected = 1;
            int actual = CharacterList.Count;

            Assert.AreEqual(expected, actual);
        }
示例#6
0
        public void changeWeapon_changeACharatersWeapong_returnsTNewWeaponUseWeaponString()
        {
            Character testCharacter = new King("Bob");

            testCharacter.weapon = new Bow();

            String expectedString = "I shoot with my bow!";

            String actualString = testCharacter.weapon.UseWeapon();

            Assert.AreEqual(expectedString, actualString);
        }
示例#7
0
        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();
        }
示例#8
0
        /*
         *  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;
            }
        }