194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/ruby-tic-tac-toe.rb', line 194
def check_game(next_turn)
game_over = nil
@columns.each do |column|
if times_in_column(column, @cpu) == 3
put_line
draw_game
put_line
puts ""
puts " Game Over -- #{@cpu_name} WINS!!!\n".blue
game_over = true
@cpu_score += 1
ask_to_play_again(false)
end
if times_in_column(column, @user) == 3
put_line
draw_game
put_line
puts ""
puts " Game Over -- #{@user_name} WINS!!!\n".blue
game_over = true
@user_score += 1
ask_to_play_again(true)
end
end
unless game_over
if(moves_left > 0)
if(next_turn == @user)
user_turn
else
cpu_turn
end
else
put_line
draw_game
put_line
puts ""
puts " Game Over -- DRAW!\n".blue
ask_to_play_again(rand() > 0.5)
end
end
end
|