Class: Maze
Instance Attribute Summary collapse
-
#character ⇒ Object
Returns the value of attribute character.
-
#current_square ⇒ Object
Returns the value of attribute current_square.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#map ⇒ Object
Returns the value of attribute map.
-
#not_finished ⇒ Object
Returns the value of attribute not_finished.
-
#presenting_map ⇒ Object
Returns the value of attribute presenting_map.
-
#target ⇒ Object
Returns the value of attribute target.
-
#target_location ⇒ Object
Returns the value of attribute target_location.
-
#winner ⇒ Object
Returns the value of attribute winner.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options_hash = {}) ⇒ Maze
constructor
A new instance of Maze.
- #play {|_self| ... } ⇒ Object
Methods included from PlaceBlocks
#add_block, #add_many_blocks, #print_settings, #remove_block, #remove_many_blocks
Methods included from UpdateMap
#place_character, #print_map, #reset_map, #reset_screen, #update_and_print
Constructor Details
#initialize(options_hash = {}) ⇒ Maze
Returns a new instance of Maze.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vg_tools.rb', line 26 def initialize(={}) extend CheckingMethods unless [:checking_methods] == false extend MoveMethods unless [:move_methods] == false @character = [:character] || "$ ".yellow @target = [:target] || "@ ".yellow @current_square = [:starting_player_location] ? check_coordinates("player", [:starting_player_location],[:map]) : [1,1] @target_location = [:target_location] ? check_coordinates("target", [:target_location],[:map]) : [7,11] @map = build_map([:map]) add_many_blocks([:blocks],false) if [:blocks] @not_finished = true @error_message = @winner = false @settings = end |
Instance Attribute Details
#character ⇒ Object
Returns the value of attribute character.
16 17 18 |
# File 'lib/vg_tools.rb', line 16 def character @character end |
#current_square ⇒ Object
Returns the value of attribute current_square.
16 17 18 |
# File 'lib/vg_tools.rb', line 16 def current_square @current_square end |
#error_message ⇒ Object
Returns the value of attribute error_message.
16 17 18 |
# File 'lib/vg_tools.rb', line 16 def @error_message end |
#map ⇒ Object
Returns the value of attribute map.
16 17 18 |
# File 'lib/vg_tools.rb', line 16 def map @map end |
#not_finished ⇒ Object
Returns the value of attribute not_finished.
16 17 18 |
# File 'lib/vg_tools.rb', line 16 def not_finished @not_finished end |
#presenting_map ⇒ Object
Returns the value of attribute presenting_map.
16 17 18 |
# File 'lib/vg_tools.rb', line 16 def presenting_map @presenting_map end |
#target ⇒ Object
Returns the value of attribute target.
16 17 18 |
# File 'lib/vg_tools.rb', line 16 def target @target end |
#target_location ⇒ Object
Returns the value of attribute target_location.
16 17 18 |
# File 'lib/vg_tools.rb', line 16 def target_location @target_location end |
#winner ⇒ Object
Returns the value of attribute winner.
16 17 18 |
# File 'lib/vg_tools.rb', line 16 def winner @winner end |
Class Method Details
.session(options_hash = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vg_tools.rb', line 40 def self.session(={}) game_session = self.new() unless [:skip_intro] dots = "" 4.times do game_session.reset_screen puts "Starting New Session#{dots}" sleep 0.6 dots += "." end game_session.reset_screen puts <<-oview Game Created ========================================= Charater: #{game_session.character} Starting Space: Row: #{game_session.current_square[0]} Col: #{game_session.current_square[1]} Target: #{game_session.target} Target Location: Row: #{game_session.target_location[0]} Col: #{game_session.target_location[1]} ========================================= oview game_session.reset_map game_session.place_character game_session.print_map sleep 2 end game_session end |
Instance Method Details
#play {|_self| ... } ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vg_tools.rb', line 74 def play # reset_screen; start_time = Time.now.to_f yield(self) end_time = Time.now.to_f time_difference = (end_time - start_time).round(3) # minutes = time_difference / 60 # seconds = time_difference % 60 # total_time = "" # total_time += "#{minutes} Minute" if minutes > 0 # total_time += "s" if minutes > 1 # total_time += ", " if minutes > 0 && seconds > 0 # total_time += "#{seconds} Second" if seconds > 0 # total_time += "s" if seconds > 1 puts "Total Time: #{time_difference}" end |