Skip to content

Commit

Permalink
Implement complete
Browse files Browse the repository at this point in the history
  • Loading branch information
hayatroid committed Mar 27, 2024
1 parent 66ea08f commit e3c65e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/App.vue
@@ -1,9 +1,12 @@
<script setup lang="ts">
import { ref } from 'vue'
import Game from './components/Game.vue'
const id = ref<number>(0)
</script>

<template>
<Game :id="0" />
<Game :id="id" :key="id" @complete="id++" />
</template>

<style scoped>
Expand Down
7 changes: 7 additions & 0 deletions src/components/Game.vue
Expand Up @@ -6,6 +6,10 @@ const props = defineProps<{
id: number
}>()
const emits = defineEmits<{
complete: []
}>()
const word = idioms[props.id].word
const idiom_en = idioms[props.id].idiom_en
const idiom_ja = idioms[props.id].idiom_ja
Expand All @@ -27,6 +31,9 @@ const onKeyDown = (e: KeyboardEvent) => {
if (pos.value < end && e.key == idiom_en[pos.value] && !e.repeat) {
pos.value++
}
if (pos.value == end) {
emits('complete')
}
}
document.addEventListener('keydown', onKeyDown)
</script>
Expand Down

0 comments on commit e3c65e0

Please sign in to comment.