cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <html>
    <head>
        <meta charset="UTF-8" />
        <title>hello phaser!</title>
        <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1566177/phaser.min.js"></script>
    </head>
    <body>

    <script type="text/javascript">
    window.onload = function() {
//var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'fdsa', { preload: preload, create: create, update: update, render: render });
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-game', { preload: preload, create: create });
function preload() {
  game.load.crossOrigin='anonymous';
  game.load.image('background','https://s3-us-west-2.amazonaws.com/s.cdpn.io/1566177/6qADJICYOg_ZH2h1514872157_1514872250.png');
  game.load.image('button','https://s3-us-west-2.amazonaws.com/s.cdpn.io/1566177/bottan01.gif');
  game.load.script('webfont','//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
  
  
}
var button_a;
var button_b;
var button_c;
var question_text;
var answer_a_text;
var answer_b_text;
var answer_c_text;
var response_text;
var current_question = 0;
var questions;
var answer_choices = [];
var correct_answers;
var number1;
var number2;
var x,y,z; 
var title_text;
var score_text;
var score=0;
var timer_text;
var timer = 0;
      
WebFontConfig = {
    //  'active' means all requested fonts have finished loading
    //  We set a 1 second delay before calling 'createText'.
    //  For some reason if we don't the browser cannot render the text the first time it's created.
    active: function() { game.time.events.add(Phaser.Timer.SECOND, createQuestionText, this); },
    //active: function() { game.time.events.add(Phaser.Timer.SECOND*2, createAnswerAText, this); },
    //  The Google Fonts we want to load (specify as many as you like in the array)
    google: {
      families: ['Roboto']
    }
};
      
function create() {
    game.add.sprite(0,0,'background');
    button_a = game.add.button(95, 160, 'button', buttonAPressed, this, 'over', 'out', 'down');
    button_a = game.add.button(95, 260, 'button', buttonBPressed, this, 'over', 'out', 'down');
    button_a = game.add.button(95, 360, 'button', buttonCPressed, this, 'over', 'out', 'down');

  //問題の配列
  number1 = Math.floor(Math.random()*10) + 1;
  number2 = Math.floor(Math.random()*10) + 1;
  
  
  questions = "" + number1 + " + " + number2;

  correct_answers = number1 + number2;
  
   x = Math.floor(Math.random() * 3);
  answer_choices[x] = correct_answers - 1;
  do {
     y = Math.floor(Math.random() * 3);
    answer_choices[y] = correct_answers; 
  } while (x == y)
   z = 3-x-y;
  answer_choices[z] = correct_answers + 1;
  console.log(answer_choices);
    //API call: retreive the progress by reading current_question value
 
timer = game.time.create(2000, false);
  timer.add(1500,updateText);
  timer.start();
  
  //テキスト内容
   question_text = game.add.text(game.world.centerX, 120, "");
    question_text.anchor.setTo(0.5);
    question_text.font = 'Roboto';
    question_text.fontSize = 60;
    question_text.fill = '#00FFCC';
    title_text = game.add.text(game.world.centerX, 40,"calculation ドリル");
    title_text.anchor.setTo(0.5);
    title_text.font='Roboto';
    title_text.fontSize = 40;
    title_text.fill='#FF0';
    answer_a_text = game.add.text(300, 200, "");
    answer_a_text.font = 'Roboto';
    answer_a_text.font.align = 'left';
    answer_a_text.fontSize = 60;
    answer_a_text.fill = '#FFF';
    answer_a_text.inputEnabled = true;
    answer_a_text.events.onInputUp.add(buttonAPressed, this);
    answer_b_text = game.add.text(300, 300, "");
    answer_b_text.font = 'Roboto';
    answer_b_text.font.align = 'left';
    answer_b_text.fontSize = 60;
    answer_b_text.fill = '#FFF';
    answer_b_text.inputEnabled = true;
    answer_b_text.events.onInputUp.add(buttonBPressed, this);
    answer_c_text = game.add.text(300, 400, "");
    answer_c_text.font = 'Roboto';
    answer_c_text.font.align = 'left';
    answer_c_text.fontSize = 60;
    answer_c_text.fill = '#FFF';
    answer_c_text.inputEnabled = true;
    answer_c_text.events.onInputUp.add(buttonCPressed, this);
    response_text = game.add.text(game.world.centerX, 550,"当てはまる問題にクリック!!");
    response_text.anchor.setTo(0.5);
    response_text.font = 'Roboto';
    response_text.fontSize = 40;
    response_text.fill = '#FF3333';
    score_text = game.add.text(700, 40,'Score: '+ score);
    score_text.anchor.setTo(0.5);
    score_text.font = 'Roboto';
    score_text.fontSize = 20;
    score_text.fill = '#FFF';

}
      
function buttonAPressed () {
  if(current_question<questions.length)
  if(correct_answers==answer_choices[0])
  {
    correctAnswer();
    if(current_question<questions.length)
    {
      updateText();
    }else {
      quizFinished();
    }
  }else {
    incorrectAnswer();
  }
}
function buttonBPressed () {
  if(current_question<questions.length)
  if(correct_answers==answer_choices[1])
  {
    
    correctAnswer();
    if(current_question<questions.length)
    {
      updateText();
    }else {
      quizFinished();
    }
  }else {
    incorrectAnswer();
  }
}
function buttonCPressed () {
  if(current_question<questions.length)
  if(correct_answers==answer_choices[2])
  { 
    correctAnswer();
    if(current_question<questions.length)
    {
      updateText();
    }else {
      quizFinished();
    }
  }else {
    incorrectAnswer();
  }
}
function quizFinished()
{
  //API call: achievement unlock
  response_text.text="終了!!";
  
  //answer_a_text.text = "もう一回";
  //answer_b_text.text = "終了!!";
  //answer_c_text.text = ;
}
      
function correctAnswer()
{
  console.log(score);
  score += 10;

  current_question+=1;
  create();
  //API call: update progress by storing current_question
}

function incorrectAnswer()
{
  score -= 10;
  score_text.text = 'Score: '+ score;
  response_text.text="残念はずれ!ァヵン(σ`д゜)ベェ";
}
      
function updateText()
{
  question_text.text = questions;
  
  answer_a_text.text = answer_choices[0];
  answer_b_text.text = answer_choices[1];
  answer_c_text.text = answer_choices[2];
  
}
};
      
      
    </script>

    </body>
</html>


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console