-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
88 lines (76 loc) · 1.84 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require "sinatra"
require "sinatra/reloader"
require "require_all"
set :port, 80
require_rel "db", "models"
def init
puts "init called"
@word = newWord().upcase
@definition = define(@word)
@list = @listOfWords
end
get "/" do
@page_name = "Guess the Word"
init()
$score = "0"
puts "[NEW GAME #{Time.now}] #{@word} : #{$score} : #{@definition}"
erb :main
end
get "/custom-game" do
@page_name = "Custom Game"
@getID = ""
erb :customword
end
get '/game' do
@page_name = "Custom Game"
custom = params[:id]
data = findCustomGame(custom)
@word = data[0]
@definition = data[1]
if @word == "notFo"
erb :pagenotfound
else
puts "[CUSTOM #{Time.now}] #{@word} : #{@definition}"
@list = File.read('words.txt').upcase.lines.map &:split
erb :custom_game
end
end
post "/" do
@page_name = "Guess the Word"
init()
$score = params["endGameButton"].to_i
puts "[CONT GAME #{Time.now}] #{@word} : #{$score} : #{@definition}"
erb :main
end
post "/custom-game" do
@page_name = "Custom Game"
@getID = generateCustomGame(params["word"], params["definition"]).to_s
erb :customword
end
get '/leaderboard' do
@page_name = "Leaderboard"
@results = sortDB()[0...10]
erb :leaderboard
end
post "/leaderboard" do
@page_name = "Leaderboard"
name = params[:name]
score = params[:score]
submitScore(name, score)
@results = sortDB()[0...10]
erb :leaderboard
end
get "/wowproject" do
@list = File.read('words.txt').upcase.lines.map &:split
@listOfWords = File.read('jobs.txt').upcase.lines.map &:split
randomNumber = rand(0..@listOfWords.length-1)
@word = @listOfWords[randomNumber].to_s[2..6]
@definition = define(@word)
@page_name = "Guess The Word - Jobs & Skills"
puts "[J&S #{Time.now}] #{@word} : #{@definition}"
erb :jobs_words
end
error 404 do
@page_name = "Guess the Word"
erb :pagenotfound
end