testStates.rb
RubyMud/testStates.rb · 2.2 KB
From the archive rbmud-0.1rc2.tar.gz
Download the archive « Back to the archive contents
class State
def Links=(links)
@links = links
end
def Links
return @links
end
def ArriveFunc
@arriveFunc
end
def DepartFunc
@arriveFunc
end
def initialize(arriveFunc,departFunc,name)
@links = []
@arriveFunc = arriveFunc
@departFunc = departFunc
end
def Evaluate()
for t in @links
if (t.Test)
(@departFunc != nil)? @departFunc.call : 0
(t.Finish.ArriveFunc != nil)? t.Finish.ArriveFunc.call : 0
return t.Finish
end
end
return self
end
end
class Link
def Start
@start
end
def Finish
@finish
end
def Test
@test
end
def initialize(name,start,finish,test)
@start = start
@finish = finish
@test = test
# Link the tests
@start.Links.push(self)
end
end
class Quest
def initialize()
@name = ""
@description = ""
end
end
class Bunny
def Eat
print "Eating\n"
print "Adding object to tick queue scheduled for 1 sec\n"
end
def Move
print "Moving\n"
print "Adding object to tick queue scheduled for 1 sec\n"
end
def initialize()
# Define states
@eat = State.new(method(:Eat),nil,"Eat")
@walk = State.new(method(:Move),nil,"Move")
# Define links
@eatWalk = Link.new("1",@eat,@walk,true)
@walkEat = Link.new("2",@walk,@eat,true)
@currentState = @eat
end
def Tick()
@currentState = @currentState.Evaluate()
end
end
#begin rdoc
#Example thing
#1
#2
#3
#end
class Combat
def HandToHand
print "Eating\n"
print "Adding object to tick queue scheduled for 1 sec\n"
end
#A
#This is the weapon function
#end
def Weapon
print "Moving\n"
print "Adding object to tick queue scheduled for 1 sec\n"
end
def Spell
print "Moving\n"
print "Adding object to tick queue scheduled for 1 sec\n"
end
def initialize(mobile1,mobile1)
# Involved parties
@mobile1 = mobile1
@mobile2 = mobile2
# Define states
@eat = State.new(method(:Eat),nil,"Eat")
@walk = State.new(method(:Move),nil,"Move")
# Define links
@eatWalk = Link.new("1",@eat,@walk,true)
@walkEat = Link.new("2",@walk,@eat,true)
@currentState = @eat
end
def Tick()
@currentState = @currentState.Evaluate()
end
end
bunny = Bunny.new()
bunny.Tick()
bunny.Tick()
bunny.Tick()
bunny.Tick()