#!/usr/bin/ruby class Actor attr_accessor :uid, :name, :x, :y, :z, :hp, :maxhp, :alignment def pathfind (map, xd, yd) xa = @x ya = @y closed = {} q = MapPriorityQueue.new(xd, yd, MapPath.new(map, false) << map[@x, @y]) p, r, s = nil i=0 while q.length>0 i+=1 p = q.getnext next unless p r = p.last next unless r next if r and closed[r] return p,i if (r.x==xd) and (r.y==yd) closed[r] = true p.successors(self).each do |s| q << s end end return nil, i end end class Player < Actor def initialize(x, y) @x = x @y = y @z = 0 @maxhp = 10 @hp = 10 @alignment = :unaligned end def alignment= (align) raise "NotAnAligment" unless [:lawful, :neutral, :chaotic, :unaligned].index align end def hp= (hp) @hp = (hp<0 ? 0 : (hp>@maxhp ? @maxhp : hp) ) end def maxhp= (mhp) @maxhp = (mhp<0 ? 0 : mhp) @hp = (@maxhp<@hp ? @maxhp : @hp) end end class Monster < Actor end if __FILE__ == $0 require "../utils/assert.rb" puts "unit test succeeded" end