class Point
A Point
is an area on the gamegrid
Attributes
ground[R]
gtype[RW]
Attributes of your point
id[R]
object[RW]
Attributes of your point
x[RW]
Attributes of your point
y[RW]
Attributes of your point
Public Class Methods
new(x,y,ground,object=nil)
click to toggle source
Initialize: Set the required variables in the beginning of time
# File lib/GameGrid.rb, line 196 def initialize(x,y,ground,object=nil) @id=rand(999999999) @x=x @y=y @ground=ground if object!=nil then @object=object else @object=nil end obj=object if (obj===nil) then obj=" no objects" end setGType(); puts "Point created at #{@x}, #{@y}, on #{@ground}, with"+obj end
Public Instance Methods
getloc()
click to toggle source
# File lib/GameGrid.rb, line 213 def getloc return 'hi' end
ground=(target)
click to toggle source
Ground=: Set the ground to any ground area (aka. rock)
# File lib/GameGrid.rb, line 190 def ground=(target) @ground=target setGType() end
ifdo(action)
click to toggle source
Ifdo: What might happen if you do <action>?
# File lib/GameGrid.rb, line 136 def ifdo(action) actionlist=["fall","jump","swim","sit"] resultsperType={ "rocksolid"=>['You will lose 1/2 lives, lose 8 altitude', 'You will lose 5 energy, gain 3 altitude', 'Not possible','You will lose 4 altitude, lose 2 energy'], "softy"=>['You will lose 8 altitude','You will lose 5 energy, gain 3 altitude', 'Not possible', 'You will lose 4 altitude, lose 1 1/2 energy'], "dangerous"=>['You will lose 3 1/2 lives, lose 8 altitude', 'You will lose 10 energy, gain 3 altitude', 'You will lose 4 1/2 lives','You will lose 4 altitude, lose 2 1/2 lives'] } if (resultsperType.include?(@gtype)===false) then raise "Ground Type does not comply" end myresults=resultsperType[@gtype] if (actionlist.include?(action)===false) then raise "Action type does not comply" end ordernum=actionlist.index(action) result=myresults[ordernum] log(self.to_s+": .ifdo function called, result='"+result+"'") return result end
result(action)
click to toggle source
Result: Do (action) for me.
# File lib/GameGrid.rb, line 170 def result(action) actionlist=["fall","jump","swim","sit"] resultsperType={ "rocksolid"=>['$lives-=0.5; $altitude-=8', '$energy-=5; $altitude+=3', '','$altitude-=4; $energy-=2'], "softy"=>['$altitude-=8','$energy-=5; $altitude+=3', '', '$altitude-=4, $energy-=1.5;'], "dangerous"=>['$lives-=3.5; $altitude-=8', '$energy-=10; $altitude+=3', '$lives-=4.5','$altitude-=4; $lives-=2.5'] } if (resultsperType.include?(@gtype)===false) then raise "Ground Type does not comply" end myresults=resultsperType[@gtype] if (actionlist.include?(action)===false) then raise "Action type does not comply" end ordernum=actionlist.index(action) result=myresults[ordernum] puts ifdo(action) eval(result) end
setGType()
click to toggle source
SetGType: What type of ground am I standing on?
# File lib/GameGrid.rb, line 157 def setGType case @ground; when "asphalt", "rock", "concrete", "wood" @gtype="rocksolid" when "carpet", "bed", "mat" @gtype="softy" when "lava", "magma", "fire", "spikes", "poison" @gtype="dangerous" end return @gtype; end
this()
click to toggle source
This: Basic info about this point
# File lib/GameGrid.rb, line 218 def this if (@object===nil) then return 'at '+@x.to_s+', '+@y.to_s+', on '+@ground+', with no objects found.' else return 'at '+@x.to_s+', '+@y.to_s+', on '+@ground+', with a '+@object+' found on the ground.' end end