-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.rb
More file actions
74 lines (61 loc) · 1.6 KB
/
Copy pathgame.rb
File metadata and controls
74 lines (61 loc) · 1.6 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require_relative 'world.rb'
class Game
attr_accessor :world,:input,:command,:command_list
def initialize(readin=STDIN, output=STDOUT, xml_file_path)
@input = readin
@output = output
@world = World.new(xml_file_path)
@command_list = []
end
def get_command
if(@command_list.length==0)
temp_command = @input.gets
temp_command.chomp!
@command = temp_command
else
@command = @command_list.sample
end
end
def user_turn
@world.grue.determine_next_move(@world.user.current_room)
@world.grue.grue_close_check
get_command
while(!@world.user.user_move(@command))
get_command
end
if(@world.grue.current_room.title == @world.user.current_room.title)
@world.grue.grue_attacked
@world.user.pick_up_crystal
end
end
def grue_turn
@world.grue.grue_close_check
@world.grue.move_grue_to_user(@world.user.current_room)
if(@world.grue.current_room.title == @world.user.current_room.title)
@world.user.user_attacked
end
end
def resting_turn
puts " "
puts "~~~~Resting~~~~"
puts " "
end
def loop
turns = 0
# Game loop runs as long as user hasnt won or quit yet.
while (@command != "quit" && !@world.user.userWon)
# Every 4 turns take a rest and move grue.
if(turns%4==0 && turns!=0)
resting_turn
turns =0
grue_turn
else
user_turn
turns= turns+1
end
end
if(@world.user.userWon)
puts "Congratulations you win!!"
end
end
end