-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
app.rb
64 lines (53 loc) · 1.66 KB
/
app.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
require 'sinatra/base'
require 'sinatra/flash'
require_relative 'lib/wordguesser_game'
class WordGuesserApp < Sinatra::Base
enable :sessions
register Sinatra::Flash
before do
@game = session[:game] || WordGuesserGame.new('')
end
after do
session[:game] = @game
end
# These two routes are good examples of Sinatra syntax
# to help you with the rest of the assignment
get '/' do
redirect '/new'
end
get '/new' do
erb :new
end
post '/create' do
# NOTE: don't change next line - it's needed by autograder!
word = params[:word] || WordGuesserGame.get_random_word
# NOTE: don't change previous line - it's needed by autograder!
@game = WordGuesserGame.new(word)
redirect '/show'
end
# Use existing methods in WordGuesserGame to process a guess.
# If a guess is repeated, set flash[:message] to "You have already used that letter."
# If a guess is invalid, set flash[:message] to "Invalid guess."
post '/guess' do
params[:guess].to_s[0]
### YOUR CODE HERE ###
redirect '/show'
end
# Everytime a guess is made, we should eventually end up at this route.
# Use existing methods in WordGuesserGame to check if player has
# won, lost, or neither, and take the appropriate action.
# Notice that the show.erb template expects to use the instance variables
# wrong_guesses and word_with_guesses from @game.
get '/show' do
### YOUR CODE HERE ###
erb :show # You may change/remove this line
end
get '/win' do
### YOUR CODE HERE ###
erb :win # You may change/remove this line
end
get '/lose' do
### YOUR CODE HERE ###
erb :lose # You may change/remove this line
end
end