Esempio n. 1
0
        public override BattleAction ai(Party goodGuys)
        {
            /* start ai */

            Random random = new Random();
            int i;
            Character target = null;

            /* Should modularize these loops */
            for (i = 0; i < goodGuys.Size; i++)
                if (((PlayerCharacter)goodGuys.getCharacter(i)).Class == ClassEnum.WHITEMAGE && !goodGuys.getCharacter(i).isDead)
                    target = goodGuys.getCharacter(i);

            if( target == null )
                for (i = 0; i < goodGuys.Size; i++)
                    if (((PlayerCharacter)goodGuys.getCharacter(i)).Class == ClassEnum.REDMAGE && !goodGuys.getCharacter(i).isDead)
                        target = goodGuys.getCharacter(i);

            if (target == null)
            {/* start if */

                target = goodGuys.getCharacter(random.Next(Party.MAXPARTY));

                while( target.isDead )
                    target = goodGuys.getCharacter(random.Next(Party.MAXPARTY));

            }/* end if */

            return new AttackAction(target);
        }
Esempio n. 2
0
        public override BattleEvent ai(Party goodGuys)
        {
            /* start ai */

            Random random = new Random();
            int target = random.Next( Party.MAXPARTY );
            BattleAction action = new BattleAction(ActionEnum.ATTACK, null);

            return new BattleEvent(mEnemy, action, goodGuys.getCharacter(target), 0);
        }
Esempio n. 3
0
        public override BattleAction ai(Party goodGuys)
        {
            /* start ai */

            Random random = new Random();
            int target = random.Next( goodGuys.Size );

            while( goodGuys.getCharacter(target).isDead )
                target = random.Next(goodGuys.Size);

            return new AttackAction(goodGuys.getCharacter(target));
        }
Esempio n. 4
0
        public override BattleEvent ai(Party goodGuys)
        {
            /* start ai */

            Character target = goodGuys.getCharacter(0);
            BattleAction action;
            int i;
            AbilitiesIterator abilities;
            Ability theAbility;

            if (mAbilities.Count != 0)
            {/* start if */

                abilities = getAbilities();
                theAbility = abilities.getAbilityAtIndex(0);

                foreach (Ability ability in abilities)
                    if (ability.AffectEnemy)
                        if (ability.BaseDamage > theAbility.BaseDamage)
                            theAbility = ability;

                for (i = 0; i < goodGuys.Size; i++)
                    if (goodGuys.getCharacter(i).CurrentHealth < target.CurrentHealth)
                        target = goodGuys.getCharacter(i);

                if (theAbility.Cost > mEnemy.CurrentMana)
                    action = new BattleAction(ActionEnum.ATTACK, null);
                else
                    action = new BattleAction(ActionEnum.ABILITY, theAbility);

            }/* end if */
            else
            {/* start else */

                action = new BattleAction(ActionEnum.ATTACK, null);

            }/* end else */

            return new BattleEvent(mEnemy, action, target, 0);
        }
Esempio n. 5
0
        public override BattleAction ai(Party goodGuys)
        {
            /* start ai */

            Character target = getTarget( goodGuys );
            BattleAction action;
            AbilitiesIterator abilities;
            Ability theAbility;

            if (mAbilities.Count != 0)
            {/* start if */

                abilities = getAbilities();
                theAbility = abilities.getAbilityAtIndex(0);

                foreach (Ability ability in abilities)
                    if (ability.AffectEnemy)
                        if (ability.BaseDamage > theAbility.BaseDamage)
                            theAbility = ability;

                if (theAbility.Cost > mEnemy.CurrentMana)
                    action = new AttackAction(target);
                else
                    if (theAbility.isSingleTarget)
                        action = new AbilityAction(theAbility, target);
                    else
                        action = new AbilityAction(theAbility);

            }/* end if */
            else
            {/* start else */

                action = new AttackAction(target);

            }/* end else */

            return action;
        }
Esempio n. 6
0
        private Character[] getAliveCharacters(Party goodGuys)
        {
            /* start getAliveCharacters */

            int i, j, count = 0;
            Character[] alivePlayers;

            for (i = 0; i < goodGuys.Size; i++)
                if (!goodGuys.getCharacter(i).isDead)
                    count++;

            alivePlayers = new Character[count];

            for( i = 0,j = 0; i < goodGuys.Size; i++ )
                if (!goodGuys.getCharacter(i).isDead)
                {/* start if */

                    alivePlayers[j] = goodGuys.getCharacter(i);
                    j++;

                }/* end if */

            return alivePlayers;
        }
Esempio n. 7
0
        public override BattleEvent ai(Party goodGuys)
        {
            /* start ai */

            Random random = new Random();
            int i;
            Character target = null;
            BattleAction action = new BattleAction(ActionEnum.ATTACK, null);

            /* Should modularize these loops */
            for (i = 0; i < goodGuys.Size; i++)
                if (((PlayerCharacter)goodGuys.getCharacter(i)).Class == ClassEnum.WHITEMAGE)
                    target = goodGuys.getCharacter(i);

            if( target == null )
                for (i = 0; i < goodGuys.Size; i++)
                    if (((PlayerCharacter)goodGuys.getCharacter(i)).Class == ClassEnum.REDMAGE)
                        target = goodGuys.getCharacter(i);

            if (target == null)
                target = goodGuys.getCharacter(random.Next(Party.MAXPARTY));

            return new BattleEvent(mEnemy, action, target, 0);
        }
Esempio n. 8
0
        public BattleAction takeTurn( Party goodGuys )
        {
            /* start takeTurn */

            return mAI.ai( goodGuys );
        }
Esempio n. 9
0
        public BattleAction getPlayerAction( Character character, Party badGuys )
        {
            /* start getPlayerAction */

            return mView.getPlayerAction(character, badGuys);
        }
Esempio n. 10
0
        private void initialize()
        {
            /* start initialize */

            ClassEnum choice;
            int i;
            String name;
            Character[] characters = new Character[ Party.MAXPARTY ];

            mView = new TextView();

            for (i = 0; i < Party.MAXPARTY; i++)
            {/* start loop */

                choice = mView.getClassChoice();
                name = mView.getCharacterName();

                characters[ i ] = CharacterFactory.getInstance().getCharacter(choice, name);

            }/* end loop */

            mGoodGuys = new Party(characters);
            mView.GoodGuys = mGoodGuys;
            mBattle = new Battle(this, mGoodGuys);
            mDungeon = Dungeon.getInstance(this, mView);
            mView.Dungeon = mDungeon.GetGrid();
        }
Esempio n. 11
0
 public abstract BattleAction ai(Party goodGuys);
Esempio n. 12
0
 public abstract BattleEvent ai(Party goodGuys);
Esempio n. 13
0
 // Constructors
 public Battle(Game currentGame, Party goodGuyParty)
 {
     mGame = currentGame;
     mGoodGuys = goodGuyParty;
 }
Esempio n. 14
0
        private ItemAction HandleItemSelection(Character character, Party badGuys)
        {
            /* start HandleItemSelection */

            Console.WriteLine("Which item would you like to use?");
            Ability[] items = mGoodGuys.Consumables;
            Ability choice;
            int i;

            if (items != null)
            {/* start if */

                for (i = 0; i < items.Length; i++)
                    Console.WriteLine(i + ". " + items[i].Name);

                choice = items[sanitizeInput(0,items.Length - 1)];

                mGoodGuys.removeItem(choice);

                if (choice.AffectEnemy)
                    return new ItemAction(choice);
                else
                    return new ItemAction(choice, getTarget(mGoodGuys, GOODGUYS));

            }/* end if */

            Console.WriteLine( "You have no items!" );
            return null;
        }
Esempio n. 15
0
        public BattleAction getPlayerAction(Character character, Party badGuys)
        {
            /* start getPlayerAction */

            BattleAction action = null;

            Console.WriteLine("It's " + character.Name + "'s turn!");
            Console.WriteLine(character.Name + " has " + character.CurrentHealth + " health and " + character.CurrentMana + " mana.");

            while (action == null)
            {/* start loop */

                Console.WriteLine("What would you like to do?");
                Console.WriteLine("1. Attack.");
                Console.WriteLine("2. Ability.");
                Console.WriteLine("3. Item.");

                action = CreateBattleAction((ActionEnum)sanitizeInput( 1, 3 ), character, badGuys);

            }/* end loop */

            return action;
        }
Esempio n. 16
0
        private BattleAction CreateBattleAction(ActionEnum action,Character character, Party badGuys )
        {
            /* start CreateBattleAction */

            if (action == ActionEnum.ATTACK)
                return new AttackAction(getTarget(badGuys, BADGUYS));

            if (action == ActionEnum.ABILITY)
                return HandleAbilitySelection(character, badGuys);

            if (action == ActionEnum.ITEM)
                return HandleItemSelection(character, badGuys);

            return null;
        }
Esempio n. 17
0
        private Character getTarget(Party party, bool partyAlignment)
        {
            /* start getTarget */

            int i;
            bool dead = true;
            Character candidate = null;

            if (partyAlignment == GOODGUYS)
            {/* start if */

                Console.WriteLine("Who would you like to heal?");
                for (i = 0; i < party.Size; i++)
                    Console.WriteLine(i + ". " + party.getCharacter(i).Name + "-Health: " + party.getCharacter(i).CurrentHealth + " -Mana : " + party.getCharacter(i).CurrentMana);

                candidate = party.getCharacter(sanitizeInput( 0, party.Size - 1));

            }/* end if */
            else
            {/* start else */

                while (dead)
                {/* start loop */

                    Console.WriteLine("Who would you like to damage?");
                    for (i = 0; i < party.Size; i++)
                        if (!party.getCharacter(i).isDead)
                            Console.WriteLine(i + ". " + party.getCharacter(i).Name + "-Health: " + party.getCharacter(i).CurrentHealth + " -Mana : " + party.getCharacter(i).CurrentMana);

                    candidate = party.getCharacter(sanitizeInput(0, party.Size - 1));

                    dead = candidate.isDead;

                    if (dead)
                        Console.WriteLine("INVALID INPUT! Pick one that's alive!");

                }/* end loop */

            }/* end else */

            return candidate;
        }
Esempio n. 18
0
        public Party getSpecificParty(EnemyType type)
        {
            /* start getSpecificParty */

            Party badGuys = null;

            if( type == EnemyType.DRAGON )
                badGuys = new Party( new Character[] { getDragon() } );

               return badGuys;
        }
Esempio n. 19
0
        private Character getTarget(Party goodGuys)
        {
            /* start getTarget */

            Character target;
            int i;

            Character[] alivePlayers = getAliveCharacters(goodGuys);

            for (i = 0, target = alivePlayers[ 0 ]; i < alivePlayers.Length; i++)
                if (alivePlayers[ i ].CurrentHealth < target.CurrentHealth)
                    target = alivePlayers[ i ];

            return target;
        }
Esempio n. 20
0
        public Character[] getTurnOrder(Party otherParty)
        {
            /* start getTurnOrder */

            int size = this.mPartySize + otherParty.mPartySize;
            int i, j;
            Character[] turnOrder = new Character[size];
            Character temp;

            for (i = 0; i < mParty.Length; i++)
                turnOrder[ i ] = mParty[ i ];

            for( j = 0; j < otherParty.mPartySize; j++, i++ )
                turnOrder[ i ] = otherParty.mParty[ j ];

            for (i = 0; i < size; i++)
                for (j = 0; j < size; j++)
                    if ( turnOrder[ i ].CompareTo( turnOrder[ j ] ) )
                    {/* start if */

                        temp = turnOrder[i];
                        turnOrder[i] = turnOrder[j];
                        turnOrder[j] = temp;

                    }/* end if */

            return turnOrder;
        }
Esempio n. 21
0
        public void startBattle(EnemyType specificEnemytype)
        {
            mBadGuys = EnemyFactory.getInstance().getSpecificParty(type);

            turnOrder = mGoodGuys.getTurnOrder(mBadGuys);
            selectFirstCharacter();

            turnOrder = mGoodGuys.getTurnOrder(mBadGuys);
            selectFirstCharacter();

            while (!battleOver())
            {
                if (currentActor.isPlayer)
                {
                    executeAction(mGame.getPlayerAction( currentActor ));
                }
                else
                {
                    Enemy current_enemy = (Enemy) currentActor;
                    executeAction(current_enemy.takeTurn(mGoodGuys));
                }
            }
        }
Esempio n. 22
0
        private AbilityAction HandleAbilitySelection(Character character, Party badGuys)
        {
            /* start HandleAbilitySelection */

            Character target;
            Ability ability;
            int i = 0;

            Console.WriteLine("Which ability would you like to use?");

            foreach (Ability candidate in character.Abilities)
            {/* start loop */

                Console.WriteLine(i + ". " + candidate.Name + "-Mana Cost: " + candidate.Cost);
                i++;

            }/* end loop */

            ability = character.Abilities.getAbilityAtIndex(sanitizeInput(0,character.Abilities.Count - 1));

            if (ability.AffectEnemy)
                target = getTarget(badGuys, BADGUYS);
            else
                target = getTarget(mGoodGuys, GOODGUYS);

            return new AbilityAction(ability, target);
        }
Esempio n. 23
0
        private void initialize()
        {
            /* start initialize */

            int choice, i;
            String[] classes = new String[ 6 ] { "Warrior", "Theif", "Monk", "White Mage", "Black Mage", "Red Mage" };
            String name;
            Character[] characters = new Character[ Party.MAXPARTY ];

            for (i = 0; i < Party.MAXPARTY; i++)
            {/* start loop */

                mView.sendOutput("What class type do you want? You get 3.");
                mView.sendOutput(classes.GetEnumerator(), TypeEnum.STRING);
                choice = (int)mView.getInput(TypeEnum.INT);
                name = (string)mView.getInput(TypeEnum.STRING);

                characters[ i ] = CharacterCreationFactory(choice, name);

            }/* end loop */

            mGoodGuys = new Party(characters);
            mBattle = new BattleSystem(this, mGoodGuys);
            mDungeon = new Dungeon(this, mGoodGuys);
        }
Esempio n. 24
0
        // Methods
        /*Start Battle Method Outline */
        /* 1) Get good and bad guys.
         * 2) Create an array that can hold all characters.
         * 3) Sort array by agility.
         * 4) Loop through array, giving each character a turn. Start over at the first element you the last goes.(L)
         * 5) For each players turn, MATH and handle choices. (F)
         * 6) If a player character defeats an enemy, call the gainExperience method of the character and send the worth of the enemy it defeated.
         */
        public void startBattle()
        {
            mBadGuys = EnemyFactory.getInstance().getEnemyParty(mGoodGuys.Level);

            turnOrder = mGoodGuys.getTurnOrder(mBadGuys);
            selectFirstCharacter();

            while(!battleOver())
            {/*Begin battle loop*/
                if (currentActor.isPlayer)
                {
                    executeAction(mGame.getPlayerAction(currentActor));
                }
                else
                {
                    Enemy current_enemy = (Enemy)currentActor;
                    executeAction(current_enemy.takeTurn(mGoodGuys));
                }

                selectNextCharacter();
            }/*End battle loop*/

            mGame.notifyBattleOutcome(mGoodGuys.isDead);
        }