Newer
Older
Skillsemi2023_WEB_Otaki_Nemoto / beautyVote.js

class Question{
    constructor(){
        this.question = 0;
        this.answer = 0;
        this.choiceA = 0;
        this.choiceB = 0;
        this.choiceC = 0;
        this.choiceD = 0;
    }
    join(question, answer, choiceA, choiceB, choiceC, choiceD){
        this.question = question;
        this.answer = answer;
        this.choiceA = choiceA;
        this.choiceB = choiceB;
        this.choiceC = choiceC;
        this.choiceD = choiceD;
    }
    getQustion(){
        return this.question;
    }
    getAnswer(){
        return this.answer;
    }
    getChoice(idx){
        return this.choices[idx]; 
    }
    
}




class Player{
    constructor(){
        this.points = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
        this.choice = 0;
    }
    calcScore(){
        var score = 0;
        for(var i = 0; i < MAX_ROUND; i ++){
            if(this.points[i] == CORRECT){
                score ++;
            }
        }
        return score;
    }
}



function setup(){
    canvasSize(960, 1200);
    lineW(3);
    //loadImg(0, "image/bg.png");
    timer = 0;
    setQuestion(round);
}


function mainloop(){
    if(timer < 900){
        timer ++;
    }
    fill("silver");
    setAlp(50);
    fRect(50, 50, 855, 100, "black");
    fText("Q.", 110, 100, 50, "white");
    fRect(45, 295, 865, 560, "white");
    fRect(50, 300, 400, 250, "black");
    fRect(500, 300, 400, 250, "black");
    fRect(50, 600, 400, 250, "black");
    fRect(500, 600, 400, 250, "black");

    sRect(45, 880, 865, 40, "black");
    fRect(45, 880, (timer/900)*865, 40, "red");
    setAlp(100);

    
    fText("A.", 100, 425, 50, "white");
    fText("B.", 550, 425, 50, "white");
    fText("C.", 100, 725, 50, "white");
    fText("D.", 550, 725, 50, "white");

    fText(question[round].question, 480, 100, 30, "white");    
    fText(question[round].choiceA, 275, 425, 30, "white");
    fText(question[round].choiceB, 725, 425, 30, "white");
    fText(question[round].choiceC, 275, 725, 30, "white");
    fText(question[round].choiceD, 725, 725, 30, "white");

    fText(int(timer/30), 900, 1100, 50, "red");

    setAlp(50);

    fText((round+1) + "回戦", 100, 1000, 50, "red");
    for(var i = 0; i < MAX_ROUND; i ++){
        if(player.points[i] == CORRECT){
            fText("O", 480 + 50*i, 1000, 50, "red");
        }
        else if(player.points[i] == WRONG) {
            fText("X", 480 + 50*i, 1000, 50, "blue");
        }
        else{
            fText("*", 480 + 50*i, 1000, 50, "black");
        }
    }

    if(round >= MAX_ROUND){
        fText("あなたのスコアは" + player.calcScore() + "点です", 480, 600, 80, "gold");
    }

    if(tapC == 1){
        tapC ++;

        if(round < MAX_ROUND){ 
            if(50 <= tapX && tapX <= 450 && 300 <= tapY && tapY <= 550){
                player.choice = A;
                checkAnswer();
            }
            else if(500 <= tapX && tapX <= 900 && 300 <= tapY && tapY <= 550){
                player.choice = B;
                checkAnswer();
            }
            else if(50 <= tapX && tapX <= 450 && 600 <= tapY && tapY <= 850){
                player.choice = C;
                checkAnswer();
            }
            else if(500 <= tapX && tapX <= 900 && 600 <= tapY && tapY <= 850){
                player.choice = D;
                checkAnswer();
            }
        }   
    }    
}




function setQuestion(round){
    question[round].join(questions[round], answer[round], choices[round][A], choices[round][B], choices[round][C], choices[round][D]);
}


function checkAnswer(){
    if(player.choice == question[round].answer){
        player.points[round] = CORRECT;
    }
    else{
        player.points[round] = WRONG;
    }
    timer = 0;
    round ++;
    if(round < MAX_ROUND){
        setQuestion(round);
    }
}


var round = 0;
var MAX_ROUND = 10;

var timer = 0;
var select = 0;

var A = 0;
var B = 1;
var C = 2;
var D = 3;
var CORRECT = 1;
var WRONG = 0;

var question = new Array(MAX_ROUND);
for(var i = 0; i < MAX_ROUND+1; i ++){
    question[i] = new Question();
}

var player = new Player();


var questions = ["「にっこり」の対義語は?",
                "もっとも年齢が高いのは?", 
                "中国語で「勉強」意味は?",
                "焼き肉の「テッポウ」はどこの部位?",
                "アフリカ大陸でもっとも面積が大きい国は?",
                "実在する生き物は?",
                "カスタネットの名前の由来となったものは?",
                "名前が人物に由来しているのは?", 
                "ジンベイザメは英語で何シャーク?",
                "心臓がない生き物は?"];

var answer = [C, A, B, B, C, C, C, C, B, B];

var choices = [["がっくり", "げっそり", "むっつり", "しっとり"],
                ["ドナルド・トランプ", "ボリス・ジョンソン", "ウラジーミル・プーチン", "アンゲラ・メルケル"],
                ["喧嘩っ早い", "無理やり", "細かい", "意地悪な"],
                ["食道", "直腸", "こめかみ", "胃袋"],
                ["エチオピア", "リビア", "アルジェリア", "ケニア"],
                ["キリンコウモリ", "ライオンコウモリ", "ウサギコウモリ", "オオカミコウモリ"],
                ["ハサミの刃", "貝の殻", "栗の実", "両手"],
                ["そら豆", "えんどう豆", "いんげん豆", "ひよこ豆"],
                ["エレファント", "ホエール", "ダイナソー", "メガ"],
                ["カニ", "ナマコ", "タコ", "ホタテ"]];