This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
forked from thestrabusiness/Adventure_Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld.rb
62 lines (49 loc) · 1.49 KB
/
world.rb
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
61
62
class World
WORLD_WIDTH = 10
WORLD_HEIGHT = 10
def initialize
@rooms = Array.new(WORLD_HEIGHT, Array.new(WORLD_WIDTH)) #create a WORLD_HIGHT*WORLD_WIDTH 2d array to represent world
end
def move_north(player)
player.y_pos -= 1 if player.y_pos > 0 else puts "You can't go that way"
end
def move_south(player)
player.y_pos += 1 if player.y_pos < WORLD_HEIGHT - 1 else puts "You can't go that way"
end
def move_east(player)
player.x_pos += 1 if player.x_pos < WORLD_WIDTH - 1 else puts "You can't go that way"
end
def move_west(player)
player.x_pos -= 1 if player.x_pos > 0 else puts "You can't go that way"
end
def get_room_of(player)
@rooms[player.x_pos][player.y_pos] ||= Room.new #access existing room at player's X,Y coordinates or create new one if it doesn't exist yet.
end
end
class Room
attr_accessor :size, :content
def initialize
@content = set_room_content
@size = set_room_size
@adjective = describe
end
def interact(player)
if @content
@content.interact(player)
@content = nil
end
end
def to_s
"You are in a #{@size} room. It is #{@adjective}."
end
private
def set_room_content
[Monster, Sword, Potion, Armor].sample(random: Random.new).new
end
def set_room_size
["small", "medium", "large", "square", "long", "tall", "circular"].sample(random: Random.new)
end
def desribe
["dark", "dank", "creepy", "smelly", "moldy", "sexy" ].sample(random: Random.new)
end
end