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

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

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

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

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

第一步先畫一個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">答對{{ 0 }}題</p>
      </div>
  </div>

先畫一個div里面放一張圖片,下面顯示答對題目數(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">答對{{ 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;">{{ "題目內(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 class="header">
      <div>
        <img style="height: 143px;width: 189px;margin-top: 30px;margin-bottom: 10px;" src="./img/tuzi.png" alt="">
        <p class="text1">答對{{ 0 }}題</p>
        <p class="text1">累計獎勵</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;">{{ "題目內(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">回答錯誤!</p>
    </div>
    <p class="text1" @click="xyt"> {{ "下一題" }}</p>
  </div>

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

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

// 0未選,1選對,2選錯
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; // 答案錯誤
      }
  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; // 答案錯誤
      }
  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; // 答案錯誤
      }
  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; // 答案錯誤
      }
  if (aaa.value == 0 & bbb.value == 0 & ccc.value == 0 & ddd.value == 0) {
    ddd.value = 1
  }
}
let xyt=()=>{
if(  timusl.value<=10){
  timusl.value++
}
}

最后稍微加一點點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>

就可以達到一個卡片答題的效果了,但是代碼又重又呆,我們再優(yōu)化一點點代碼,把題目循環(huá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">答對{{ correctCount }}題</p>
        <p class="text1">累計獎勵</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">回答錯誤!</p>
    </div>
    <div v-if="currentQuestionIndex >= 10">
      <p class="text1">恭喜回答完所有題目,您一共答對{{ 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é)是從哪個朝代開始成為固定的節(jié)日?",
    options: ["唐", "宋", "元", "明"],
    correctAnswer: "A"
  },
  {
    content: "月餅最初是用來做什么的?",
    options: ["祭奉月神的貢品", "饋贈親友的禮物", "節(jié)日食品", "地方小吃"],
    correctAnswer: "A"
  },
  {
    content: "在古代月圓和月缺一般形容什么?",
    options: ["天氣好壞", "兇吉象征", "身體是否健康", "悲歡離合"],
    correctAnswer: "D"
  },
  {
    content: "傳說中嫦娥是誰的妻子?",
    options: ["黃帝", "后裔", "大禹", "吳剛"],
    correctAnswer: "B"
  },
  {
    content: "嫦娥下凡(打一花名)?",
    options: ["月季", "玫瑰", "牡丹", "百合"],
    correctAnswer: "A"
  },
  {
    content: "中秋過后又重陽(打一詩句)?",
    options: ["月上柳梢頭", "明月幾時有", "一節(jié)復一節(jié)", "抬頭望明月"],
    correctAnswer: "C"
  },
  {
    content: "“解落三秋葉,能開二月花”描寫的是哪一種自然現(xiàn)象?",
    options: ["雪", "月", "風", "霜"],
    correctAnswer: "C"
  },
  {
    content: "以下哪個不是跟中秋節(jié)有關(guān)的傳說?",
    options: ["精衛(wèi)填海", "吳剛伐桂", "玉兔搗藥", "嫦娥奔月"],
    correctAnswer: "A"
  },
  {
    content: "八月十五又稱什么節(jié)?",
    options: ["月餅節(jié)", "團圓節(jié)", "故鄉(xiāng)節(jié)", "詩人節(jié)"],
    correctAnswer: "B"
  },
  {
    content: "在傳說中,哪位皇帝曾在中秋夢游月宮?",
    options: ["秦始皇嬴政", "唐玄宗李隆基", "宋徽宗趙佶", "明成祖朱棣"],
    correctAnswer: "B"
  },
  // 其他題目...
];
let currentQuestionIndex = ref(1); // 當前題目的索引
let currentQuestion = ref(questions[currentQuestionIndex.value - 1]); // 當前題目的內(nèi)容
let selectedAnswer = ref(''); // 用戶選擇的答案
let isAnswered = ref(false); // 是否已回答
let correctCount = ref(0); // 答對的題目數(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實現(xiàn)猜謎卡片游戲的文章就介紹到這了,更多相關(guān)vue游戲內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

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

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

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

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

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

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

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

    解決Vue項目Network:?unavailable的問題

    項目只能通過Local訪問而不能通過Network訪問,本文主要介紹了解決Vue項目Network:?unavailable的問題,具有一定的參考價值,感興趣的可以了解一下
    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ū)別,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-11-11
  • vue+elementUI組件table實現(xiàn)前端分頁功能

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

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

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

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

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

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

    淺析一下Vue3的響應式原理

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

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

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

最新評論

江孜县| 青神县| 沛县| 通道| 慈利县| 吉木乃县| 怀仁县| 南木林县| 洞口县| 新兴县| 厦门市| 呼和浩特市| 砀山县| 石门县| 马关县| 莱州市| 洛扎县| 积石山| 台东市| 舟山市| 云和县| 永嘉县| 伊春市| 南京市| 长乐市| 榆树市| 南和县| 青铜峡市| 鄯善县| 元阳县| 古丈县| 湘潭市| 滨州市| 章丘市| 竹山县| 乳山市| 河北区| 乡宁县| 宣武区| 宜春市| 丰城市|