-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.rb
42 lines (30 loc) · 871 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
require 'sinatra'
require 'sinatra/reloader' if development?
require './mastermind'
p = PlayerGame.new
get '/' do
code = p.code
puts code
guesses_left = p.max_guess_count - p.guess_count
if !params['guess'].nil?
guess = params['guess'].downcase.chomp.split(" ")
if p.valid_guess(guess)
game_board = p.game_board(guess)
game_hints = p.check_guess(guess)
if p.game_over?(guess)
message = p.game_over_message(guess)
end
end
error_message = p.error_message
end
erb :index, :locals => { :game_board => game_board, :game_hints => game_hints,
:guesses_left => guesses_left, :error_message => error_message,
:message => message }
end
get "/play_again_method" do
p = PlayerGame.new
redirect '/'
end
# p = PlayerGame.new
# p.valid_guess("blue".downcase.chomp.split(" "))
# puts p.error_message