Skip to content

Instantly share code, notes, and snippets.

@GoSeek
Last active August 29, 2015 14:22
Show Gist options
  • Save GoSeek/3901edfcbf785ef7e2a6 to your computer and use it in GitHub Desktop.
Save GoSeek/3901edfcbf785ef7e2a6 to your computer and use it in GitHub Desktop.
Attempting to load a random room when game starts
random_room_initialize_xp1.rb:87:in `[]': no implicit conversion of Hash into Integer (TypeError)
from random_room_initialize_xp1.rb:87:in `next_scene'
from random_room_initialize_xp1.rb:92:in `opening_scene'
from random_room_initialize_xp1.rb:18:in `play'
from random_room_initialize_xp1.rb:98:in `<main>'
#http://stackoverflow.com/questions/9538090/how-can-i-filter-an-array-of-hashes-to-get-only-the-keys-in-another-array
=begin
I am currently trying to figure out how to make the game load with a random room, instead of specifiying which room it starts on
I need to exclude :death and :finished from being loading when game starts.
=end
class Engine
def initialize(start_scene)
@start_scene = start_scene
end
def play()
current_scene = @start_scene.opening_scene()
last_scene = @start_scene.next_scene(:finished)
while current_scene != last_scene
next_scene_name = current_scene.enter()
current_scene = @start_scene.next_scene(next_scene_name)
end
current_scene.enter()
end
end
class Scene
def enter()
exit(1)
end
end
class Juan < Scene
def enter()
puts "Juan scene placeholder"
return :finished
end
end
class Too < Scene
def enter()
puts "Too scene placeholder"
end
end
class Death < Scene
def enter()
puts "death scene placeholder"
end
end
class Finished < Scene
def enter()
puts "Finished scene enter"
end
end
class A1 < Scene
def enter()
puts "A1 scene"
end
end
class B2 < Scene
def enter()
puts "B2 scene"
end
end
class C3 < Scene
def enter()
puts "C3 scene"
end
end
class Map
@@scenes = [
{:one => 'Juan.new'},
{:two => 'Too.new'},
{:death => 'Death.new'},
{:finished => 'Finished.new'},
{:a1 => 'A1.new'},
{:b2 => 'B2.new'},
{:c3 => 'C3.new'}
]
def initialize
@start_scene = @@scenes.reject { |scene| [:death, :finished].any? { |game_over| scene.key? game_over } }.sample
end
def next_scene(scene_name)
val = @@scenes[scene_name]
return val
end
def opening_scene()
return next_scene(@start_scene)
end
end
selected_a_map = Map.new
loaded_a_game = Engine.new(selected_a_map)
loaded_a_game.play()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment