Kazu Ate Game

    
      
  • /*
     * @title Kazu Ate Game
     * @description my bookmarklet
     * @include http://*
     * @license MIT License
     * @require 
     * @javascript_url
     * @private
     */
    (()=> {
      var ANS = parseInt(Math.random() * 20) + 1;
      // console.log(ANS);
      // init GAME obj
      var GAME = GAME || {
         "start": true,
         "count": 0,
         "score": 0,
         "life": 7,
        hint: val=> {
          if (val > ANS) {
            return 'Ookii yo!';
          } 
          else if (val < ANS) {
            return 'Chiisai yo!';
          } else if (!/\d+/.test(val)) {
            return 'err';
          } else {
            return 'correct';
          }
        }
      };
      while (GAME.life > 0) {
        if (GAME.start && GAME.score !== 0) {
          ANS = parseInt(Math.random() * 20) + 1;
        }
        GAME.start = false;
        var res = parseInt(window.prompt('Kazu wa [ 1-20 ] ??'));
        if (GAME.hint(res) == 'err') {
          alert('Suuji wo iretene!!');
        } else if (GAME.hint(res) == 'correct') {
          alert('Seikai !!');
          GAME.start = true;
          ++GAME.score;
        } else {
          alert(GAME.hint(res));
        }
        --GAME.life;
        res = null;
      }
      alert('Answer: ' + ANS + '  SCORE = ' + GAME.score);
    })();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2016/03/16 22:00:49 - 2016-03-16
  2. 2016/03/16 20:54:40 - 2016-03-16
  3. 2016/03/16 20:45:41 - 2016-03-16
  4. 2016/03/16 20:41:39 - 2016-03-16