<template>
<view class="wrap">
數獨:{{ sdNum }} * {{ sdNum }}
<view class="btn" style="padding: 32rpx; background: pink" @click="startFun">點選開始計時</view>
<view class="btn" style="padding: 32rpx; background: pink" @click="clickBtn">點選數獨按鈕</view>
<up-keyboard
mode="number"
:show="show"
:dotDisabled="true"
@change="changeValue"
@close="close"
@cancel="close"
@confirm="close"
tips="數獨鍵盤"
:safeAreaInsetBottom="true"
class="jianpan"
/>
<view>999--{{ testValue }}</view>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { onShow, onHide } from '@dcloudio/uni-app'
// import { taskDetail, memberInfo } from '@/api/hmm'
// import store from '@/store'
// import { transformTimeTwo } from '@/utils/hmm'
const sdNum = ref(5)
const rightList = ref([])
const randomNum = ref(0)
const answerList = ref([])
const rowList = ref([
{
question: [
[0, 0, 0, 0],
[0, 2, 3, 1],
[0, 3, 2, 4],
[2, 1, 0, 3]
],
answer: [
[3, 4, 1, 2],
[4, 2, 3, 1],
[1, 3, 2, 4],
[2, 1, 4, 3]
]
},
{
question: [
[2, 0, 0, 3],
[3, 0, 2, 1],
[0, 2, 3, 0],
[0, 0, 0, 2]
],
answer: [
[2, 1, 4, 3],
[3, 4, 2, 1],
[1, 2, 3, 4],
[4, 3, 1, 2]
]
},
{
question: [
[1, 0, 0, 0],
[4, 2, 3, 0],
[0, 4, 1, 0],
[3, 1, 0, 2]
],
answer: [
[1, 3, 2, 4],
[4, 2, 3, 1],
[2, 4, 1, 3],
[3, 1, 4, 2]
]
},
{
question: [
[3, 0, 1, 0],
[0, 1, 2, 0],
[2, 0, 3, 0],
[0, 3, 0, 2]
],
answer: [
[3, 2, 1, 4],
[4, 1, 2, 3],
[2, 4, 3, 1],
[1, 3, 4, 2]
]
},
{
question: [
[0, 0, 3, 0],
[0, 2, 0, 1],
[0, 3, 2, 4],
[0, 4, 1, 0]
],
answer: [
[4, 1, 3, 2],
[3, 2, 4, 1],
[1, 3, 2, 4],
[2, 4, 1, 3]
]
},
{
question: [
[0, 1, 4, 0],
[4, 2, 0, 1],
[0, 0, 0, 0],
[0, 4, 2, 3]
],
answer: [
[3, 1, 4, 2],
[4, 2, 6, 1],
[2, 3, 1, 4],
[1, 4, 2, 3]
]
},
{
question: [
[1, 0, 4, 0],
[0, 2, 0, 3],
[0, 1, 3, 4],
[0, 0, 0, 1]
],
answer: [
[1, 3, 4, 2],
[4, 2, 1, 3],
[2, 1, 3, 4],
[3, 4, 2, 1]
]
},
{
question: [
[0, 0, 0, 3],
[0, 3, 4, 2],
[0, 1, 0, 0],
[4, 0, 3, 1]
],
answer: [
[2, 4, 1, 3],
[1, 3, 4, 2],
[3, 1, 2, 4],
[4, 2, 3, 1]
]
},
{
question: [
[2, 4, 0, 0],
[0, 1, 2, 0],
[4, 0, 1, 0],
[0, 3, 4, 2]
],
answer: [
[2, 4, 3, 1],
[3, 1, 2, 4],
[4, 2, 1, 3],
[1, 3, 4, 2]
]
},
{
question: [
[1, 4, 2, 0],
[0, 3, 1, 0],
[0, 2, 0, 0],
[4, 0, 3, 0]
],
answer: [
[1, 4, 2, 3],
[2, 3, 1, 4],
[3, 2, 4, 1],
[4, 1, 3, 2]
]
}
])
const rowListFive = ref([
{
question: [
[0, 2, 3, 0, 1],
[4, 1, 0, 0, 3],
[0, 0, 4, 1, 0],
[1, 5, 0, 3, 4],
[3, 0, 1, 0, 2]
],
answer: [
[5, 2, 3, 4, 1],
[4, 1, 5, 2, 3],
[2, 3, 4, 1, 5],
[1, 5, 2, 3, 4],
[3, 4, 1, 5, 2]
]
},
{
question: [
[3, 5, 0, 2, 0],
[2, 1, 0, 0, 4],
[0, 4, 2, 0, 3],
[1, 0, 0, 4, 2],
[0, 2, 0, 3, 5]
],
answer: [
[3, 5, 4, 2, 1],
[2, 1, 3, 5, 4],
[5, 4, 2, 1, 3],
[1, 3, 5, 4, 2],
[4, 2, 1, 3, 5]
]
},
{
question: [
[0, 5, 0, 2, 3],
[2, 3, 0, 0, 1],
[5, 1, 2, 0, 0],
[3, 4, 0, 1, 2],
[0, 0, 3, 4, 0]
],
answer: [
[4, 5, 1, 2, 3],
[2, 3, 4, 5, 1],
[5, 1, 2, 3, 4],
[3, 4, 5, 1, 2],
[1, 2, 3, 4, 5]
]
},
{
question: [
[5, 0, 2, 3, 0],
[0, 1, 0, 4, 2],
[4, 0, 3, 0, 5],
[1, 0, 0, 2, 3],
[0, 3, 1, 0, 4]
],
answer: [
[5, 4, 2, 3, 1],
[3, 1, 5, 4, 2],
[4, 2, 3, 1, 5],
[1, 5, 4, 2, 3],
[2, 3, 1, 5, 4]
]
},
{
question: [
[0, 5, 4, 3, 1],
[0, 1, 0, 5, 4],
[5, 0, 3, 0, 2],
[1, 2, 0, 0, 0],
[4, 0, 1, 0, 5]
],
answer: [
[2, 5, 4, 3, 1],
[3, 1, 2, 5, 4],
[5, 4, 3, 1, 2],
[1, 2, 5, 4, 3],
[4, 3, 1, 2, 5]
]
},
{
question: [
[3, 0, 2, 0, 1],
[0, 1, 0, 5, 0],
[5, 0, 4, 0, 3],
[0, 3, 0, 2, 4],
[2, 0, 1, 3, 5]
],
answer: [
[3, 5, 2, 4, 1],
[4, 1, 3, 5, 2],
[5, 2, 4, 1, 3],
[1, 3, 5, 2, 4],
[2, 4, 1, 3, 5]
]
},
{
question: [
[4, 0, 2, 5, 1],
[0, 1, 0, 3, 0],
[3, 0, 5, 0, 4],
[0, 4, 0, 2, 5],
[2, 5, 0, 0, 3]
],
answer: [
[4, 3, 2, 5, 1],
[5, 1, 4, 3, 2],
[3, 2, 5, 1, 4],
[1, 4, 3, 2, 5],
[2, 5, 1, 4, 3]
]
},
{
question: [
[2, 0, 0, 5, 1],
[0, 1, 0, 4, 3],
[0, 0, 5, 1, 2],
[1, 2, 0, 0, 5],
[3, 5, 1, 0, 0]
],
answer: [
[2, 4, 3, 5, 1],
[5, 1, 2, 4, 3],
[4, 3, 5, 1, 2],
[1, 2, 4, 3, 5],
[3, 5, 1, 2, 4]
]
},
{
question: [
[3, 2, 4, 0, 0],
[0, 1, 3, 0, 4],
[0, 0, 5, 1, 3],
[0, 3, 0, 4, 5],
[4, 0, 1, 3, 0]
],
answer: [
[3, 2, 4, 5, 1],
[5, 1, 3, 2, 4],
[2, 4, 5, 1, 3],
[1, 3, 2, 4, 5],
[4, 5, 1, 3, 2]
]
},
{
question: [
[0, 1, 0, 4, 5],
[5, 0, 2, 1, 0],
[1, 5, 0, 0, 2],
[3, 0, 1, 0, 4],
[0, 3, 0, 2, 1]
],
answer: [
[2, 1, 3, 4, 5],
[5, 4, 2, 1, 3],
[1, 5, 4, 3, 2],
[3, 2, 1, 5, 4],
[4, 3, 5, 2, 1]
]
}
])
const rowListSix = ref([
{
question: [
[0, 5, 0, 2, 0, 6],
[2, 4, 6, 0, 0, 3],
[1, 2, 4, 0, 6, 5],
[5, 6, 0, 4, 2, 1],
[4, 0, 0, 6, 3, 2],
[6, 0, 2, 0, 1, 0]
],
answer: [
[3, 5, 1, 2, 4, 6],
[2, 4, 6, 1, 5, 3],
[1, 2, 4, 3, 6, 5],
[5, 6, 3, 4, 2, 1],
[4, 1, 5, 6, 3, 2],
[6, 3, 2, 5, 1, 4]
]
},
{
question: [
[1, 3, 0, 2, 5, 6],
[0, 6, 0, 3, 0, 4],
[0, 5, 6, 1, 0, 2],
[3, 0, 2, 4, 6, 0],
[5, 0, 1, 0, 4, 0],
[6, 4, 3, 0, 2, 1]
],
answer: [
[1, 3, 4, 2, 5, 6],
[2, 6, 5, 3, 1, 4],
[4, 5, 6, 1, 3, 2],
[3, 1, 2, 4, 6, 5],
[5, 2, 1, 6, 4, 3],
[6, 4, 3, 5, 2, 1]
]
},
{
question: [
[5, 6, 0, 2, 3, 4],
[2, 0, 3, 0, 0, 5],
[0, 0, 2, 5, 4, 6],
[4, 5, 6, 1, 0, 0],
[3, 0, 0, 4, 0, 2],
[6, 2, 4, 0, 5, 1]
],
answer: [
[5, 6, 1, 2, 3, 4],
[2, 4, 3, 6, 1, 5],
[1, 3, 2, 5, 4, 6],
[4, 5,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 6, 3]
]
},
{
question: [
[0, 0, 0, 3, 2, 0],
[3, 2, 0, 6, 1, 5],
[2, 4, 1, 5, 3, 0],
[0, 6, 3, 1, 4, 2],
[4, 1, 5, 0, 6, 3],
[0, 3, 2, 0, 0, 0]
],
answer: [
[1, 5, 6, 3, 2, 4],
[3, 2, 4, 6, 1, 5],
[2, 4, 1, 5, 3, 6],
[5, 6, 3, 1, 4, 2],
[4, 1, 5, 2, 6, 3],
[6, 3, 2, 4, 5, 1]
]
},
{
question: [
[3, 4, 1, 6, 0, 5],
[0, 0, 0, 0, 3, 4],
[4, 3, 0, 2, 6, 1],
[1, 2, 6, 0, 4, 3],
[2, 1, 0, 0, 0, 0],
[6, 0, 4, 3, 1, 2]
],
answer: [
[3, 4, 1, 6, 2, 5],
[5, 6, 2, 1, 3, 4],
[4, 3, 5, 2, 6, 1],
[1, 2, 6, 5, 4, 3],
[2, 1, 3, 4, 5, 6],
[6, 5, 4, 3, 1, 2]
]
},
{
question: [
[1, 0, 3, 4, 0, 6],
[4, 6, 0, 1, 5, 3],
[5, 1, 6, 0, 0, 0],
[0, 0, 0, 6, 1, 5],
[3, 4, 1, 0, 6, 2],
[6, 0, 5, 3, 0, 1]
],
answer: [
[1, 5, 3, 4, 2, 6],
[4, 6, 2, 1, 5, 3],
[5, 1, 6, 2, 3, 4],
[2, 3, 4, 6, 1, 5],
[3, 4, 1, 5, 6, 2],
[6, 2, 5, 3, 4, 1]
]
}
])
// const show = ref(true)
const show = ref(false)
const testValue = ref(0)
// 開始計時
const timmer = ref(null)
const startTime = ref(0)
const stopTime = ref(0)
onShow(() => {
generateShuDu()
})
onHide(() => {
clearInterval(timmer.value)
})
const generateShuDu = () => {
console.log(11122233)
rightList.value = []
answerList.value = []
const num = Math.floor(Math.random() * 10)
randomNum.value = num
if (sdNum.value == 4) {
rightList.value = rowList.value[randomNum.value].question
answerList.value = rowList.value[randomNum.value].answer
} else if (sdNum.value == 5) {
rightList.value = rowListFive.value[randomNum.value].question
answerList.value = rowListFive.value[randomNum.value].answer
} else if (sdNum.value == 6) {
rightList.value = rowListSix.value[randomNum.value].question
answerList.value = rowListSix.value[randomNum.value].answer
}
//生成數獨
console.log('rightList')
console.log(rightList.value)
console.log(answerList.value)
for (let i = 0; i < rightList.value.length; i++) {
for (let j = 0; j < rightList.value[i].length; j++) {
if (rightList.value[i][j] == 0) {
rightList.value[i][j] = ''
}
}
}
console.log(rightList.value)
console.log(111)
}
const clickBtn = () => {
show.value = true
}
const changeValue = (val) => {
show.value = false
testValue.value = val
}
const close = () => {
show.value = false
}
// 開始
const startFun = () => {
clearInterval(timmer.value)
startTime.value = 0
stopTime.value = 0
startTime.value = new Date().getTime()
// 開始之後 時間超過一個小時 就停止了 需要重新玩
// stopTime.value = 60 * 60 * 24 * 1000
stopTime.value = 10 * 1000 //測試 10s 超時
timmer.value = setInterval(() => {
const newDateTime = new Date().getTime() - startTime.value
if (newDateTime >= stopTime.value) {
clearInterval(timmer.value)
console.log('遊戲超時自動結束')
} else {
transformTime(newDateTime)
}
}, 1000)
}
const transformTime = (date) => {
var datetime = ''
//計算出小時數
var leave1 = date % (24 * 3600 * 1000) //計算天數後剩餘的毫秒數
var hours =
Math.floor(leave1 / (3600 * 1000)) < 10
? '0' + Math.floor(leave1 / (3600 * 1000))
: Math.floor(leave1 / (3600 * 1000))
//計算相差分鐘數
var leave2 = leave1 % (3600 * 1000) //計算小時數後剩餘的毫秒數
var minutes =
Math.floor(leave2 / (60 * 1000)) < 10
? '0' + Math.floor(leave2 / (60 * 1000))
: Math.floor(leave2 / (60 * 1000))
//計算相差秒數
var leave3 = leave2 % (60 * 1000) //計算分鐘數後剩餘的毫秒數
var seconds =
Math.round(leave3 / 1000) < 10 ? '0' + Math.round(leave3 / 1000) : Math.round(leave3 / 1000)
datetime = hours + ' 小時 ' + minutes + ' 分鐘 ' + seconds + ' 秒'
console.log(8888)
console.log(datetime)
return datetime
}
</script>
<style lang="scss">
::v-deep .u-popup {
.u-keyboard {
.u-keyboard {
.u-keyboard__button-wrapper {
// &:nth-last-child(2) {
// .u-keyboard__button-wrapper__button {
// // background: red !important;
// background: rgba(200, 202, 210, 1) !important;
// &.u-hover-class {
//
// // background: red !important;
// opacity: 1;
// }
// }
// }
&:nth-last-child(2),
&:nth-last-child(1) {
display: none;
}
}
}
}
}
</style>