at-m42:lecture7
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
at-m42:lecture7 [2009/04/13 15:49] – eechris | at-m42:lecture7 [2011/01/14 12:45] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 645: | Line 645: | ||
Game: Lord of the Rings | Game: Lord of the Rings | ||
=========================== | =========================== | ||
- | | + | |
WeightyItem: | WeightyItem: | ||
Item: clay pipe has value 0 | Item: clay pipe has value 0 | ||
Line 684: | Line 684: | ||
class WeightyItem extends Item { ... } | class WeightyItem extends Item { ... } | ||
- | class MagicItem | + | class MagicalItem |
</ | </ | ||
Line 719: | Line 719: | ||
Game: Lord of the Rings | Game: Lord of the Rings | ||
=========================== | =========================== | ||
- | | + | |
WeightyItem: | WeightyItem: | ||
WeightyItem: | WeightyItem: | ||
Line 745: | Line 745: | ||
<code groovy> | <code groovy> | ||
- | interface | + | interface |
- | + | Boolean abstract canCarry(Player player) | |
- | Boolean abstract canCarry(Player player) | + | |
} | } | ||
- | abstract class AbstractItem implements | + | abstract class AbstractItem implements |
- | String toString() | + | class WeightyItem extends AbstractItem |
- | return "Item: ${name} has value ${value}" | + | |
- | } | + | |
- | + | ||
- | Boolean hasDescription() { | + | |
- | return ! (description == '' | + | |
- | } | + | |
- | + | ||
- | Boolean canCarry(Player player) | + | |
- | return (player.funds >= value) | + | |
- | | + | |
- | // ----- properties ---------------------------------- | + | class MagicalItem extends AbstractItem { ... } |
+ | </code> | ||
- | def name | + | Full listing for [[http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture07/ |
- | def value // value of the item in game points | + | |
- | def description = '' | + | |
- | } | + | ---- |
- | class WeightyItem extends | + | The implementation for this is give in Example 15, where '' |
- | + | ||
- | String toString() { | + | |
- | return | + | |
- | } | + | |
- | + | ||
- | Boolean canCarry(Player player) { | + | |
- | return super.canCarry(player) && (weight < player.strength) | + | |
- | } | + | |
- | + | ||
- | // ---- properties ------------------------- | + | |
- | + | ||
- | def weight = 0 | + | |
- | } | + | |
- | + | ||
- | class MagicalItem extends | + | |
- | + | ||
- | String toString() { | + | |
- | return | + | |
- | } | + | |
- | + | ||
- | Boolean | + | |
- | return super.canCarry(player) && (player.power >= (potency/ | + | |
- | } | + | |
- | </ | + | |
<code groovy 1 | Example 15: The interface calls (at-m42/ | <code groovy 1 | Example 15: The interface calls (at-m42/ |
at-m42/lecture7.1239637796.txt.gz · Last modified: 2011/01/14 12:25 (external edit)