implement restart game

master
Peter Babič 3 years ago
parent 2f33323f54
commit 6c3ff2b904
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 24
      src/App.svelte

@ -3,6 +3,7 @@
</script> </script>
<script> <script>
import { onMount } from "svelte"
const pole = 0 const pole = 0
const hole = 1 const hole = 1
const pick = 2 const pick = 2
@ -13,6 +14,12 @@
let circles = [] let circles = []
let playing = true let playing = true
let bold = false
const restart = () => {
circles = []
playing = true
bold = false
const numCircles = 15 const numCircles = 15
for (let i = 0; i < numCircles; i++) { for (let i = 0; i < numCircles; i++) {
@ -62,6 +69,7 @@
jumps.addEdge(9, 11) jumps.addEdge(9, 11)
jumps.addEdge(9, 14) jumps.addEdge(9, 14)
jumps.addEdge(11, 14) jumps.addEdge(11, 14)
}
const commonBetween = (a, b) => const commonBetween = (a, b) =>
adjcs.adjacencyList[a].filter(common => adjcs.adjacencyList[a].filter(common =>
@ -120,6 +128,7 @@
if (hints.length == 0) { if (hints.length == 0) {
playing = false playing = false
bold = true
} }
return return
@ -130,6 +139,8 @@
clearDests() clearDests()
} }
} }
onMount(() => restart())
</script> </script>
<style> <style>
@ -212,13 +223,24 @@
background-color: blue; background-color: blue;
} }
.restart {
cursor: pointer;
}
.playing { .playing {
visibility: hidden; visibility: hidden;
} }
.bold {
font-weight: bold;
}
</style> </style>
<main> <main>
<div class:playing>GAME OVER</div> <div>
<span class="restart" class:bold on:click={restart}>RESTART GAME</span>
<span class:playing> | GAME OVER</span>
</div>
<div class="triangle"> <div class="triangle">
{#each circles as _, i} {#each circles as _, i}
<div <div

Loading…
Cancel
Save