2 Position = Struct.new( :x, :y )
6 attr_accessor :pos, :name, :object_type, :description
9 @pos = Position.new( nil, nil )
17 class Creature < GameObject
19 attr_accessor :state, :hp, :thac0, :hd, :ac, :xp_value, :inventory
30 num.times { result += rand( 4 ) + 1 }
37 num.times { result += rand( 20 ) + 1 }
42 def attack( g, target )
44 target.state = "fighting"
46 if d20 < @thac0 - target.ac
47 g.say( "#{name} misses." )
54 g.say( "#{@name} attacks #{target.name}. Hit! (#{damage} damage)." )
60 class Player < Creature
67 @object_type = "Human"
74 @description = "A typical human geek."
78 def attack( g, target )
82 @xp += target.xp_value
83 g.say( "#{@name} gains #{target.xp_value} experience points!" )
90 class Monster < Creature
99 def Monster.register( monster )
100 @@monsters << monster
109 g.objects.each_value do |o|
110 if o.instance_of?( Player ) and o.pos = @pos
134 @description = "The Orc is a humanoid creature resembling a caveman. It has dangerous looking fangs and a snout. Somehow, it does not look very smart."
140 class Slime < Monster
142 Monster.register Slime
147 @object_type = "Slime"
154 @description = "The Slime is a slimy jelly, oozing over the ground. You really don't feel like touching that."
160 class Weapon < GameObject
169 @object_type = "Sword"
170 @description = "A metal sword"