-
Notifications
You must be signed in to change notification settings - Fork 0
/
heads_tails.rb
69 lines (62 loc) · 1.34 KB
/
heads_tails.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
class HeadsTails
attr_accessor :player
def initialize(player)
@player = player
heads_tails
end
def heads_tails
puts "Welcome to Heads and Tails!"
@coin = ["heads", "tails"
]
puts "select heads or tails"
users_guess = gets.strip
betting
case users_guess
when "heads"
if @coin.sample == users_guess
puts "YOU WIN!"
@player.win(@bet)
else
puts "you lose..."
@player.lose(@bet)
end
play_again
when "tails"
if @coin.sample == users_guess
puts "YOU WIN!"
@player.win(@bet)
else
puts "you lose..."
@player.lose(@bet)
end
play_again
else
puts "invalid option"
end
end
def play_again
puts "would you like to play again? (y/n)"
selection = gets.strip
case selection
when "y"
heads_tails
when "n"
restart = Casino.new(@player)
restart.main_menu
else
puts "invalid option"
play_again
end
end
def betting
puts "You currently have #{@player.wallet.money}"
puts "How much would you like to bet?"
@bet = gets.to_i
if @bet > @player.wallet.money
puts "YOU BROKE BRO TRY AGAIN"
betting
end
return @player
return @bet
end
end