-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdungeon.rb
151 lines (118 loc) · 3.5 KB
/
dungeon.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
=begin
/*Struct were changed for entire class due they change their objects
Player = Struct.new(:name, :location)
Room = Struct.new(:reference, :name, :description, :connections)
=end
class Dungeon
attr_accessor :player
def initialize(player_name)
@player = Player.new(player_name)
@rooms = []
end
#This add a new Room to @rooms array
def add_room(reference, name, description, connections)
@rooms << Room.new(reference, name, description, connections)
end
#This make the dungeon work
def start(location)
@player.location = location
show_current_description
end
def show_current_description
puts find_room_in_dungeon(@player.location).full_description
end
def find_room_in_dungeon(reference)
@rooms.detect { |room| room.reference == reference }
end
def find_room_in_direction(direction)
find_room_in_dungeon(@player.location).connections[direction]
end
def go(direction)
puts "You go " + direction.to_s
@player.location = find_room_in_direction(direction)
show_current_description
end
class Gretting
def game_init
gretting = puts "Elf: Wellcome strainger do you have any name ?\n"
puts "Yes my name is .. :"
@name = gets.chomp!.capitalize
while @name.length <= 0
puts "Elf: What is your name strainger:\n"
@name = gets.chomp!.capitalize
end
puts "\nElf: So your name is #{@name} uuhh!, dude! do have any idea of where on earth are you?, this isn't a place for racional people, best if you run away...\n "
early_choise = false
while early_choise == false
puts "What you wanna do ?\n"
puts "1. Leave"
puts "2. Keep on"
option = gets.chomp.to_i
if option == 1
puts "You: OMG! i didn't notice, see ya! faggot"
puts "Game Over"
early_choise = true
exit
elsif option == 2
puts "You: Shut up, and get out of my way!"
early_choise = true
end
end
puts "Elf: Well done strainger!, it's time to chose your class\n"
end
end
class Player
attr_accessor :name, :location
def initialize(name)
@name = name
end
def type_player
player_class_choise = false
while player_class_choise == false
puts "#{@name}, you must chose a class !"
puts "1. Warrior"
puts "2. Wizzard"
puts "3. Dwarf"
warrior_choise = gets.chomp.to_i
case warrior_choise
when 1
puts "You are a Human, class warrior"
player_class_choise = true
when 2
puts "You are an Elf, class wizzard"
player_class_choise = true
when 3
puts "You are a Dwarf, class support"
player_class_choise = true
else
"unknown"
end
end
end
end
class Room
attr_accessor :reference, :name, :description, :connections
def initialize(reference, name, description, connections)
@reference = reference
@name = name
@description = description
@connections = connections
end
def full_description
@name + "\n\nYou are in " + @description
end
end
end
#Dialog when game just start
gretting = Dungeon::Gretting.new
gretting.game_init
#Player Chose their class *pls check dialog that clash
new_player = Dungeon::Player.new("#{@name}")
puts new_player.type_player
# Create the main dungeon object
my_dungeon = Dungeon.new("#{@name}")
# Add rooms to the dungeon
my_dungeon.add_room(:largecave, "Large Cave", "a large cavernous cave", { :west => :smallcave })
my_dungeon.add_room(:smallcave, "Small Cave", "a small, claustrophobic cave", { :east => :largecave })
# Start the dungeon by placing the player in the large cave
my_dungeon.start(:largecave)