|
1 package app |
|
2 |
|
3 import scalatags.Text.all._ |
|
4 import scala.util.Random |
|
5 |
|
6 |
|
7 object MinimalApplication extends cask.MainRoutes{ |
|
8 |
|
9 val bootstrap = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.css" |
|
10 |
|
11 var x = Random.between(0, 7) |
|
12 var y = Random.between(0, 7) |
|
13 var z = Random.between(0, 7) |
|
14 |
|
15 abstract class Answer |
|
16 case object No extends Answer |
|
17 case object Correct extends Answer |
|
18 case class Wrong(n: Int) extends Answer |
|
19 |
|
20 var ans : Answer = No |
|
21 var cnt = 1 |
|
22 |
|
23 val heart = raw("❤️") |
|
24 val unicorn = raw("🦄") |
|
25 |
|
26 var nms = List("Christiane", "Sebastian") |
|
27 |
|
28 @cask.get("/") |
|
29 def hello() = |
|
30 doctype("html")( |
|
31 html( |
|
32 head(link(rel := "stylesheet", href := bootstrap)), |
|
33 body( |
|
34 div(cls := "container")( |
|
35 //h1(s"Hello ${nms((cnt / 3) % 2)}!"), |
|
36 h1(s"Hello Christiane"), |
|
37 h1(s"$x + $y = ??"), |
|
38 ans match { |
|
39 case No => "" |
|
40 case Correct => i(color.green)("Correct!") |
|
41 case Wrong(n) => i(color.red)(s"$n is wrong!") |
|
42 }, |
|
43 form(action := "/", method := "post")( |
|
44 frag( |
|
45 for (i <- 0 to 12) yield button(`type` := "submit", name := "name", value := i.toString)(i.toString) |
|
46 ) |
|
47 ), |
|
48 frag( |
|
49 for (i <- 0 until cnt) yield |
|
50 if ((i + 1) % 10 != 0) heart else unicorn |
|
51 ) |
|
52 ) |
|
53 ) |
|
54 ) |
|
55 ) |
|
56 |
|
57 @cask.postForm("/") |
|
58 def answer(name: String) = { |
|
59 if (x + y == name.toInt) { |
|
60 ans = Correct |
|
61 x = Random.between(0, 7) |
|
62 y = Random.between(0, 7) |
|
63 z = Random.between(0, 7) |
|
64 cnt = cnt + 1 |
|
65 } |
|
66 else |
|
67 ans = Wrong(name.toInt) |
|
68 hello() |
|
69 } |
|
70 |
|
71 initialize() |
|
72 } |