better message
This commit is contained in:
parent
7bfe17181d
commit
6e8689771e
38
src/Game.vue
38
src/Game.vue
@ -18,6 +18,7 @@ const board = $ref(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let message = $ref('')
|
||||||
let allowInput = true
|
let allowInput = true
|
||||||
let currentRowIndex = $ref(0)
|
let currentRowIndex = $ref(0)
|
||||||
const currentRow = $computed(() => board[currentRowIndex])
|
const currentRow = $computed(() => board[currentRowIndex])
|
||||||
@ -67,7 +68,7 @@ function completeRow() {
|
|||||||
if (currentRow.every((tile) => tile.letter)) {
|
if (currentRow.every((tile) => tile.letter)) {
|
||||||
const word = currentRow.map((tile) => tile.letter).join('')
|
const word = currentRow.map((tile) => tile.letter).join('')
|
||||||
if (!allWords.includes(word) && word !== answer) {
|
if (!allWords.includes(word) && word !== answer) {
|
||||||
alert(`"${word}" is not a valid word.`)
|
showMessage(`Not in word list`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,20 +92,36 @@ function completeRow() {
|
|||||||
if (correct) {
|
if (correct) {
|
||||||
// yay!
|
// yay!
|
||||||
allowInput = false
|
allowInput = false
|
||||||
requestIdleCallback(() => alert('yay!'))
|
showMessage(
|
||||||
|
['Genius', 'Magnificent', 'Impressive', 'Splendid', 'Great', 'Phew'][
|
||||||
|
currentRowIndex
|
||||||
|
]
|
||||||
|
)
|
||||||
} else if (currentRowIndex < board.length - 1) {
|
} else if (currentRowIndex < board.length - 1) {
|
||||||
// go the next row
|
// go the next row
|
||||||
currentRowIndex++
|
currentRowIndex++
|
||||||
} else {
|
} else {
|
||||||
// game over :(
|
// game over :(
|
||||||
allowInput = false
|
allowInput = false
|
||||||
requestIdleCallback(() => alert('oops'))
|
showMessage(answer.toUpperCase())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showMessage('Not enough letters')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showMessage(msg: string) {
|
||||||
|
message = msg
|
||||||
|
setTimeout(() => {
|
||||||
|
message = ''
|
||||||
|
}, 1000)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<Transition>
|
||||||
|
<div class="message" v-if="message">{{ message }}</div>
|
||||||
|
</Transition>
|
||||||
<header>
|
<header>
|
||||||
<h1>VVORDLE</h1>
|
<h1>VVORDLE</h1>
|
||||||
<a
|
<a
|
||||||
@ -150,6 +167,21 @@ function completeRow() {
|
|||||||
height: 420px;
|
height: 420px;
|
||||||
margin: 0px auto;
|
margin: 0px auto;
|
||||||
}
|
}
|
||||||
|
.message {
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
top: 80px;
|
||||||
|
color: #fff;
|
||||||
|
background-color: rgba(0, 0, 0, 0.85);
|
||||||
|
padding: 16px 20px;
|
||||||
|
z-index: 2;
|
||||||
|
border-radius: 8px;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
transition: opacity 0.3s ease-out;
|
||||||
|
}
|
||||||
|
.message.v-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
.row {
|
.row {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(5, 1fr);
|
grid-template-columns: repeat(5, 1fr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user