Class: Point
- Inherits:
-
Object
- Object
- Point
- Defined in:
- lib/GameGrid.rb
Overview
A Point is an area on the gamegrid
Instance Attribute Summary collapse
-
#ground ⇒ Object
Returns the value of attribute ground.
-
#gtype ⇒ Object
Attributes of your point.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#object ⇒ Object
Attributes of your point.
-
#x ⇒ Object
Attributes of your point.
-
#y ⇒ Object
Attributes of your point.
Instance Method Summary collapse
- #getloc ⇒ Object
-
#ifdo(action) ⇒ Object
Ifdo: What might happen if you do <action>?.
-
#initialize(x, y, ground, object = nil) ⇒ Point
constructor
Initialize: Set the required variables in the beginning of time.
-
#result(action) ⇒ Object
Result: Do (action) for me.
-
#setGType ⇒ Object
SetGType: What type of ground am I standing on?.
-
#this ⇒ Object
This: Basic info about this point.
Constructor Details
#initialize(x, y, ground, object = nil) ⇒ Point
Initialize: Set the required variables in the beginning of time
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# 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 |
Instance Attribute Details
#ground ⇒ Object
Returns the value of attribute ground.
133 134 135 |
# File 'lib/GameGrid.rb', line 133 def ground @ground end |
#gtype ⇒ Object
Attributes of your point
132 133 134 |
# File 'lib/GameGrid.rb', line 132 def gtype @gtype end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
133 134 135 |
# File 'lib/GameGrid.rb', line 133 def id @id end |
#object ⇒ Object
Attributes of your point
132 133 134 |
# File 'lib/GameGrid.rb', line 132 def object @object end |
#x ⇒ Object
Attributes of your point
132 133 134 |
# File 'lib/GameGrid.rb', line 132 def x @x end |
#y ⇒ Object
Attributes of your point
132 133 134 |
# File 'lib/GameGrid.rb', line 132 def y @y end |
Instance Method Details
#getloc ⇒ Object
213 214 215 |
# File 'lib/GameGrid.rb', line 213 def getloc return 'hi' end |
#ifdo(action) ⇒ Object
Ifdo: What might happen if you do <action>?
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# 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) ⇒ Object
Result: Do (action) for me.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# 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 ⇒ Object
SetGType: What type of ground am I standing on?
157 158 159 160 161 162 163 164 165 166 167 |
# 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 ⇒ Object
This: Basic info about this point
218 219 220 221 222 223 224 |
# 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 |