bx-865-apps #1

Merged
ksenia_mikhailova merged 140 commits from bx-865-apps into main 2024-06-27 15:03:27 +03:00
2 changed files with 65 additions and 26 deletions
Showing only changes of commit 48ef3fb744 - Show all commits

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { UseDraggable } from '@vueuse/components'; import { UseDraggable } from '@vueuse/components';
import type { Position } from '@vueuse/core'; import { type Position } from '@vueuse/core';
import { random_сolor, shuffle_array, getRandomIntInclusive } from '../helpers'; import { random_сolor, shuffle_array, getRandomIntInclusive } from '../helpers';
import icon1 from '~icons/mdi/square'; import icon1 from '~icons/mdi/square';
@ -12,73 +12,96 @@ import icon3 from '~icons/mdi/circle';
import icon3_o from '~icons/mdi/circle-outline'; import icon3_o from '~icons/mdi/circle-outline';
import icon4 from '~icons/mdi/hexagon'; import icon4 from '~icons/mdi/hexagon';
import icon4_o from '~icons/mdi/hexagon-outline'; import icon4_o from '~icons/mdi/hexagon-outline';
const icons_list = [
icon1,
icon1_o,
icon2,
icon2_o,
icon3,
icon3_o,
icon4,
icon4_o,
]
const colors = ref([
random_сolor(),
random_сolor(),
random_сolor(),
random_сolor(),
])
const icons = [ const icons = [
{ {
fill: icon1, id: 1, fill: 0, outline: 1,
outline: icon1_o,
color: random_сolor(),
ref: ref<HTMLElement | null>(null)
}, },
{ {
fill: icon2, id: 2, fill: 2, outline: 3,
outline: icon2_o, color: random_сolor(),
ref: ref<HTMLElement | null>(null)
}, },
{ {
fill: icon3, id: 3, fill: 4, outline: 5,
outline: icon3_o, color: random_сolor(),
ref: ref<HTMLElement | null>(null)
}, },
{ {
fill: icon4, id: 4, fill: 6, outline: 7,
outline: icon4_o, color: random_сolor(),
ref: ref<HTMLElement | null>(null)
}, },
] ]
const source_icons = ref(shuffle_array(icons))
const target_icons = ref(shuffle_array(icons))
const active_drag = ref<string | null>(null) const active_drag = ref<string | null>(null)
const dragStart = (_: Position, event: PointerEvent) => { const dragStart = (_: Position, event: PointerEvent) => {
const element = event.currentTarget const element = event.currentTarget
if (element instanceof HTMLElement && element.dataset.id) { if (element instanceof HTMLElement && element.dataset.id) {
active_drag.value = element.dataset.id active_drag.value = element.dataset.id
console.log(`update active drag ${element.dataset.id}`)
} }
} }
const dragEnd = (position: Position, event: PointerEvent) => { const dragEnd = (position: Position, _: PointerEvent) => {
const target = document.elementsFromPoint(position.x, position.y).find(el => el.className == 'target-item') const target = document.elementsFromPoint(position.x, position.y).find(el => el.className == 'target-item')
if (target instanceof HTMLElement && target.dataset.id) { if (target instanceof HTMLElement && target.dataset.id) {
const targetId = target.dataset.id const targetId = target.dataset.id
const sourceId = active_drag.value const sourceId = active_drag.value
if (targetId == sourceId) { if (targetId == sourceId) {
console.log('n') success.value.push(parseInt(targetId))
} }
} }
} }
const componentKey = ref(0)
const success = ref<number[]>([])
const updateGame = () => {
success.value = []
componentKey.value += 1
source_icons.value = shuffle_array(icons)
target_icons.value = shuffle_array(icons)
colors.value = [random_сolor(), random_сolor(), random_сolor(), random_сolor()]
}
</script> </script>
<template> <template>
<div class="game"> <div class="game" :key="componentKey">
<div class="target"> <div class="target">
<span class="target-item" v-for="(item, i) in shuffle_array(icons)" :data-id="i"> <span class="target-item" v-for="item in target_icons" :data-id="item.id">
<component :is="item.outline" :style="{ 'color': item.color }"></component> <component :is="icons_list[item.outline]" :style="{ 'color': colors[item.id - 1] }"></component>
</span> </span>
</div> </div>
<UseDraggable v-for="(item, i) in shuffle_array(icons)" class="source-item" :data-id="i" <UseDraggable v-for="item in source_icons" class="source-item" :data-id="item.id"
:initial-value="{ x: getRandomIntInclusive(100, 1400), y: getRandomIntInclusive(300, 700) }" :initial-value="{ x: getRandomIntInclusive(100, 1400), y: getRandomIntInclusive(300, 700) }"
:on-start="dragStart" :on-end="dragEnd"> :on-start="dragStart" :on-end="dragEnd">
<component :is="item.fill" :style="{ 'color': item.color }" :ref="item.ref"></component> <component v-if="!success.includes(item.id)" :is="icons_list[item.fill]"
:style="{ 'color': colors[item.id - 1] }" :ref="item.ref"></component>
</UseDraggable> </UseDraggable>
<div class="links" v-if="success.length >= icons.length">
<RouterLink to="/">На главную</RouterLink>
<RouterLink to="/game" @click="updateGame">Еще раз</RouterLink>
</div>
</div> </div>
</template> </template>
<style scoped lans="scss"> <style scoped lans="scss">
.game { .game {
position: fixed; position: fixed;
display: flex;
height: 100vh; height: 100vh;
width: 100vw; width: 100vw;
position: relative;
display: flex;
flex-direction: column;
justify-content: space-around;
} }
.target { .target {
@ -96,4 +119,17 @@ const dragEnd = (position: Position, event: PointerEvent) => {
font-size: 7rem; font-size: 7rem;
position: absolute; position: absolute;
} }
.links {
display: flex;
flex-direction: column;
font-size: 5rem;
align-items: center;
gap: 1rem;
}
.links a {
text-decoration: none;
color: black;
}
</style> </style>

View File

@ -12,6 +12,9 @@
<li> <li>
<RouterLink to="projects">Проекты</RouterLink> <RouterLink to="projects">Проекты</RouterLink>
</li> </li>
<li>
<RouterLink to="game">Игра</RouterLink>
</li>
<li> <li>
<a href="https://timesheet.kustarshina.ru/">Табель рабочего времени</a> <a href="https://timesheet.kustarshina.ru/">Табель рабочего времени</a>
</li> </li>