(编辑)试图在javascript中创建一个简单的乐透游戏

时间:2016-12-13 15:43:48

标签: javascript html

尝试在javascript中创建一个简单的乐透游戏

我试图创建一个简单的小型乐透游戏,但在java脚本中使用20个数字和4个球,因此它非常适合创建一个随机票给用户,另一个作为随机乐透号码而不重复自己。 ....对于随机生成器,每个匹配的数字都涉及到一个金钱系统,用户获得x数量,数字变为绿色。

应该只需点击一下即可完成所有操作,无论是赢或输类型,还是按钮再次播放,同时游戏会跟踪赢或输的金额..任何帮助都会很棒帮助...



var playcost = 1;
var match1 = 5;
var match2 = 10;
var match3 = 20;
var match4 = 40;
var FirstBall = 0;
var SecondBall = 0;
var ThirdBall = 0;
var ForthBall = 0;

function lottoGen()
{
  setInterval(
          function lottoGen(min , max)
  {
      return Math.round(Math.random() * (20 - 1) + 1);
  }
   function usersNumbers();
  {
      var numbers = [], 
          random;
    
      for(var i = 0; i < 4; i++)
      {   
        
        random = lottoGen(1, 20);
        while(numbers.indexOf(random) !== -1)
        {
            console.log("upps (" + random + ") it is in already.");
            random = lottoGen(1, 20);
            console.log("replaced with: (" + random + ").");
        }
        numbers.push(random);
      }
    output.value = numbers.join(", ");
  }
  btn.onclick = usersNumbers;
  
}
  //Update the scoreboard 
           document.getElementById("lottoGen").innerHTML = "numbers :"+matches;
           document.getElementById("usersNumbers").innerHTML = "numbers  :"+matches;
            
           colourTheTeams(); 
            
           //Tick the clock 
           clockSeconds++;
           document.getElementById("matches").innerHTML = "matches : "+playcost;
          }
    ,1000); 
}

  
  
  
  
  
  
  function colourmatches()
{
 
  if(numbers == usersNumbers)
  {
    document.getElementById("numbers").style.color = "Green";
    document.getElementById("usersNumbers").style.color = "green";
  }
 
  else if(numbers > usersNumbers)
  {
    document.getElementById("numbers").style.color = "red";
    document.getElementById("usersNumbers").style.color = "black";    
  }
  
  else
  {
    document.getElementById("numbers").style.color = "black";
    document.getElementById("usersNumbers").style.color = "red";        
  }
  
  
}
&#13;
<!DOCTYPE html>
<HTML>
  <HEAD>
    <TITLE>The Lotto Game</TITLE>
  </HEAD>
  <BODY>
    <H1>The Lotto Game</H1>
    <H1 id="matches">Total :€10</H1>
    <H1 id="FirstBall"> </H1>
    <H1 id="SecondBall"> </H1>
    <H1 id="ThirdBall"> </H1>
    <H1 id="ForthBall"> </H1>
    <div id="randomNumbers"></div>
<H1 id="usersNumbers">your ticket :</H1>
    
<button class="lottoGen">Run the Lottery</button>
<button class="Play-Again">Play Again!</button>

  </BODY>
</HTML>
&#13;
&#13;
&#13;

0 个答案:

没有答案