Class: CodeMap
- Inherits:
-
Object
- Object
- CodeMap
- Defined in:
- lib/code_map.rb
Overview
This class is reponsible for keeping the befunge code. It will output the current operation the pointer is at, and also set and get operations based on coordinates. CodeMap#print_map will be used for animation and debuggin modes.
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#map ⇒ Object
readonly
Returns the value of attribute map.
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #get_operation ⇒ Object
- #get_operation_at(x, y) ⇒ Object
-
#initialize(file) ⇒ CodeMap
constructor
A new instance of CodeMap.
- #print_map ⇒ Object
- #set_operation_at(x, y, op) ⇒ Object
Constructor Details
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/code_map.rb', line 6 def height @height end |
#map ⇒ Object (readonly)
Returns the value of attribute map.
6 7 8 |
# File 'lib/code_map.rb', line 6 def map @map end |
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
6 7 8 |
# File 'lib/code_map.rb', line 6 def pointer @pointer end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/code_map.rb', line 6 def width @width end |
Instance Method Details
#get_operation ⇒ Object
13 14 15 |
# File 'lib/code_map.rb', line 13 def get_operation @map[@pointer.y][@pointer.x] end |
#get_operation_at(x, y) ⇒ Object
21 22 23 |
# File 'lib/code_map.rb', line 21 def get_operation_at(x, y) @map[y][x] end |
#print_map ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/code_map.rb', line 25 def print_map system 'clear' @map.each_with_index do |line, i| line.each_with_index do |char, j| if @pointer.x == j && @pointer.y == i print char.colorize(background: :red) else print char end end print "\n" end end |
#set_operation_at(x, y, op) ⇒ Object
17 18 19 |
# File 'lib/code_map.rb', line 17 def set_operation_at(x, y, op) @map[y][x] = op end |