class Grid

Attributes

area[RW]
center[RW]
ground[RW]
id[R]
origin[RW]
points[RW]
visualizer[R]
xdif[RW]
xmax[RW]
xmin[RW]
ydif[RW]
ymax[RW]
ymin[RW]

Public Class Methods

new(xmin,xmax,ymin,ymax,origin=[0,0],center=[0,0],ground="asphalt") click to toggle source
# 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

Public Instance Methods

[](x,y) click to toggle source
# File lib/GameGrid.rb, line 230
def [](x,y)
    xypair=[x,y]
    return @points[xypair]
end
[]=(x,y,to) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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