Advertisement
Guest User

My code

a guest
Sep 16th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <link rel="stylesheet" href="style.css" />
  5.         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  6.         <title>Clicker!</title>
  7.     </head>
  8.    
  9.     <body>
  10.         <h3 id="head1"><span id="Aliens">0</span> aliens</h3>
  11.         <h3 id="head2"><span id="Empires">0</span> empires</h3>
  12.         <h3 id="head3"><span id="Spaceships">0</span> spaceships</h3>
  13.         <h3 id="head4"><span id="Planets">0</span> planets</h3>
  14.         <h3 id="head5"><span id="SolarSystems">0</span> solarsystems</h3>
  15.         <h3 id="head6"><span id="Galaxies">0</span> galaxies</h3>
  16.         <h3 id="head7"><span id="Workers">0</span> workers</h3>
  17.         <!--<p>You need <span id="test">0</span> aliens to hire a worker!</p>--> <!--Need to make dynamic-->
  18.         <img id="Alien" src="alien.png">
  19.         <img id="whirl" src="galaxy.jpg" style="width:25em; height:25em;">
  20.         <button id="Purchase">Hire Workers</button>
  21.     </body>
  22.     <script>   
  23.     $(function() {
  24.     $('#Alien').click(function() {
  25.         incrementCounter();
  26.     });
  27.  
  28.     function incrementCounter() {
  29.         var previousCounter = parseInt($("#Aliens").text());
  30.         previousCounter = isNaN(previousCounter) ? 0: ++previousCounter;
  31.  
  32.         $("#Aliens").text(previousCounter);
  33.  
  34.         if(previousCounter % 25 === 0) {
  35.             $("#Empires").text(previousCounter/25);
  36.         }
  37.        
  38.         if(previousCounter % 100 === 0) {
  39.             $("#Spaceships").text(previousCounter/100);
  40.         }
  41.        
  42.         if(previousCounter % 1000 === 0) {
  43.             $("#Planets").text(previousCounter/1000);
  44.         }
  45.        
  46.         if(previousCounter % 10000 === 0) {
  47.             $("#SolarSystems").text(previousCounter/10000);
  48.         }
  49.        
  50.         if(previousCounter % 100000 === 0) {
  51.             $("#Galaxies").text(previousCounter/100000);
  52.         }
  53.  
  54.     }
  55.  
  56.     function resetCounter() {
  57.         $("#Aliens").text(0);
  58.     }
  59. });
  60.    
  61.     </script>  
  62.     <script id="s2">
  63.     $(function() {
  64.     $('#Purchase').click(function() {
  65.         automaticCounter();
  66.     });
  67.    
  68.     function automaticCounter() {
  69.         var workers = parseInt($("#Workers").text());
  70.         workers = isNaN(workers) ? 0: ++workers;
  71.        
  72.         $("#Workers").text(workers);
  73.        
  74.         var autoCounter = parseInt($("#Aliens").text());
  75.         autoCounter = isNaN(autoCounter) ? 0: autoCounter - 10 * workers;
  76.  
  77.         $("#Aliens").text(autoCounter);
  78.        
  79.         var workerCheck = setInterval(function(){
  80.             var workers = parseInt($("#Workers").text());
  81.                 if( workers > 0 ){
  82.                     for(var i = 0; i < workers; i++){
  83.                     $("#Alien").click();      
  84.                     }
  85.                 }
  86.         },5000);
  87.     }
  88.     });
  89.     </script>
  90. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement