-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhouse.rb
More file actions
60 lines (53 loc) · 1.55 KB
/
house.rb
File metadata and controls
60 lines (53 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Outline
# Room Class
# => Look around in Room
# => Go to other room in certain direction
# => Look at objects in Room
require "./house_game_objects.rb"
require "./house_commands.rb"
require "./house_rooms.rb"
# This is the prompt where players type their commands. It displays the current room name and sends commands to the evaluate method
def prompt
include Commands
print "[#{$current_room.name}]:>"
command = gets.chomp.downcase
# split the command so we have seperate word and params
command = command.split(' ')
# grab the first word and define it as the word of the command
command_word = command.shift
# and the rest of the command is one or more parameters
command_params = command
evaluate(command_word, command_params)
end
# Here the commands are evaluated and (if necessary) sent to the appropriate method
def evaluate(command_word, command_params)
case command_word
when "q", "quit"
puts "Bye, bye!"
return
when "look"
look($current_room, command_params)
when "go"
go($current_room, command_params)
when "get"
get($current_room, command_params)
when "i", "inventory"
inventory
when "use"
use($current_room, command_params)
else
puts "I don't understand #{command_params}"
end
prompt
end
# Calling the methods to create the rooms and objects and set the directions
create_objects
create_object_actions
create_rooms
set_directions
# Define the first room the game starts in
$current_room = $room1
# Creating an empty inventory array
$inventory = {}
# Start the game by running the prompt
prompt