class Rbfunge::Program

Attributes

direction[RW]

Public Class Methods

new() click to toggle source
# File lib/rbfunge/program.rb, line 6
def initialize
        @program = []
        @current_x = 0
        @current_y = 0
        @direction = :right
end

Public Instance Methods

get(x, y) click to toggle source
# File lib/rbfunge/program.rb, line 45
def get(x, y)
        @program[y][x]
end
get_current() click to toggle source
# File lib/rbfunge/program.rb, line 49
def get_current
        get(@current_x, @current_y)
end
load_code(code) click to toggle source
# File lib/rbfunge/program.rb, line 13
def load_code(code)
        line_array = code.split("\n")
        25.times do
                line = line_array.shift
                line = pad_line(line)
                byte_array = []
                line.each_byte { |b| byte_array << b}
                @program << byte_array
        end
end
move() click to toggle source
# File lib/rbfunge/program.rb, line 32
def move
        case @direction
        when :right
                @current_x = (@current_x + 1) % 80
        when :left
                @current_x = (@current_x - 1) % 80
        when :up
                @current_y = (@current_y - 1) % 25
        when :down
                @current_y = (@current_y + 1) % 25
        end
end
pad_line(line) click to toggle source
# File lib/rbfunge/program.rb, line 24
def pad_line(line)
        if line.nil?
                padded_line = "".ljust(80)
        else
                padded_line = line[0..79].ljust(80)
        end
end
put(x, y, value) click to toggle source
# File lib/rbfunge/program.rb, line 53
def put(x, y, value)
        @program[x][y] = value
end