Class: Grid
- Inherits:
-
Object
- Object
- Grid
- Defined in:
- lib/GameGrid.rb
Instance Attribute Summary collapse
-
#area ⇒ Object
Returns the value of attribute area.
-
#center ⇒ Object
Returns the value of attribute center.
-
#ground ⇒ Object
Returns the value of attribute ground.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#points ⇒ Object
Returns the value of attribute points.
-
#visualizer ⇒ Object
readonly
Returns the value of attribute visualizer.
-
#xdif ⇒ Object
Returns the value of attribute xdif.
-
#xmax ⇒ Object
Returns the value of attribute xmax.
-
#xmin ⇒ Object
Returns the value of attribute xmin.
-
#ydif ⇒ Object
Returns the value of attribute ydif.
-
#ymax ⇒ Object
Returns the value of attribute ymax.
-
#ymin ⇒ Object
Returns the value of attribute ymin.
Instance Method Summary collapse
- #[](x, y) ⇒ Object
-
#[]=(x, y, to) ⇒ Object
Make sure to actually syntax like this: [x,y]=to.
-
#initialize(xmin, xmax, ymin, ymax, origin = [0,0], center = [0,0], ground = "asphalt") ⇒ Grid
constructor
A new instance of Grid.
- #update ⇒ Object
- #updpoints(gr = @ground) ⇒ Object
- #visualize(point = nil) ⇒ Object
Constructor Details
#initialize(xmin, xmax, ymin, ymax, origin = [0,0], center = [0,0], ground = "asphalt") ⇒ Grid
Returns a new instance of Grid.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/GameGrid.rb', line 272 def initialize(xmin,xmax,ymin,ymax,origin=[0,0],center=[0,0],ground="asphalt") begin xmax-=1; ymax-=1; @id=rand() @xmin=xmin;@xmax=xmax;@ymin=ymin;@ymax=ymax; @area=(@xmax-@xmin+1)*(@ymax-@ymin+1) @xdif=(@xmax-@xmin+1);@ydif=(@ymax-@ymin+1) @origin=origin @center=center @points={}; @ground=ground @visualizer="run visualize method on this grid to set visualizer"; @oldvisualizers=[] updpoints() rescue xmin=0,xmax=0,ymin=0,ymax=0,ground="asphalt" retry end puts "Initialized Grid." end |
Instance Attribute Details
#area ⇒ Object
Returns the value of attribute area.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def area @area end |
#center ⇒ Object
Returns the value of attribute center.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def center @center end |
#ground ⇒ Object
Returns the value of attribute ground.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def ground @ground end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def id @id end |
#origin ⇒ Object
Returns the value of attribute origin.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def origin @origin end |
#points ⇒ Object
Returns the value of attribute points.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def points @points end |
#visualizer ⇒ Object (readonly)
Returns the value of attribute visualizer.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def visualizer @visualizer end |
#xdif ⇒ Object
Returns the value of attribute xdif.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def xdif @xdif end |
#xmax ⇒ Object
Returns the value of attribute xmax.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def xmax @xmax end |
#xmin ⇒ Object
Returns the value of attribute xmin.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def xmin @xmin end |
#ydif ⇒ Object
Returns the value of attribute ydif.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def ydif @ydif end |
#ymax ⇒ Object
Returns the value of attribute ymax.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def ymax @ymax end |
#ymin ⇒ Object
Returns the value of attribute ymin.
228 229 230 |
# File 'lib/GameGrid.rb', line 228 def ymin @ymin end |
Instance Method Details
#[](x, y) ⇒ Object
230 231 232 233 |
# File 'lib/GameGrid.rb', line 230 def [](x,y) xypair=[x,y] return @points[xypair] end |
#[]=(x, y, to) ⇒ Object
Make sure to actually syntax like this: [x,y]=to
234 235 236 237 |
# File 'lib/GameGrid.rb', line 234 def []=(x,y,to) #Make sure to actually syntax like this: [x,y]=to xypair=[x,y] @points[xypair]=to; end |
#update ⇒ Object
238 239 240 241 |
# File 'lib/GameGrid.rb', line 238 def update @area=(@xmax-@xmin+1)*(@ymax-@ymin+1) @xdif=(@xmax-@xmin+1);@ydif=(@ymax-@ymin+1) end |
#updpoints(gr = @ground) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/GameGrid.rb', line 242 def updpoints(gr=@ground) puts "Updating points on grid...\n GRID UPDATE NOTICE: You are using updpoints, the latest version of the official Grid Point Updater!" update() begin keepsetting1=true; xnum=@xmin; ynum=@ymin; xmax=@xmax; ymax=@ymax; xnumy=@xmin; while (keepsetting1===true) do ynumy=@ymin; keepsetting2=true; while (keepsetting2===true) do curpoint=Point.new(xnum,ynumy,gr); pair=[xnum,ynumy] @points[pair]=curpoint ynumy+=1 if (ynumy>ymax) keepsetting2=false; break; end end xnum+=1 if (xnum>xmax) keepsetting1=false; break; end end if (@area===@points.length) then; log("Grid:updpoints:success"); else; error("Grid:updpoints:failed grid.area='#{@area}', grid.points.length='#{@points.length}', area!=points.length",IndexError); end rescue IndexError @area=@points.length retry end end |
#visualize(point = nil) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/GameGrid.rb', line 291 def visualize(point=nil) puts "Converting Point elements to Arrays..." plotmarks=point if point.class===Array; plotmarks=[point.x,point,y] if point.class===Point; xdif=@xdif; ydif=@ydif xline="|"+" o "*xdif+"|\n" yplnum=@ymax+1; full = " "+"___"*(xdif)+"\n" while(yplnum>@ymin) curd="" curd=" " if (yplnum<10&&yplnum>(-1)) full+=(yplnum.to_s+curd+xline); yplnum-=1; break if (yplnum<=@ymin); end #full=xline*ydif xplotters = " "; xplnum=@xmin+1; xplotters=" " if @xmin<0; puts "Measuring plot size... Calculating Areas..." while(xplnum<=@xmax+2) curd,curd2=" "; curd=" ".to_s if xplnum<0; xplotters+=curd.to_s+xplnum.to_s+curd2.to_s; xplnum+=1 break if xplnum>=@xmax+2; end puts "Processing visualization..." full+=" "+"___"*(xdif)+"\n";full+=xplotters @visualizer=full; @oldvisualizers.push(full) puts full end |