Class: Maze

Inherits:
Object
  • Object
show all
Includes:
PlaceBlocks, UpdateMap
Defined in:
lib/vg_tools.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options_hash={})
  extend CheckingMethods unless options_hash[:checking_methods] == false
  extend MoveMethods unless options_hash[:move_methods] == false
  @character = options_hash[:character] || "$ ".yellow
  @target = options_hash[:target] || "@ ".yellow
  @current_square = options_hash[:starting_player_location] ? check_coordinates("player", options_hash[:starting_player_location],options_hash[:map]) : [1,1]
  @target_location = options_hash[:target_location] ? check_coordinates("target", options_hash[:target_location],options_hash[:map]) : [7,11]
  @map = build_map(options_hash[:map])
  add_many_blocks(options_hash[:blocks],false) if options_hash[:blocks]
  @not_finished = true
  @error_message = @winner = false
  @settings = options_hash
end

Instance Attribute Details

#characterObject

Returns the value of attribute character.



16
17
18
# File 'lib/vg_tools.rb', line 16

def character
  @character
end

#current_squareObject

Returns the value of attribute current_square.



16
17
18
# File 'lib/vg_tools.rb', line 16

def current_square
  @current_square
end

#error_messageObject

Returns the value of attribute error_message.



16
17
18
# File 'lib/vg_tools.rb', line 16

def error_message
  @error_message
end

#mapObject

Returns the value of attribute map.



16
17
18
# File 'lib/vg_tools.rb', line 16

def map
  @map
end

#not_finishedObject

Returns the value of attribute not_finished.



16
17
18
# File 'lib/vg_tools.rb', line 16

def not_finished
  @not_finished
end

#presenting_mapObject

Returns the value of attribute presenting_map.



16
17
18
# File 'lib/vg_tools.rb', line 16

def presenting_map
  @presenting_map
end

#targetObject

Returns the value of attribute target.



16
17
18
# File 'lib/vg_tools.rb', line 16

def target
  @target
end

#target_locationObject

Returns the value of attribute target_location.



16
17
18
# File 'lib/vg_tools.rb', line 16

def target_location
  @target_location
end

#winnerObject

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(options_hash={})
  game_session = self.new(options_hash)
  unless options_hash[: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

Yields:

  • (_self)

Yield Parameters:

  • _self (Maze)

    the object that the method was called on



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