瓦尔麻烦! d:

时间:2014-06-02 07:28:16

标签: javascript variables

所以..我正在制作增量游戏,每个结构都会给你一定数量的Cookie。游标给你两个Cookies,我希望Rep给你五个cookie。但是,他们两个都给了两个Cookies,我不知道如何改变它。这是我的片段。 另外,我如何制作它以显示我的总cps? CPS是每秒的cookie。我有这个,但它也没有。

var cookies = 0;

function cookieClick(number){
  cookies = cookies + number;
  document.getElementById("cookies").innerHTML = cookies;
};

var cps = 0;

function cps(cursors, rep){
  cps = cursors + rep;
  document.getElementById('cps').innerHTML = cps;
};

var cursors = 0;

function buyCursor(number){
  var cursorCost = Math.floor(10 * Math.pow(1.1,cursors));     //works out the cost of this cursor
  if(cookies >= cursorCost){                                   //checks that the player can afford the cursor
    cursors = cursors + 1;                                   //increases number of cursors
    cookies = cookies - cursorCost;                          //removes the cookies spent
    document.getElementById('cursors').innerHTML = cursors;  //updates the number of cursors for the user
    document.getElementById('cookies').innerHTML = cookies;  //updates the number of cookies for the user
  };
  var nextCost = Math.floor(10 * Math.pow(1.1,cursors));       //works out the cost of the next cursor
  document.getElementById('cursorCost').innerHTML = nextCost;  //updates the cursor cost for the user
}; 

var rep = 0;

function buyRep(){
  var repCost = Math.floor(50 * Math.pow(1.2,rep));     //works out the cost of this rep
  if(cookies >= repCost){                                   //checks that the player can afford the rep
    rep = rep + 1;                                   //increases number of rep
    cookies = cookies - repCost;                          //removes the cookies spent
    document.getElementById('rep').innerHTML = rep;  //updates the number of rep for the user
    document.getElementById('cookies').innerHTML = cookies;  //updates the number of cookies for the user
  };
  var nextCost = Math.floor(50 * Math.pow(1.2,rep));       //works out the cost of the next rep
  document.getElementById('repCost').innerHTML = nextCost;  //updates the rep cost for the user
};


window.setInterval(function(){

  cookieClick(cursors);
  cookieClick(rep);

}, 1000);

0 个答案:

没有答案