class Location

Represents a 2D location in space. Note that there is an attr_accessor for @x and @y.

Attributes

x[RW]
y[RW]

Public Class Methods

new(x, y) click to toggle source

Sets the x and y to the given values.

# File lib/locationclass.rb, line 7
def initialize(x, y)
        @x = x
        @y = y
end

Public Instance Methods

[](k) click to toggle source
# File lib/locationclass.rb, line 45
def [](k)
        return nil unless (k == 0 or k == 1)
        return self.x() if (k == 0)
        return self.y()
end
[]=(k, v) click to toggle source
# File lib/locationclass.rb, line 50
def []=(k, v)
        return nil unless (k == 0 or k == 1)
        self.x = v if (k == 0)
        self.y = v
end
highest_value_x?() click to toggle source

Returns true if @x > @y.

# File lib/locationclass.rb, line 29
def highest_value_x?()
        return @x > @y
end
highest_value_y?() click to toggle source

Returns true if @y > @x.

# File lib/locationclass.rb, line 33
def highest_value_y?()
        return @y > @x
end
lowest_value_x?() click to toggle source

Returns true unless @x > @y.

# File lib/locationclass.rb, line 37
def lowest_value_x?()
        return !highest_value_x?()
end
lowest_value_y?() click to toggle source

Returns true unless @y > @x.

# File lib/locationclass.rb, line 41
def lowest_value_y?()
        return !highest_value_y?()
end
move(x, y) click to toggle source

Increases the x and y by the given amounts.

# File lib/locationclass.rb, line 13
def move(x, y)
        @x += x
        @y += y
end
moveNeg(x, y) click to toggle source

Decreases the x and y by the given amounts.

# File lib/locationclass.rb, line 18
def moveNeg(x, y)
        @x -= x
        @y -= y
end
moveTo(x, y) click to toggle source

Moves the location to the specified values.

# File lib/locationclass.rb, line 23
def moveTo(x, y)
        @x = x
        @y = y
end