-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.rb
More file actions
209 lines (191 loc) · 6.06 KB
/
controller.rb
File metadata and controls
209 lines (191 loc) · 6.06 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
require_relative 'deck'
require_relative 'dealer'
require_relative 'gamer'
# game_deck = Deck.new
# user = User.new('vasya', game_deck)
# p user.user_cards
# p user.money
# p user.points
puts "
─────────────────────────────
─────────────▐█▌─────────────
─────────────▐░▌─────────────
─────────────▐░▌─────────────
─────────────▐░▌─────────────
──────────▄▄▀░░░▀▄▄──────────
────────▄▀░░░░░░░░░▀▄────────
──────▄▀░░░░░░░░░░░░░▀▄──────
─────▐░░░░░░░░░░░░░░░░░▌─────
────▐░░░░░░░░░░░░░░░░░░░▌────
───▐░░░░░░░░░░░░░░░░░░░░░▌───
───▐░░░░░░░░░░░░░░░░░░░░░▌───
───▐░░░░░░░░░░░░░░░░░░░░░▌───
───▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌───
──▄███████████████████████▄──
─████▀────▀███████▀────▀███▄─
─███▀───────█████────────███─
─███───███───███───███───███─
─███───▀▀▀───███───▀▀▀───███─
─▀███▄─────▄█████▄─────▄███▀─
──▀███████████████████████▀──
───▐░░░░░░░░░░░░░░░░░░░░░▌───
───▐░░░░░░░░░░░░░░░░░░░░░▌───
───▐░▄▀▀█▀▀█▀▀█▀▀█▀▀█▀▀▄░▌───
───▐░█▄▄█▄▄█▄▄█▄▄█▄▄█▄▄█░▌───
───▐░█──█──█──█──█──█──█░▌───
───▐░█▀▀█▀▀█▀▀█▀▀█▀▀█▀▀█░▌───
───▐░▀▄▄█▄▄█▄▄█▄▄█▄▄█▄▄▀░▌───
───▐░░░░░░░░░░░░░░░░░░░░░▌───
───▐░░░░░░░░░░░░░░░░░░░░░▌───
────▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀────"
def init_game(username)
@deck = Deck.new
@hand = Hand.new(@deck)
@player = Gamer.new(username, @hand)
@dealer = Dealer.new('Bender', @hand)
end
def restart_game
@deck.create
@player.new_game
@dealer.new_game
no_money_rescue
end
def no_money_rescue
rescue => e
puts e.message
puts <<~TEXT
New game?
1) - yes
2) - no
TEXT
loop do
user_input = gets.chomp.to_i
case user_input
when 1
@player.money = 100
restart_game
break
when 2
abort("Go home, baby")
else
puts "enter right num (1 or 2)"
end
end
end
def print_status
puts "Check your cards:"
@player.print_cards
puts "Check your points:"
puts @player.points
puts "Dealer cards: #{"* " * @dealer.cards.size}"
end
def user_check
if @player.check_available
@player.check
puts "Player checks..."
if @dealer.play?
@dealer.get_card()
puts "Dealer got one card..."
else
puts "Dealer checks..."
end
else
puts "You lost your check"
end
end
def user_get_card
@player.get_card()
print_status
rescue => e
puts e.message
end
def draw
puts "DRAW"
@player.add_money(10)
@dealer.add_money(10)
end
def user_wins
puts "#{@player.name} wins with #{@player.points} points against #{@dealer.name}'s #{@dealer.points} points"
@player.add_money
end
def dealer_wins
puts "#{@dealer.name} wins with #{@dealer.points} points against #{@player.name}'s #{@player.points} points"
@dealer.add_money
end
def user_open_cards
# if @dealer.points > 21 && @player.points > 21
# draw
# elsif @player.points > 21 || @dealer.points > 21
# if @player.points > 21
# dealer_wins
# else
# user_wins
# end
# elsif @player.points > @dealer.points
# user_wins
# elsif @player.points == @dealer.points
# draw
# elsif @dealer.points > @player.points
# dealer_wins
# end
puts "Dealer cards: "
@dealer.print_cards
if @player.points < 21 && @dealer.points <21 && @dealer.points == @player.points
draw
elsif @player.points <= 21 && @player.points > @dealer.points
user_wins
elsif @dealer.points <= 21 && @dealer.points > @player.points
dealer_wins
elsif @dealer.points > 21 && @player.points > 21
puts "All players lost"
end
end
def ask_for_restart
puts "your money: #{@player.money}"
puts <<~TEXT
One more time?
1) - yes
2) - no
TEXT
loop do
user_input = gets.chomp.to_i
case user_input
when 1
restart_game
break
when 2
abort("Go home, baby")
else
puts "enter right num (1 or 2)"
end
end
end
puts "Welcome to Bender's Black Jack room.
Rules:
1) At first you need to put your name
2) Then game will be started. Enjoy!
3) If you want go to your mom, put 'exit'
Put your name:"
user_input = gets.chomp
abort("Go home, baby") if user_input == 'exit'
puts "You have 100$"
init_game(user_input)
loop do
print_status
puts <<~TEXT
Choose an action:
1) Check
2) Take card
3) Open cards
TEXT
user_input = gets.chomp.to_i
case user_input
when 1
user_check
when 2
user_get_card
when 3
user_open_cards
ask_for_restart
end
end