-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgame_script.rb
55 lines (41 loc) · 1015 Bytes
/
game_script.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
require 'ruby2d'
require 'byebug'
require_relative 'random_player'
require_relative 'grid'
set title: 'Matches', background: 'white'
g = Grid.new
tick = 0 # set timer to 0
time_increment = 120 # approx 2 seconds per move
p1 = RandomPlayer.new("First")
p2 = RandomPlayer.new("Second")
p1.opponent = p2.color
p2.opponent = p1.color
#simulated coin toss for first move
coin_toss = rand(2)
if coin_toss == 1
player_one = p1
player_two = p2
else
player_one = p2
player_two = p1
end
update do
if tick % time_increment == 0
if tick % (time_increment * 2) == 0
player = player_one
else
player = player_two
end
if g.winning_state?
set title: "Winner!: #{player.player_name}"
else
set title: "Player: #{player.player_name}"
column, amount = player.play_round(g)
#skip players turn if they give invalid column
next if !g.available_columns.include?(column)
g.remove_chips_from_heap( column, amount )
end
end
tick += 1
end
show