13.07.2015 Views

29 The Power of Inheritance and Polymorphism

29 The Power of Inheritance and Polymorphism

29 The Power of Inheritance and Polymorphism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Inheritance</strong> <strong>and</strong> <strong>Polymorphism</strong> 1018• Support "magic action" comm<strong>and</strong>s. Magic action comm<strong>and</strong>s weaken ordestroy monsters at a distance from the player; like movement comm<strong>and</strong>s, theyare directional.A magic action comm<strong>and</strong> inflicts a predefined amount <strong>of</strong> damage on anymonster located on the neighbouring square in the specified direction, half thatamount <strong>of</strong> damage on any monster two squares away along the specifieddirectional axis, a quarter that amount on a monster three squares away etc.Magic does not project through walls.Use <strong>of</strong> a magic action comm<strong>and</strong> consumes "manna" points. If the playerobject has insufficient manna points, the player suffers damage equal to twicethe deficit. So, if a comm<strong>and</strong> requires 8 manna points <strong>and</strong> the player object'smanna is 3, the manna is reduced to zero <strong>and</strong> the player object's health isreduced by 10 after executing the comm<strong>and</strong>.• Provide the following basic behaviours for monster objects.A monster object will attack the player object if it is on an adjacent point.If not immediately adjacent to the player object, some monsters "look" for theplayer <strong>and</strong>, if they can "see" the player, they may advance toward it or launch aprojectile.If they are not able to detect the player object, a monster object will perform its"normal movement" function. This might involve r<strong>and</strong>om movement, nomovement, or some more purposive behaviour.Monster objects do not attempt to acquire collectable items.Monster objects do not interact with other monster objects.<strong>29</strong>.2 DESIGN<strong>29</strong>.2.1 PreliminariesThis "preliminaries" section explores a few aspects <strong>of</strong> the program that seem prettymuch fixed by the specification. <strong>The</strong> objective is to fill out some details <strong>and</strong> get afew pointers to things that should be considered more thoroughly.For example the specification implies the existence <strong>of</strong> "class Dungeon", "classPlayer", "class Monster", a class for "collectable items" <strong>and</strong> so forth. We might aswell jot down a few initial ideas about these classes, making a first attempt toanswer the perennial questions "What does class X do? What do instances <strong>of</strong> classX own?". Only the most important responsibilities will get identified at this stage;more detailed consideration <strong>of</strong> specific aspects <strong>of</strong> the program will result in furtherresponsibilities being added. Detailed analysis later on will also show that some <strong>of</strong>the classes are interrelated, forming parts <strong>of</strong> a class hierarchy.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!