Esempio n. 1
0
        //Calculate Attack roll for Character
        public void CharacterAttacks(Character character, Monster monster)
        {
            //Hold character chance to hit
            int hitChance = 0;

            //Hold misschance for monster
            int missChance = 0;

            //New Seed Every Attack
            DiceRoll DiceBag = new DiceRoll();

            //Dice Roll with d20
            int roll = DiceBag.Roll(DiceRoll.Dice.D20);

            //If roll is  1, guarantee miss attack
            if (roll == 1)
            {
                hitChance  = 0;
                missChance = 20;
            }

            //else if roll is 20, guarantee hit attack
            else if (roll == 20)
            {
                hitChance  = 20;
                missChance = 0;
            }

            //else Calculate hitchance/misschance to see if successfull hit
            else
            {
                //HitChance = D20 dice roll + character level + attack from items
                hitChance = roll + character.Level + character.StatModifier(AttributeEnum.Attack);


                //Miss change = monster defense, level
                missChance = monster.Defense + monster.Level;
            }


            Debug.WriteLine("character: roll:" + roll + " hitchance:" + hitChance + " Misschance:" + missChance);
            Debug.WriteLine("Char defense:" + character.Defense + " character.Level" + character.Level);


            //If hitchance is greater than misschance
            if (hitChance >= missChance)
            {
                //Calcuate damage to apply to monster
                int applyDamage = Convert.ToInt32(Math.Ceiling(character.Level * (.25)) + character.Attack + character.WeaponDamage(AttributeEnum.Attack));

                //Calcuate experience to get from monster to character for % of damage done by character
                int monsterEXP = monster.GivenExperience(applyDamage);

                //Applys damage to monster by calling method
                ApplyDamageToMonster(monster, applyDamage);

                //Add's experience to character corresponding to the percent of damage done
                character.AddExperience(monsterEXP);

                //Add's the experience gained to the score page
                score.ExperienceGainedTotal += monsterEXP;

                //Checks character experience to see if leveled up
                character.CheckExperience();

                //Damage output string
                CharacterAttack = " for " + applyDamage + " damage. ";
            }

            //Hitchance less than misschance
            else
            {
                //Miss string
                CharacterAttack = " Misses attack ";
            }
        }
Esempio n. 2
0
        public void checkTurnsAuto() //check queue of monsters and characters and look at first element, character default goes first
        {
            Monster   m = monsterq.Peek();
            Character c = characterq.Peek();

            if (m.IsDead()) //check if monster is dead, if so remove
            {
                if (monsterq.Count > 1)
                {
                    monsterq.Dequeue();
                    // numberMonsterDead = numberMonsterDead +1;
                    m = monsterq.Peek();
                }
            }
            if (c.IsDead()) //check if character is dead, remove if dead
            {
                if (characterq.Count > 1)
                {
                    characterq.Dequeue();
                    // numbercharacterdead = numbercharacterdead +1;
                    c = characterq.Peek();
                }
            }
            //case where count 0 now
            //CASES WHERE currenct charactes and monsters will go through turns, if monster/character dies turn count will be added to that side
            //could exceed 6 due to case where 6 entities of one side exceeds 6 turns because attack by otherside increase their count
            //ex 6 character went, monsters kill 1 character , now count is 7, should account for turn
            if (turncheckCharacter < 6 && turncheckMonster < 6)              //case where both parties have not gone full 6 entity
            {
                if (c.Speed + c.StatModifier(AttributeEnum.Speed) > m.Speed) //character first
                {
                    TurnMonster        = m;
                    TurnCharacter      = c;                      //character set as turn character
                    turncheckCharacter = turncheckCharacter + 1; // automatically add this character as taken its turn
                    characterq.Enqueue(characterq.Dequeue());    //add back to end of queue since didnt die
                    CharacterTurnAttackAuto();
                    //checkTurnsAuto();
                }
                else if (m.Speed >= c.Speed + c.StatModifier(AttributeEnum.Speed))
                {
                    TurnCharacter    = c;
                    TurnMonster      = m;                    //case monster higher than character then monster turn
                    turncheckMonster = turncheckMonster + 1; //add turn as taken
                    monsterq.Enqueue(monsterq.Dequeue());    //add monster back to end of quueue
                    MonsterTurnAttackAuto();
                    //checkTurnsAuto();
                }
            }
            else if (turncheckCharacter < 6 && turncheckMonster >= 6) //case characters havent taken their turns yet but monsters have
            {
                //see top ln183
                TurnMonster        = m;
                TurnCharacter      = c;                      //character set as turn character
                turncheckCharacter = turncheckCharacter + 1; // automatically add this character as taken its turn
                characterq.Enqueue(characterq.Dequeue());    //add back to end of queue since didnt die
                CharacterTurnAttackAuto();
                //checkTurnsAuto();
            }
            else if (turncheckCharacter >= 6 && turncheckMonster < 6) //case all characters go through but not monster
            {
                //set top ln 193
                TurnMonster      = m;
                TurnCharacter    = c;
                turncheckMonster = turncheckMonster + 1;
                monsterq.Enqueue(monsterq.Dequeue());
                MonsterTurnAttackAuto();
                //checkTurnsAuto();
            }
            else if (turncheckCharacter >= 6 && turncheckMonster >= 6) //case both are filled reset them
            {
                turncheckCharacter = numbercharacterdead;
                turncheckMonster   = numberMonsterDead;
                //checkTurnsAuto();
            }
            else
            { //alert if deadlock of queueing and fight button
                Debug.WriteLine("DEADLOCK");
            }
        }