forked from kacasey8/hangperson-beta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
66 lines (53 loc) · 1.68 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
65
66
require 'sinatra/base'
require 'sinatra/flash'
require './lib/hangperson_game.rb'
class HangpersonApp < Sinatra::Base
enable :sessions
register Sinatra::Flash
before do
@game = session[:game] || HangpersonGame.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] || HangpersonGame.get_random_word
# NOTE: don't change previous line - it's needed by autograder!
@game = HangpersonGame.new(word)
redirect '/show'
end
# Use existing methods in HangpersonGame 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
letter = 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 HangpersonGame to check if player has
# won, lost, or neither, and take the appropriate action.
# Notice that the show.erb template expects to use instance variables
# @wrong_guesses and @word_with_guesses, so set those up here.
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