feat(14): setting up result message with data
i think i should be able to make it appear with delay just with css (and that would also mean that my initial delayed call to get house choice is also not necessary, but oh well, this is still nice practice)
This commit is contained in:
parent
02a5f41800
commit
4e1f4f4a8e
|
@ -96,7 +96,8 @@
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<div id="house-choice"
|
||||
<div
|
||||
id="house-choice"
|
||||
class="flex relative flex-col items-center pt-14"
|
||||
>
|
||||
<!-- Here will be imported fragment -->
|
||||
|
@ -133,12 +134,18 @@
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<!-- FRAGMENT : showdown result -->
|
||||
<section
|
||||
id="message"
|
||||
class="flex flex-col items-center text-white"
|
||||
th:classappend="${gameFinished} ? '' : 'invisible'"
|
||||
th:classappend="${showdownState.gameResult.nonEmpty} ? '' : 'invisible'"
|
||||
>
|
||||
<p class="text-6xl tracking-wide text-center uppercase">You lose</p>
|
||||
<p
|
||||
class="text-6xl tracking-wide text-center uppercase"
|
||||
th:text="${showdownState.gameResult.nonEmpty} ? 'You ' + ${showdownState.gameResult.get} : 'awesome'"
|
||||
>
|
||||
You lose
|
||||
</p>
|
||||
<button
|
||||
class="mt-6 w-9/12 h-12 tracking-widest uppercase bg-white rounded-xl text-radial-gradient-bottom"
|
||||
>
|
||||
|
|
|
@ -59,21 +59,24 @@ position: absolute;
|
|||
sealed trait Choice {
|
||||
def name: String
|
||||
def iconPath: String
|
||||
def isBeating: Set[Choice]
|
||||
}
|
||||
object Choice {
|
||||
case object Paper extends Choice {
|
||||
def name: String = "paper"
|
||||
def iconPath: String = "public/images/icon-paper.svg"
|
||||
def isBeating: Set[Choice] = Set(Rock)
|
||||
}
|
||||
case object Scissors extends Choice {
|
||||
def name: String = "scissors"
|
||||
def iconPath: String = "public/images/icon-scissors.svg"
|
||||
def isBeating: Set[Choice] = Set(Paper)
|
||||
}
|
||||
case object Rock extends Choice {
|
||||
def name: String = "rock"
|
||||
def iconPath: String = "public/images/icon-rock.svg"
|
||||
def isBeating: Set[Choice] = Set(Rock)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** this will be Data Transfer Object, because Thymeleaf wants var and i want
|
||||
|
@ -110,13 +113,16 @@ position: absolute;
|
|||
var houseChoice: Option[ChoiceBadge],
|
||||
var gameEnded: Boolean
|
||||
) {
|
||||
def isPlayerVictorious(): Option[Boolean] = {
|
||||
def gameResult: Option[String] = {
|
||||
houseChoice.map(houseSelectedChoice => {
|
||||
val player = playersChoice.c
|
||||
val house = houseSelectedChoice.c
|
||||
false
|
||||
if (player == house) {
|
||||
"tied"
|
||||
} else if (player.isBeating(house)) {
|
||||
"won"
|
||||
} else "lose"
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue