-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.rb
43 lines (34 loc) · 918 Bytes
/
game.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
class Game
attr_reader :won
def initialize(winning_position, players, portal_hash)
@players = players
@portal_hash = portal_hash
@winning_position = winning_position
@won = false
end
def next_player
selected_player = @players.shift
@players << selected_player
return selected_player
end
def check_position_portal_hash(player)
portal = @portal_hash[player.position]
if portal == nil
return player.position
else
portal_length = portal.length
player.modify_position(portal_length)
end
end
def check_winning_position(player)
@won = true if player.position >= @winning_position
return player.position >= @winning_position
end
def step
player = next_player()
roll_amount = player.roll_dice
player.modify_position(roll_amount)
check_winning_position(player)
check_position_portal_hash(player)
end
end