Example #1
0
        //Has all the creatures left standing attack the player
        private void creaturesAttack()
        {
            GenericCreature currCreature;

            for (int i = 0; i < creatures.getLength(); i++)
            {
                currCreature = (GenericCreature)creatures.getItem(i);
                if (currCreature.checkAttack())
                {
                    Strike strike = new Strike(currCreature);
                    Attack attack = new Attack(strike);
                    if (strike.isStriking())
                    {
                        String output = currCreature.getName() + " targets you with ";
                        if (strike.isMelee())
                        {
                            output += "a melee attack.";
                        }
                        else if (strike.isRanged())
                        {
                            output += "a ranged attack.";
                        }
                        else if (strike.isMagical())
                        {
                            output += "a spell.";
                        }
                        Constants.writeLine(output);
                        player.attacked(attack);
                        currCreature.attacked();
                    }
                    else
                    {
                        Constants.writeLine(currCreature.getName() + " has begun defending.");
                    }
                }
                System.Threading.Thread.Sleep(750);
            }
        }
Example #2
0
        //let's the player attack a creature, if theres only one creature just attacks that creature
        private void playerAttack()
        {
            Constants.writeLine("It's your turn.");
            int    choice = 0;
            Strike playerAttack;

            do
            {
                playerAttack = new Strike(player);
                if (!playerAttack.isStriking())
                {
                    return;
                }
                Constants.writeLine("Who would you like to target?");
                choice = chooseCreature();
            } while (choice == 0);

            Attack attack = new Attack(playerAttack);

            if (choice == 1)
            {
                Constants.writeLine("You targeted yourself.");
                player.attacked(attack);
            }
            else
            {
                GenericCreature target = (GenericCreature)creatures.getItem(choice - 2);
                Constants.writeLine("You targeted " + target.getName() + ".");
                target.attacked(attack);
                if (!target.isAlive())
                {
                    Constants.writeLine("The creature falls to the ground dead.");
                    creatures.removeItem(choice - 2);
                }
                System.Threading.Thread.Sleep(750);
            }
        }