Explorar el Código

工作记忆修复

周玉佂 hace 2 semanas
padre
commit
e87bceb31f

+ 68 - 49
src/views/gameCenter/components/games/WorkingMemory/components/ability/index.vue

@@ -28,6 +28,8 @@ const $emits = defineEmits(['gameOver'])
 interface LevelData {
   level: number
   correct: boolean
+  ifNeedClick: boolean
+  ifUserClick: boolean
   score: number
   responseStartTime: number
   responseEndTime: number
@@ -49,8 +51,10 @@ const fistOpen = ref(true) // 第一屏
 const flage1 = ref(true) // 视觉模式选项
 const flage2 = ref(false) // 听觉模式选项
 const flage3 = ref(false) // 混合模式选项
-const next_stepFlag1 = ref(false) // 图片游戏开始
-const next_stepFlag2 = ref(false) // 数字模式开始
+const next_stepFlag1 = ref(false) // 视觉游戏开始
+const next_stepFlag2 = ref(false) // 听觉模式开始
+const next_stepFlag3 = ref(false) // 混合模式开始
+
 // const next_stepflag = ref(true) // 第二屏
 const countDownVal = ref(560) // 倒计时时间
 const showAdd = ref(false)
@@ -80,7 +84,7 @@ const maxNumber = 9
 let currentNumber = 0
 // 响应开始时间戳
 let responseStartTime = 0
-
+let currentLetterList = []
 let timerId: any
 let divShowInteval: any
 let gameStartTime_record = 0
@@ -88,6 +92,11 @@ let gameStartTime_record = 0
 const planInfo = ref<RTPlanMgrQuery>()
 const instance = getCurrentInstance()
 const userStore = useUserStore()
+function executeMethod() {
+  nextOnce()
+  console.log('执行此方法。')
+  // createCurrentLetterList(onceData.value)
+}
 const setTimetiming = () => {
   let elapsedSeconds = 0
   function startTimer() {
@@ -97,7 +106,8 @@ const setTimetiming = () => {
         // executeMethod()
         elapsedSeconds = 0
         showAdd.value = true
-        nextOnce()
+        // nextOnce()
+        executeMethod()
       }
     }, 1000)
     // if (elapsedSeconds >= 60) {
@@ -118,20 +128,27 @@ function shuffleArray(array: any) {
   }
   return newArray
 }
+
 const chengFlagek = () => {
   console.log('开始')
   if (flage1.value) {
     setTimetiming()
     next_stepFlag1.value = true
     next_stepFlag2.value = false
+    next_stepFlag3.value = false
     fistOpen.value = false
     countDownVisible.value = true
   } else if (flage2.value) {
     fistOpen.value = false
     next_stepFlag2.value = true
     next_stepFlag1.value = false
+    next_stepFlag3.value = false
     // countDownVisible.value = true
   } else {
+    fistOpen.value = false
+    next_stepFlag2.value = false
+    next_stepFlag1.value = false
+    next_stepFlag3.value = true
   }
 }
 const chengFlage1 = (answer: string) => {
@@ -224,6 +241,7 @@ const nextOnce = () => {
     } else {
       // 游戏结束
       console.log('游戏结束2')
+      console.log(gameList, '游戏数据')
       clearInterval(timerId)
       clearInterval(divShowInteval)
       // sendData()
@@ -267,46 +285,52 @@ const setOnceData = () => {
   responseStartTime = performance.now()
   // console.log(currentNumber, 'currentNumber')
   onceData.value = gameData.value[currentLevel][currentNumber]
-  //     timerId = setInterval(() => {
-  //       elapsedSeconds++
-  //       if (elapsedSeconds > 3) {
-  //         executeMethod()
-  //         elapsedSeconds = 0
-  //       }
-  //     }, 1000)
-  // divShow.value = true
-  //
-  // divShowInteval = setInterval(() => {
-  //   showAdd.value = true
-  //   nextOnce()
-  // }, 2000)
-  // onceData.value.choices = shuffleArray(onceData.value.choices)
+  console.log(currentLevel, '当前游戏等级')
+  if (currentLevel == 0) {
+    gameList.push({
+      level: currentLevel,
+      correct: false,
+      score: 0,
+      ifNeedClick: gameData.value[currentLevel][0].answer === onceData.value.question,
+      ifUserClick: false,
+      responseEndTime: performance.now(),
+      responseStartTime: responseStartTime
+    })
+  }
 }
 
-const handleClick = (answer: string) => {
-  const correct = onceData.value.answer === answer
-  VoiceImpRef.value.videoPlay('click')
-  setTimeout(() => {
-    if (correct) {
-      console.log(VoiceImpRef.value, 'hbbbbbbbbbbbbbbbbbbbbbbbbbdf=============>')
-
-      VoiceImpRef.value.videoPlay('right')
-    } else {
-      VoiceImpRef.value.videoPlay('error')
-    }
-  }, 200)
-  // 收集当前试次的用户操作数据
-  gameList.push({
-    level: currentLevel,
-    correct: correct,
-    score: correct ? scoreList[currentLevel] : 0,
-    responseEndTime: performance.now(),
-    responseStartTime: responseStartTime
-  })
-  console.log(gameList)
-
-  // 开始下一次
-  nextOnce()
+const handleKeyDown = (event: any) => {
+  console.log(event.button, '判断鼠标点击左键还是右键')
+  console.log(event.key, '判断鼠标点j还是f')
+  console.log(currentNumber, '当前试次', gameList, gameList[currentNumber])
+  if (event.key == 'f') {
+    gameList[currentNumber].ifUserClick = true
+  }
+  if (gameList[currentNumber].ifUserClick === gameList[currentNumber].ifNeedClick) {
+    gameList[currentNumber].correct = true
+  }
+  // }
+  // // VoiceImpRef.value.videoPlay('click')
+  // // setTimeout(() => {
+  // //   if (correct) {
+  // //     console.log(VoiceImpRef.value, 'hbbbbbbbbbbbbbbbbbbbbbbbbbdf=============>')
+  // //
+  // //     VoiceImpRef.value.videoPlay('right')
+  // //   } else {
+  // //     VoiceImpRef.value.videoPlay('error')
+  // //   }
+  // // }, 200)
+  // // 收集当前试次的用户操作数据
+  // // gameList.push({
+  // //   level: currentLevel,
+  // //   correct: correct,
+  // //   score: correct ? scoreList[currentLevel] : 0,
+  // //   responseEndTime: performance.now(),
+  // //   responseStartTime: responseStartTime
+  // // })
+  // // 开始下一次
+  // // nextOnce()
+  // console.log(gameList, '当前试次用户操作数据')
 }
 
 // 发送请求
@@ -422,15 +446,9 @@ async function exec() {
 onMounted(() => {
   exec()
   nextTick(() => {
+    window.addEventListener('keydown', handleKeyDown)
     countDownVisible.value = true
     setTimetiming()
-    // console.log(onceData.value.choices, 'onceData392')
-    // onceData.value = shuffleArray(onceData.value)
-    // onceData.value.choices = shuffleArray(onceData.value.choices)
-    // countDownVisible.value = true
-    // 倒计时
-    // getTime()
-    // setTimetiming()
   })
 })
 watchEffect(() => {
@@ -440,6 +458,7 @@ watchEffect(() => {
 onUnmounted(() => {
   clearInterval(timerId)
 })
+// 添加键盘事件监听
 </script>
 
 <style scoped lang="scss">

+ 16 - 42
src/views/gameCenter/components/games/WorkingMemory/index.vue

@@ -16,8 +16,9 @@
       <!--      </div>-->
       <div
         class="child-container bor-radius-8 bg-[#ffffff] w-[1960px] h-[960px] mt-[100px] flex flex-col justify-center items-center gap-y-[30px]"
-        @click="handleKeyDown()"
       >
+        <!--        @click="handleKeyDown()"-->
+
         <div v-if="fistOpen" class="absolute left-[225px] top-[170px] color-[#111111] text-[35px]">
           <h1>请选择游戏模式:</h1>
         </div>
@@ -169,32 +170,10 @@ const planInfo = ref<RTPlanMgrQuery>()
 const instance = getCurrentInstance()
 const userStore = useUserStore()
 function executeMethod() {
-  // gameList.push({
-  //   level: currentLevel,
-  //   correct: false,
-  //   score: 0,
-  //   ifNeedClick: gameData.value[currentLevel][0].answer === onceData.value.question,
-  //   ifUserClick: false,
-  //   responseEndTime: performance.now(),
-  //   responseStartTime: responseStartTime
-  // })
   nextOnce()
   console.log('执行此方法。')
   // createCurrentLetterList(onceData.value)
 }
-function createCurrentLetterList(sourceLetterList: any) {
-  currentLetterList = []
-  for (var i = 0; i < sourceLetterList.length; i++) {
-    let tempObj = {
-      letter: sourceLetterList[i],
-      ifNeedClick: false,
-      ifUserClick: false,
-      userResponseTime: 0
-    }
-    currentLetterList.push(tempObj)
-    console.log(currentLetterList, 'currentLetterList')
-  }
-}
 const setTimetiming = () => {
   let elapsedSeconds = 0
   function startTimer() {
@@ -395,31 +374,26 @@ const setOnceData = () => {
   // console.log(currentNumber, 'currentNumber')
   onceData.value = gameData.value[currentLevel][currentNumber]
   console.log(currentLevel, '当前游戏等级')
-  gameList.push({
-    level: currentLevel,
-    correct: false,
-    score: 0,
-    ifNeedClick: gameData.value[currentLevel][0].answer === onceData.value.question,
-    ifUserClick: false,
-    responseEndTime: performance.now(),
-    responseStartTime: responseStartTime
-  })
+  if (currentLevel == 0) {
+    gameList.push({
+      level: currentLevel,
+      correct: false,
+      score: 0,
+      ifNeedClick: gameData.value[currentLevel][0].answer === onceData.value.question,
+      ifUserClick: false,
+      responseEndTime: performance.now(),
+      responseStartTime: responseStartTime
+    })
+  }
 }
 
 const handleKeyDown = (event: any) => {
-  // if ()
   console.log(event.button, '判断鼠标点击左键还是右键')
   console.log(event.key, '判断鼠标点j还是f')
-  // console.log(currentLetterList, 'currentLetterList')
   console.log(currentNumber, '当前试次', gameList, gameList[currentNumber])
-  //用户点击动作
-  // if (currentNumber - 1 >= 0) {
-  gameList[currentNumber].ifUserClick = true
-  // console.log(new Date().getTime() - data.startMilliSeconds)
-  // console.log(data.currentLetterList, 'currentLetterList')
-  console.log(gameList[currentNumber].ifUserClick, gameList[currentNumber].ifNeedClick, '数据收集处理')
-  // const correct = gameList[currentNumber].ifUserClick === gameList[currentNumber].ifNeedClick
-
+  if (event.key == 'f') {
+    gameList[currentNumber].ifUserClick = true
+  }
   if (gameList[currentNumber].ifUserClick === gameList[currentNumber].ifNeedClick) {
     gameList[currentNumber].correct = true
   }