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:
efim 2023-07-02 06:01:00 +00:00
parent 02a5f41800
commit 4e1f4f4a8e
2 changed files with 21 additions and 8 deletions

View File

@ -96,8 +96,9 @@
</p> </p>
</div> </div>
<div id="house-choice" <div
class="flex relative flex-col items-center pt-14" id="house-choice"
class="flex relative flex-col items-center pt-14"
> >
<!-- Here will be imported fragment --> <!-- Here will be imported fragment -->
<!-- conditionally either house choice or request for house choice --> <!-- conditionally either house choice or request for house choice -->
@ -133,12 +134,18 @@
</div> </div>
</section> </section>
<!-- FRAGMENT : showdown result -->
<section <section
id="message" id="message"
class="flex flex-col items-center text-white" 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 <button
class="mt-6 w-9/12 h-12 tracking-widest uppercase bg-white rounded-xl text-radial-gradient-bottom" class="mt-6 w-9/12 h-12 tracking-widest uppercase bg-white rounded-xl text-radial-gradient-bottom"
> >

View File

@ -59,21 +59,24 @@ position: absolute;
sealed trait Choice { sealed trait Choice {
def name: String def name: String
def iconPath: String def iconPath: String
def isBeating: Set[Choice]
} }
object Choice { object Choice {
case object Paper extends Choice { case object Paper extends Choice {
def name: String = "paper" def name: String = "paper"
def iconPath: String = "public/images/icon-paper.svg" def iconPath: String = "public/images/icon-paper.svg"
def isBeating: Set[Choice] = Set(Rock)
} }
case object Scissors extends Choice { case object Scissors extends Choice {
def name: String = "scissors" def name: String = "scissors"
def iconPath: String = "public/images/icon-scissors.svg" def iconPath: String = "public/images/icon-scissors.svg"
def isBeating: Set[Choice] = Set(Paper)
} }
case object Rock extends Choice { case object Rock extends Choice {
def name: String = "rock" def name: String = "rock"
def iconPath: String = "public/images/icon-rock.svg" 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 /** this will be Data Transfer Object, because Thymeleaf wants var and i want
@ -110,13 +113,16 @@ position: absolute;
var houseChoice: Option[ChoiceBadge], var houseChoice: Option[ChoiceBadge],
var gameEnded: Boolean var gameEnded: Boolean
) { ) {
def isPlayerVictorious(): Option[Boolean] = { def gameResult: Option[String] = {
houseChoice.map(houseSelectedChoice => { houseChoice.map(houseSelectedChoice => {
val player = playersChoice.c val player = playersChoice.c
val house = houseSelectedChoice.c val house = houseSelectedChoice.c
false if (player == house) {
"tied"
} else if (player.isBeating(house)) {
"won"
} else "lose"
}) })
} }
} }
} }