WhackAZimp

Whack a Zimp

目前為 2014-06-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        WhackAZimp
// @namespace   InGame
// @include     http://www.dreadcast.net/Main
// @version     1.00
// @grant       none
// @description Whack a Zimp
// ==/UserScript==

whacAZimpNum = 0;

var whacAZimp = (function () {
    var CONGRATULATIONS = 'Well done you are The Whac a Zimp champion!',
        HEIGHT = 4,
        WIDTH = 7,
        LEVELUP = 100,
        initialize,
        levelHolder,
        level,
        li,
        liElements = [],
        tronchesZimp = [],
        prevZimp,
        prepGame,
        prepStage,
        renderZimp,
        renderStage,
        setUpEvents,
        scoreHolder,
        score,
        stage,
        speed = 1100,
        startGame,
        timer,
        diff,
        utils = {
            id: function (id) {
                return document.getElementById(id);
            },
            getNodeAsInt: function (parent) {
                return parent.firstChild.nodeValue - 0;
            },
            setFirstChildValue: function (parentElem, value) {
                parentElem.firstChild.nodeValue = value;
            },
            setTimer: function (func, ms) {
                return setInterval(func, ms);
            }
        };

    initialize = function (a) {
        liElements = [];
        if (undefined !== timer)
            clearInterval(timer);
        prepStage();
        renderStage();
        prepGame();
        setUpEvents();
        startGame(a);
    };

    prepStage = function () {
        li = document.createElement('li');
        li.style.backgroundColor="#ccc";
        li.style.display = "inline-block";
        li.style.height = "50px";
        li.style.margin = "0 0 5px 5px";
        li.style.textDecoration = "none";
        li.style.width = "50px";
        li.style.backgroundImage = "url('http://nsa33.casimages.com/img/2014/06/05/14060503480228466.png')";
        li.style.backgroundSize = "cover";

        stage = document.getElementById('ulStage'+whacAZimpNum);

    };

    renderStage = function () {
        for (var i = 0; i < (HEIGHT * WIDTH); i++) {
            var cloneLi = li.cloneNode(false);

            stage.appendChild(cloneLi);
            liElements.push(cloneLi);
        }
    };

    prepGame = function () {
        levelHolder = utils.id('level'+whacAZimpNum);
        level = utils.getNodeAsInt(levelHolder);
        scoreHolder = utils.id('score'+whacAZimpNum);
        score = utils.getNodeAsInt(scoreHolder);
    };

    setUpEvents = function () {
        stage.addEventListener('click', function(e) {
            if (e.target && 'li' === e.target.nodeName.toLowerCase()) {
                if ('zimp' === e.target.className) {
                    score += 10;
                    utils.setFirstChildValue(scoreHolder, score);
	                e.target.style.backgroundImage = "url('http://nsa34.casimages.com/img/2014/06/05/14060504012010051.jpg')";

                    if (score === level*100) {
                        clearInterval(timer);
                        if (1000 === score) {
                            scoreHolder.parentNode.innerHTML = CONGRATULATIONS;
                        } else {
                            speed -= LEVELUP;
                        
                            if(diff==1)
                             timer = utils.setTimer(renderZimpFacile, speed);
                            else if (diff==-10)
                               timer = utils.setTimer(renderZimpElections, speed);
        

                            level++;
                            utils.setFirstChildValue(levelHolder, level);
                        }
                    }
                }
                else //erreur
        		{
        		  score -= 10;
        		  utils.setFirstChildValue(scoreHolder, score);
	              e.target.style.backgroundImage = "url('http://nsa34.casimages.com/img/2014/06/05/14060504012010051.jpg')";
        		  setTimeout(function(){e.target.style.backgroundImage = "url('http://nsa33.casimages.com/img/2014/06/05/14060503480228466.png')";},speed);
        		  
        		  if (level > 1 && score < ((level-1)*100))
        		  {
        		      clearInterval(timer);
                      speed += LEVELUP;
                      if(diff==1)
                         timer = utils.setTimer(renderZimpFacile, speed);
                      else if (diff==-10)
                         timer = utils.setTimer(renderZimpElections, speed);        
                      
                      level--;
                      utils.setFirstChildValue(levelHolder, level);
        		    } 
        		}
            }
        }, false);
    };

    startGame = function (a) {
        diff = a;
        if(diff==1)
           timer = utils.setTimer(renderZimpFacile, speed);
        else if (diff==-10)
        {
           tronchesZimp = ["Antheim.jpg", "Dann.png","ElfeSombre.jpg","Fitz.jpg","Kinchaka.jpg","Malia.png","Oshean.jpg","Odul.png","Sÿllia.png","Zarah.png"];
            
           timer = utils.setTimer(renderZimpElections, speed);
        }
    };

    
    renderZimpFacile = function () {
        if (undefined !== prevZimp) 
        {   
            prevZimp.className = '';
            prevZimp.style.backgroundImage = "url('http://nsa33.casimages.com/img/2014/06/05/14060503480228466.png')";
        }
        prevZimp = liElements[Math.floor((Math.random()*(HEIGHT * WIDTH))+1)-1];
        prevZimp.className = 'zimp';
    	if(level <= 2)
            prevZimp.style.backgroundImage = "url('http://nsa34.casimages.com/img/2014/06/05/140605035115599491.png')";
    	else
            prevZimp.style.backgroundImage = "url('http://www.dreadcast.net/images/avatars/Elea.png')";
     };
  
    
    renderZimpElections = function () {
        if (undefined !== prevZimp) 
        {   
            prevZimp.className = '';
            prevZimp.style.backgroundImage = "url('http://nsa33.casimages.com/img/2014/06/05/14060503480228466.png')";
        }
        prevZimp = liElements[Math.floor((Math.random()*(HEIGHT * WIDTH))+1)-1];
        prevZimp.className = 'zimp';
              	
        var tronche = tronchesZimp[Math.floor(Math.random()*tronchesZimp.length)]    
            prevZimp.style.backgroundImage = "url('http://www.dreadcast.net/images/avatars/"+tronche+"')";
        }
    

    return {
        init: initialize
    };
})();


Deck.prototype.executeCommandSave = Deck.prototype.executeCommand;

Deck.prototype.executeCommand=function(a,b){
    var c=$("#"+b+" .ligne_ecriture input").val();
    $.ajaxSetup({async: false});
    this.executeCommandSave(a,b);
    $.ajaxSetup({async: true});    
    
    if(c.toLowerCase() === "waz")
    {
       $("#" + b + " .ligne_ecrite_fixed:last").html($("#" + b + " .ligne_ecrite_fixed:last").html() + '<div>Tapez waz niveauDeDifficulté avec </br> Facile : frappe le zimp. Tu pers dix points quand tu te plantes et en gagne dix quand tu réussis.</br> Moyen : Ne frappe pas le rebz où tu perds 50 points! (à venir) </br> Difficile : Moyen + Tu perds la partie si tu touches trois rebzs! (à venir) </br> Hardcore : Difficile + Tu perds dix points toutes les dix secondes. (à venir) </br></br> Elections : défoule toi sur les candidats!</div>');        
    }
    else if(c.toLowerCase() === "waz facile")
    { 
        whacAZimpNum++;
        $("#" + b + " .ligne_ecrite_fixed:last").html($("#" + b + " .ligne_ecrite_fixed:last").html() + '<section style="width: 390px; padding : 5px 0;"><ul id="ulStage'+whacAZimpNum+'" style="padding : 0; margin :0; cursor : url(http://www.dreadcast.net/images/objets/mini/gant-hydro.png), auto;" ></ul><p>Score: <span id="score'+whacAZimpNum+'">0</span> points!</p><p>Level: <span id="level'+whacAZimpNum+'">1</span></p></section>');
        whacAZimp.init(1);
    }
    else if(c.toLowerCase() === "waz elections")
    { 
        whacAZimpNum++;
        $("#" + b + " .ligne_ecrite_fixed:last").html($("#" + b + " .ligne_ecrite_fixed:last").html() + '<section style="width: 390px; padding : 5px 0;"><ul id="ulStage'+whacAZimpNum+'" style="padding : 0; margin :0; cursor : url(http://www.dreadcast.net/images/objets/mini/gant-hydro.png), auto;" ></ul><p>Score: <span id="score'+whacAZimpNum+'">0</span> points!</p><p>Level: <span id="level'+whacAZimpNum+'">1</span></p></section>');
        whacAZimp.init(-10);
    }
};