From 5b6c5d9431b352d58f7686204cea60a7417917b1 Mon Sep 17 00:00:00 2001 From: MrEidam Date: Wed, 14 Aug 2024 12:09:08 +0200 Subject: [PATCH] Dice war logic --- Games/DiceWar/main.js | 36 +++++++++++++++++++++++++++++++++--- Games/DiceWar/style.css | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/Games/DiceWar/main.js b/Games/DiceWar/main.js index fb9fe3d..bbfdb2a 100644 --- a/Games/DiceWar/main.js +++ b/Games/DiceWar/main.js @@ -53,16 +53,46 @@ function playerRoll(){ plaScore.innerHTML = playerScore; } +async function won(){ + let won = document.createElement('h1'); + won.classList.add('result', 'won'); + won.innerText = "You've won!"; + document.body.append(won); + setTimeout(() => { + won.remove(); + }, 600); +} + +async function lost(){ + let lost = document.createElement('h1'); + lost.classList.add('result', 'lost'); + lost.innerText = "You've lost!"; + document.body.append(lost); + setTimeout(() => { + lost.remove(); + }, 600); +} + +async function draw(){ + let draw = document.createElement('h1'); + draw.classList.add('result', 'draw'); + draw.innerText = "It's a draw!"; + document.body.append(draw); + setTimeout(() => { + draw.remove(); + }, 600); +} + function gamble(){ enemyRoll(); playerRoll(); setTimeout(() => { if(playerScore>enemyScore){ - alert('You won!'); + won(); }else if(playerScore