最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用vue實(shí)現(xiàn)猜謎卡片游戲

 更新時(shí)間:2023年09月14日 11:22:14   作者:意會(huì)  
這篇文章主要為大家詳細(xì)介紹了如何使用vue實(shí)現(xiàn)簡(jiǎn)單的猜謎卡片游戲,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以參考一下

先提前祝jym ,心有嫦娥月,祝福滿滿中秋!

猜題卡片靈感來自于王者榮耀的夫子的試煉,收集了一些關(guān)于中秋節(jié)的題目做成了卡片,以選擇題的形式答題。 效果圖:

第一步先畫一個(gè)div

    <header class="header">
      <div>
        <img style="height: 143px;width: 189px;margin-top: 30px;margin-bottom: 10px;" src="./img/tuzi.png" alt="">
        <p class="text1">答對(duì){{ 0 }}題</p>
      </div>
  </div>

先畫一個(gè)div里面放一張圖片,下面顯示答對(duì)題目數(shù)量

 <div class="container">
    <header class="header">
      <div>
        <img style="height: 143px;width: 189px;margin-top: 30px;margin-bottom: 10px;" src="./img/tuzi.png" alt="">
        <p class="text1">答對(duì){{ 0 }}題</p>
      </div>
  </div>
  <div class="">
        <p class="text2 timu2" style="margin-top: 30px;">第{{ timusl }}/10題</p>
        <p class="text2 timu2" style="width: 290px;word-wrap: break-word;">{{ "題目?jī)?nèi)容" }}</p>
        <div class="timu">
          <div :class="[isCorrectA?'text4':aaa? 'text5' :'text1', 'timu1']" @click="onclickA">A:{{ "木蘭辭" }}</div>
          <div :class="[isCorrectB?'text4':bbb? 'text5' :'text1', 'timu1']" @click="onclickB">B:{{ "九歌" }}</div>
        </div>
        <div class="timu">
          <div :class="[isCorrectC?'text4':ccc? 'text5' :'text1', 'timu1']" @click="onclickC">C:{{ "八陣圖" }}</div>
          <div :class="[isCorrectD?'text4':ddd? 'text5' :'text1', 'timu1']" @click="onclickD">D:{{ "蘭陵王破陣曲" }}</div>
        </div>

再加上一個(gè)div,里面放選擇題的題目和答案以及是第幾題

    <header class="header">
      <div>
        <img style="height: 143px;width: 189px;margin-top: 30px;margin-bottom: 10px;" src="./img/tuzi.png" alt="">
        <p class="text1">答對(duì){{ 0 }}題</p>
        <p class="text1">累計(jì)獎(jiǎng)勵(lì)</p>
      </div>
      <div class="">
        <p class="text2 timu2" style="margin-top: 30px;">第{{ timusl }}/10題</p>
        <p class="text2 timu2" style="width: 290px;word-wrap: break-word;">{{ "題目?jī)?nèi)容" }}</p>
        <div class="timu">
          <div :class="[isCorrectA?'text4':aaa? 'text5' :'text1', 'timu1']" @click="onclickA">A:{{ "木蘭辭" }}</div>
          <div :class="[isCorrectB?'text4':bbb? 'text5' :'text1', 'timu1']" @click="onclickB">B:{{ "九歌" }}</div>
        </div>
        <div class="timu">
          <div :class="[isCorrectC?'text4':ccc? 'text5' :'text1', 'timu1']" @click="onclickC">C:{{ "八陣圖" }}</div>
          <div :class="[isCorrectD?'text4':ddd? 'text5' :'text1', 'timu1']" @click="onclickD">D:{{ "蘭陵王破陣曲" }}</div>
        </div>
      </div>
    </header>
    <div class="result">
      <p v-if="isAnswered && isCorrectA||isCorrectB||isCorrectC||isCorrectD" class="text1">回答正確!</p>
      <p v-if="isAnswered && !isCorrectA&!isCorrectB&!isCorrectC&!isCorrectD" class="text1">回答錯(cuò)誤!</p>
    </div>
    <p class="text1" @click="xyt"> {{ "下一題" }}</p>
  </div>

最后加上一個(gè)回答正確和錯(cuò)誤的提示,以及一個(gè)按鈕,按鈕名稱為下一題,用來跳到下一題。以上為所有頁(yè)面部分

第二步寫js 我們先給每一個(gè)選項(xiàng)設(shè)置一個(gè)點(diǎn)擊事件,點(diǎn)擊時(shí)切換class的樣式,答對(duì)渲染成綠色,答錯(cuò)渲染成紅色,未答題則全是白色字體。 判斷用戶選擇的答案是否為正確答案,來渲染答錯(cuò)和答對(duì)

// 0未選,1選對(duì),2選錯(cuò)
let aaa = ref(0)
let bbb = ref(0)
let ccc = ref(0)
let ddd = ref(0)
let isAnswered = ref(false)// 是否已回答
let isCorrectA = ref(false) // 是否回答正確
let isCorrectB = ref(false) // 是否回答正確
let isCorrectC = ref(false) // 是否回答正確
let isCorrectD = ref(false) // 是否回答正確
let correctAnswer = 'A' // 正確答案(假設(shè)正確答案為 A)
let selectedAnswer = '' // 用戶選擇的答案(假設(shè)用戶選擇的答案為空)
let timusl=ref(1)
let onclickA = () => {
  selectedAnswer='A'
  isAnswered.value = true; // 設(shè)置已回答狀態(tài)
  if (selectedAnswer === correctAnswer) {
        isCorrectA.value = true; // 答案正確
      } else {
        isCorrectA.value = false; // 答案錯(cuò)誤
      }
  if (aaa.value == 0 & bbb.value == 0 & ccc.value == 0 & ddd.value == 0) {
    aaa.value = 1
  }
}
let onclickB = () => {
  selectedAnswer='B'
  isAnswered.value = true; // 設(shè)置已回答狀態(tài)
  if (selectedAnswer === correctAnswer) {
        isCorrectB.value = true; // 答案正確
      } else {
        isCorrectB.value = false; // 答案錯(cuò)誤
      }
  if (aaa.value == 0 & bbb.value == 0 & ccc.value == 0 & ddd.value == 0) {
    bbb.value = 1
  } 
}
let onclickC = () => {
  selectedAnswer='C'
  isAnswered.value = true; // 設(shè)置已回答狀態(tài)
  if (selectedAnswer=== correctAnswer) {
        isCorrectC.value = true; // 答案正確
      } else {
        isCorrectC.value = false; // 答案錯(cuò)誤
      }
  if (aaa.value == 0 & bbb.value == 0 & ccc.value == 0 & ddd.value == 0) {
    ccc.value = 1
  }
}
let onclickD = () => {
  selectedAnswer='D'
  isAnswered.value = true; // 設(shè)置已回答狀態(tài)
  if (selectedAnswer === correctAnswer) {
        isCorrectD.value = true; // 答案正確
      } else {
        isCorrectD.value = false; // 答案錯(cuò)誤
      }
  if (aaa.value == 0 & bbb.value == 0 & ccc.value == 0 & ddd.value == 0) {
    ddd.value = 1
  }
}
let xyt=()=>{
if(  timusl.value<=10){
  timusl.value++
}
}

最后稍微加一點(diǎn)點(diǎn)css

.container {
  width: 700px;
  height: 350px;
  background-color: #21314A;
}
.text1 {
  color: #fff;
  font-size: small;
  text-align: center;
  cursor: pointer;
}
.text3 {
  color: #000;
  font-size: small;
  text-align: center;
  cursor: pointer;
}
.text4 {
  color: green;
  font-size: small;
  text-align: center;
  cursor: pointer;
}
.text5 {
  color: red;
  font-size: small;
  text-align: center;
  cursor: pointer;
}
.text2 {
  color: #fff;
  font-size: small;
  /* text-align: center; */
}
.header {
  display: flex;
  margin-left: 80px;
  margin-top: 20px;
}
.timu {
  display: flex;
  width: 300px;
  text-align: center;
}
.timu1 {
  width: 150px;
  margin: 10px;
  padding: 10px;
  border-width: 2px;
  border-style: solid;
  border-radius: 10px;
  border-color: #000000;
}
.timu2 {
  margin-left: 10px;
}
</style>

就可以達(dá)到一個(gè)卡片答題的效果了,但是代碼又重又呆,我們?cè)賰?yōu)化一點(diǎn)點(diǎn)代碼,把題目循環(huán)進(jìn)去

最后的代碼如下

<template>
  <div class="container">
    <header class="header">
      <div>
        <img style="height: 143px;width: 189px;margin-top: 30px;margin-bottom: 10px;" src="./img/tuzi.png" alt="">
        <p class="text1">答對(duì){{ correctCount }}題</p>
        <p class="text1">累計(jì)獎(jiǎng)勵(lì)</p>
      </div>
      <div>
        <p class="text2 timu2" style="margin-top: 30px;">第{{ currentQuestionIndex }}/10題</p>
        <p class="text2 timu2" style="width: 290px;word-wrap: break-word;">{{ currentQuestion.content }}</p>
        <div class="timu">
          <div :class="[isCorrect('A') ? 'text4' : selectedAnswer === 'A' ? 'text5' : 'text1', 'timu1']"
            @click="selectAnswer('A')">A:{{ currentQuestion.options[0] }}</div>
          <div :class="[isCorrect('B') ? 'text4' : selectedAnswer === 'B' ? 'text5' : 'text1', 'timu1']"
            @click="selectAnswer('B')">B:{{ currentQuestion.options[1] }}</div>
        </div>
        <div class="timu">
          <div :class="[isCorrect('C') ? 'text4' : selectedAnswer === 'C' ? 'text5' : 'text1', 'timu1']"
            @click="selectAnswer('C')">C:{{ currentQuestion.options[2] }}</div>
          <div :class="[isCorrect('D') ? 'text4' : selectedAnswer === 'D' ? 'text5' : 'text1', 'timu1']"
            @click="selectAnswer('D')">D:{{ currentQuestion.options[3] }}</div>
        </div>
      </div>
    </header>
    <div class="result">
      <p v-if="isAnswered && isCorrect(selectedAnswer)" class="text1">回答正確!</p>
      <p v-else-if="isAnswered" class="text1">回答錯(cuò)誤!</p>
    </div>
    <div v-if="currentQuestionIndex >= 10">
      <p class="text1">恭喜回答完所有題目,您一共答對(duì){{ correctCount }}題!</p>
    </div>
    <p class="text1" @click="nextQuestion" v-if="isAnswered && currentQuestionIndex < 10">下一題</p>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue';
const questions = [
  {
    content: "中秋節(jié)是從哪個(gè)朝代開始成為固定的節(jié)日?",
    options: ["唐", "宋", "元", "明"],
    correctAnswer: "A"
  },
  {
    content: "月餅最初是用來做什么的?",
    options: ["祭奉月神的貢品", "饋贈(zèng)親友的禮物", "節(jié)日食品", "地方小吃"],
    correctAnswer: "A"
  },
  {
    content: "在古代月圓和月缺一般形容什么?",
    options: ["天氣好壞", "兇吉象征", "身體是否健康", "悲歡離合"],
    correctAnswer: "D"
  },
  {
    content: "傳說中嫦娥是誰(shuí)的妻子?",
    options: ["黃帝", "后裔", "大禹", "吳剛"],
    correctAnswer: "B"
  },
  {
    content: "嫦娥下凡(打一花名)?",
    options: ["月季", "玫瑰", "牡丹", "百合"],
    correctAnswer: "A"
  },
  {
    content: "中秋過后又重陽(yáng)(打一詩(shī)句)?",
    options: ["月上柳梢頭", "明月幾時(shí)有", "一節(jié)復(fù)一節(jié)", "抬頭望明月"],
    correctAnswer: "C"
  },
  {
    content: "“解落三秋葉,能開二月花”描寫的是哪一種自然現(xiàn)象?",
    options: ["雪", "月", "風(fēng)", "霜"],
    correctAnswer: "C"
  },
  {
    content: "以下哪個(gè)不是跟中秋節(jié)有關(guān)的傳說?",
    options: ["精衛(wèi)填海", "吳剛伐桂", "玉兔搗藥", "嫦娥奔月"],
    correctAnswer: "A"
  },
  {
    content: "八月十五又稱什么節(jié)?",
    options: ["月餅節(jié)", "團(tuán)圓節(jié)", "故鄉(xiāng)節(jié)", "詩(shī)人節(jié)"],
    correctAnswer: "B"
  },
  {
    content: "在傳說中,哪位皇帝曾在中秋夢(mèng)游月宮?",
    options: ["秦始皇嬴政", "唐玄宗李隆基", "宋徽宗趙佶", "明成祖朱棣"],
    correctAnswer: "B"
  },
  // 其他題目...
];
let currentQuestionIndex = ref(1); // 當(dāng)前題目的索引
let currentQuestion = ref(questions[currentQuestionIndex.value - 1]); // 當(dāng)前題目的內(nèi)容
let selectedAnswer = ref(''); // 用戶選擇的答案
let isAnswered = ref(false); // 是否已回答
let correctCount = ref(0); // 答對(duì)的題目數(shù)量
const isCorrect = (option) => {
  return isAnswered.value && selectedAnswer.value === option && selectedAnswer.value === currentQuestion.value.correctAnswer;
};
const selectAnswer = (option) => {
  selectedAnswer.value = option;
  isAnswered.value = true;
  if (isCorrect(option)) {
    correctCount.value++;
  }
};
const nextQuestion = () => {
  if (currentQuestionIndex.value < 10) {
    currentQuestionIndex.value++;
    currentQuestion.value = questions[currentQuestionIndex.value - 1];
    selectedAnswer.value = '';
    isAnswered.value = false;
  }
};
</script>
<style scoped>
.container {
  width: 700px;
  height: 350px;
  background-color: #21314A;
}
.text1 {
  color: #fff;
  font-size: small;
  text-align: center;
  cursor: pointer;
}
.text3 {
  color: #000;
  font-size: small;
  text-align: center;
  cursor: pointer;
}
.text4 {
  color: green;
  font-size: small;
  text-align: center;
  cursor: pointer;
}
.text5 {
  color: red;
  font-size: small;
  text-align: center;
  cursor: pointer;
}
.text2 {
  color: #fff;
  font-size: small;
  /* text-align: center; */
}
.header {
  display: flex;
  margin-left: 80px;
  margin-top: 20px;
}
.timu {
  display: flex;
  width: 300px;
  text-align: center;
}
.timu1 {
  width: 150px;
  margin: 10px;
  padding: 10px;
  border-width: 2px;
  border-style: solid;
  border-radius: 10px;
  border-color: #000000;
}
.timu2 {
  margin-left: 10px;
}
</style>

到此這篇關(guān)于使用vue實(shí)現(xiàn)猜謎卡片游戲的文章就介紹到這了,更多相關(guān)vue游戲內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue使用Element的Tree樹形控件實(shí)現(xiàn)拖動(dòng)改變節(jié)點(diǎn)順序方式

    vue使用Element的Tree樹形控件實(shí)現(xiàn)拖動(dòng)改變節(jié)點(diǎn)順序方式

    這篇文章主要介紹了vue使用Element的Tree樹形控件實(shí)現(xiàn)拖動(dòng)改變節(jié)點(diǎn)順序方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • vue實(shí)現(xiàn)點(diǎn)擊出現(xiàn)按鈕菜單問題

    vue實(shí)現(xiàn)點(diǎn)擊出現(xiàn)按鈕菜單問題

    文章主要介紹了如何在Vue中實(shí)現(xiàn)點(diǎn)擊按鈕顯示菜單的功能,父組件負(fù)責(zé)觸發(fā)事件,子組件負(fù)責(zé)渲染菜單,通過事件冒泡和狀態(tài)管理,實(shí)現(xiàn)了菜單的顯示和隱藏,代碼示例簡(jiǎn)潔明了,適合初學(xué)者參考
    2026-03-03
  • vue+element開發(fā)一個(gè)谷歌插件的全過程

    vue+element開發(fā)一個(gè)谷歌插件的全過程

    這篇文章主要給大家介紹了關(guān)于vue+element開發(fā)一個(gè)谷歌插件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • 解決Vue項(xiàng)目Network:?unavailable的問題

    解決Vue項(xiàng)目Network:?unavailable的問題

    項(xiàng)目只能通過Local訪問而不能通過Network訪問,本文主要介紹了解決Vue項(xiàng)目Network:?unavailable的問題,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-06-06
  • vue中v-model、v-bind和v-on三大指令的區(qū)別詳解

    vue中v-model、v-bind和v-on三大指令的區(qū)別詳解

    v-model和v-bind都是數(shù)據(jù)綁定的方式,下面這篇文章主要給大家介紹了關(guān)于vue中v-model、v-bind和v-on三大指令的區(qū)別,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-11-11
  • vue+elementUI組件table實(shí)現(xiàn)前端分頁(yè)功能

    vue+elementUI組件table實(shí)現(xiàn)前端分頁(yè)功能

    這篇文章主要為大家詳細(xì)介紹了vue+elementUI組件table實(shí)現(xiàn)前端分頁(yè)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • 適用于 Vue 的播放器組件Vue-Video-Player操作

    適用于 Vue 的播放器組件Vue-Video-Player操作

    這篇文章主要介紹了適用于 Vue 的播放器組件Vue-Video-Player操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • 關(guān)于element-ui表頭吸附問題的解決方案

    關(guān)于element-ui表頭吸附問題的解決方案

    數(shù)據(jù)過多滑動(dòng)表格的時(shí)候,看不到表頭不知道對(duì)應(yīng)的數(shù)據(jù)是什么,用戶體驗(yàn)操作不友好,要改成表頭固定住,所以本文給大家介紹了關(guān)于element-ui表頭吸附問題的兩個(gè)解決方案,需要的朋友可以參考下
    2024-01-01
  • 淺析一下Vue3的響應(yīng)式原理

    淺析一下Vue3的響應(yīng)式原理

    這篇文章主要通過示例和大家一起淺析一下Vue3的響應(yīng)式原理,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Vue3有一定幫助,需要的可以參考一下
    2022-08-08
  • VUE 直接通過JS 修改html對(duì)象的值導(dǎo)致沒有更新到數(shù)據(jù)中解決方法分析

    VUE 直接通過JS 修改html對(duì)象的值導(dǎo)致沒有更新到數(shù)據(jù)中解決方法分析

    這篇文章主要介紹了VUE 直接通過JS 修改html對(duì)象的值導(dǎo)致沒有更新到數(shù)據(jù)中解決方法,結(jié)合實(shí)例形式詳細(xì)分析了VUE使用JS修改html對(duì)象的值導(dǎo)致沒有更新到數(shù)據(jù)的原因與解決方法,需要的朋友可以參考下
    2019-12-12

最新評(píng)論

江陵县| 兴文县| 郑州市| 饶河县| 镶黄旗| 朝阳区| 礼泉县| 乌兰察布市| 杭锦后旗| 白山市| 长葛市| 闽清县| 来凤县| 噶尔县| 山阳县| 阿坝| 民和| 兴文县| 吉安市| 高唐县| 凯里市| 卫辉市| 兰西县| 包头市| 沁水县| 金山区| 洛浦县| 和平区| 循化| 任丘市| 淮北市| 赤城县| 涡阳县| 会宁县| 沧州市| 二连浩特市| 青海省| 昭平县| 长沙市| 龙州县| 康乐县|