2018-01-23

微信小程序(頭腦王者)


前言

仿照熱門小游戲(頭腦王者)制作一個簡單的出題小程序,自動是比較自動,但沒有數(shù)據(jù),如果集全民之力,收集題庫,那才完美。(最后有下載鏈接)


1,首頁



js文件


var data_util = require('../../util/util.js')

//由ID獲得一個題目

function change_question(that){

? let ques_id = Math.floor(Math.random()*5);

? let right_id = Math.floor(Math.random() * 4);

? let aques = data_util.get_question(ques_id, right_id);

? //設置題目顯示

? that.setData({

? ? question: aques.question,

? ? answer_list: aques.answers,

? ? right_answer: right_id

? })

}

//計時計分

var tc;

var col_temp = [0,0,0,0];

function timing_count(that) {

? if(that.data.time_lost>=100){

? ? clearTimeout(tc);

? ? col_temp[that.data.right_answer]=2;

? ? ? that.setData({

? ? ? ? color_select:col_temp

? ? ? });

? ? ? //reset_now_state(this);

? ? ? first_start(that,1500);

? ? //答題錯誤

? ? return;

? }

? tc = setTimeout(function () {

? ? let ts = that.data.time_lost + 1;

? ? that.setData({

? ? ? time_lost:ts,

? ? ? score:100-ts

? ? });

? ? timing_count(that);

? },100)

}

//重置狀態(tài)

function reset_now_state(that) {

? //clearTimeout(tc);

? col_temp = [0,0,0,0]

? that.setData({

? ? time_lost: 0,

? ? score:100,

? ? color_select:col_temp

? });

}

//題目設置間隙

function first_start(that,ts) {

? clearTimeout(tc);

? setTimeout(function () {

? ? reset_now_state(that);

? ? change_question(that);

? ? timing_count(that);

? ? that.setData({

? ? ? can_select:false

? ? });

? },ts);

}

Page({

? data: {

? ? //答題時間為10秒

? ? time_lost:0,

? ? //分數(shù)與流逝時間成反比

? ? score:100,

? ? //問題

? ? question:"blank",

? ? //答案表

? ? answer_list: ["a","b","c","d"],

? ? //選擇后選項顏色變化

? ? color_select:[0,0,0,0],

? ? //正確答案

? ? right_answer:0,

? ? //選擇的答案

? ? select_id:0,

? ? //總分

? ? totalscore:0,

? ? //是否可以開始答題

? ? can_select:true

? },

? onLoad: function () {

? ? first_start(this,2000);

? },

? //選擇的答案

? select_answer:function(evt){

? ? if(this.data.can_select){

? ? ? return;

? ? }

? ? this.setData({

? ? ? can_select:true,

? ? ? select_id:evt.target.id

? ? });

? ? //選擇正確

? ? if (evt.target.id == this.data.right_answer){

? ? ? console.log("right");

? ? ? //change_question(this);

? ? ? col_temp[evt.target.id]=2;

? ? ? this.setData({

? ? ? ? totalscore:this.data.totalscore+this.data.score,

? ? ? ? color_select:col_temp

? ? ? });

? ? ? //reset_now_state(this);

? ? ? first_start(this,1000);

? ? //答題錯誤

? ? }else{

? ? ? console.log("wrong");

? ? ? col_temp[this.data.right_answer]=2;

? ? ? col_temp[evt.target.id]=1;

? ? ? this.setData({

? ? ? ? color_select:col_temp

? ? ? });

? ? ? //reset_now_state(this);

? ? ? first_start(this,2000);

? ? }

? }

})


wxss文件


.score_txt{

? height: 100%;

? display: flex;

? flex-direction: column;

? align-items: center;

? justify-content: space-between;

? box-sizing: border-box;

}

.question_txt{

? display: flex;

? flex-direction: column;

? align-items: center;

? margin-top: 50rpx;

? color: #10c1f3;

}

.sp_box{

? height: 100%;

? display: flex;

? flex-direction: column;

? align-items: center;

? justify-content: space-between;

? box-sizing: border-box;

? margin-top: -15rpx;

}

.score_position{

? width: 134rpx;

? height: 56rpx;

}

.answer_group{

? width: 100%;

? margin-top: 50rpx;

}

.back_bg{

? width: 750rpx;

? height: 338rpx;

}

.total_score_txt{

? height: 100%;

? display: flex;

? flex-direction: column;

? align-items: center;

? justify-content: space-between;

? box-sizing: border-box;

? color: #ef463a;

? margin-top: 50rpx;

}


2,附件


下載地址:點擊(百度網(wǎng)盤)

復制地址:https://pan.baidu.com/s/1qZfKGWk

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容