'; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo '
Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


A little bit of javascript help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Crossrocket.1
Master Cheater
Reputation: 0

Joined: 16 Nov 2007
Posts: 307

PostPosted: Sun Nov 23, 2008 1:32 pm    Post subject: A little bit of javascript help Reply with quote

Code:
<html>
<head><link rel='stylesheet' type='text/css'href='Gssstyle2.css'>
<title>Guessin' game</title>
<body background = "AWESOMENESS.jpg">
<script language="Javascript">
var guessed = 0;
var wins = 0;
var fails = 0;
var gnumbers = new Array();

   function resetGame() //function to confirm the reset
   {
      var confirmReset = window.confirm("Are you sure you want to reset the game?");
      if(confirmReset == true)//sees if the user clicked yes and resets
      {
         guessed = 0;
         wins = 0;
         fails = 0;
         updateStats();
         document.getElementById('resultDiv').style.display = "none";
         document.getElementById('playbtn').disabled = false;
         alert ("Your form has been reset")
      } else                  //alert boxes
         {
            alert   ("Your form has not been reset")
         }
   }
     
   function generateNum() //function to generate a random number
   {
      if(guessed > 4){
         ShowRank();
         return;
      }
      var ranNum = Math.round(Math.random()*100);
      var gues = document.getElementById('txtGues').value;
      if(gues < 0 || gues > 100){
         alert("Only numbers between 0-100");
         return
      }
      for(var i=1; i<6; i++){
         if(gnumbers[i] == gues){
            alert("You tried it with this number already, choose another!");
            return;
         }
      }
     
      alert("Your random number is " + ranNum);
      guessed += 1;
      if(ranNum == gues)
      {
         wins += 1;
         updateStats();
         alert ("Correct! You rule xD");
      } else {
         var difference;
         fails += 1;
         updateStats();
         if(ranNum > gues){
            difference = ranNum-gues;
            if(difference < 6){
               alert("Wrong, your guessed number was lower! But you were very close!");
            } else {
               alert("Wrong, your guessed number was lower!");
            }
         } else {
            difference = gues-ranNum;
            if(difference < 6){
               alert("Wrong, your guessed number was higher! But you were very close!");
            } else {
               alert("Wrong, your guessed number was higher!");
            }
         }
      }
      gnumbers[guessed] = gues;
      if(guessed > 4){
         document.getElementById('playbtn').disabled = true;
         ShowRank()
      }
     
   }
   
   function ShowRank(){
         var rank;
         alert("Game Over! You've used up all your 5 guess chances. Result:");
         if(wins > 4)
            rank = "You were ALWAYS right! Your Rank: God.";
         else if(wins > 3)
            rank = "You were almost always right! Your Rank: Very very nice.";
         else if(wins > 2)
            rank = "You were almost always right! Your Rank: Very good.";
         else if(wins > 1)
            rank = "You were almost always right! Your Rank: Nice.";
         else if(wins > 0)
            rank = "You were mostly wron! Your Rank: Good.";
         else
            rank = "You were always wrong. Your Rank: Loser.";
         alert(rank);
         document.getElementById('resultDiv').innerHTML = "<span class=base>Game Over! You've used up all your 5 guess chances. Result:<br>"+rank+"<br><b>Click Reset to restart the game!</span></b><br><br>";
         document.getElementById('resultDiv').style.display = "";
         return;
   }
   
   function updateStats(){
      document.getElementById('nOfGuesses').value = guessed;
      document.getElementById('nOfWins').value = wins;
      document.getElementById('nOfFails').value = fails;
   }
   
   function keyPressHandler(e){
      if(e.which == 13)
         generateNum();
   }
</script>
</head>
<body>

<p><center>Instructions<br><!--instructions-->
<span class=base>1. Guess a number between 1-100 and enter it in the textbox<br>
2. Click play<br>
The computer just generated a random number for you and now, will check if you guessed right<br>
You will be getting tips on either your guess was higher/lower and if its near<br>
3. Keep guessing until you win!<br>
Your wins will also be told to you!</span><br><br><br><br><br><br><br><br>
<div id="container">
   <img src="guess.bmp" align="center" border="2">
   <br><br><br><br><br><br><br>
   
   <b><span class=base>Enter a guess between 1-100:</span></b> <input type="text" onkeypress="keyPressHandler(event)" name="txtGues" id="txtGues" size="3" maxlength="3" value="0">
   <input class="butts" name="playbtn" id="playbtn" type="button" value="Play!" onClick="generateNum()"/><br><br><br><br><br>
   <div id="resultDiv" style="display: none">Game Over! You've used up all your 5 guess chances. Result:<br>
   </div>
   <b><span class=base>Number of Guesses:</span></b> <input type="text" name="nOfGuesses" id="nOfGuesses" size="5" maxlength="20"  value="0" readonly="readonly"><br>
   <b><span class=base>Number of times you guessed right:</span></b> <input type="text" name="nOfWins" id="nOfWins" size="5" maxlength="20"  value="0" readonly="readonly"><br>
   <b><span class=base>Number of times you guessed wrong:</span></b> <input type="text" name="nOfFails" id="nOfFails" size="5" maxlength="20"  value="0" readonly="readonly">
   <input class="butts" type="button" value="Reset" onClick="resetGame();"/><br><br><br><br><br>
</div>

</body>
</html>

Is there a way that there was only one random number for five turns and then after that, um the thing chooses another random number?
Also the reset thing wont work for the number u write for the in the text box...the text wont clear up

_________________
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Sun Nov 23, 2008 6:19 pm    Post subject: Reply with quote

Get a random number and store it in a variable, then in resetGame generate a new one? The logic is very simple.

Um, the resetGame function never clears the text in the text box? Perhaps you should add code to do that.

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
et($this->_tpldata['postrow'][$_postrow_i]['attach'][$_attach_i]['attachrow'][$_attachrow_i]['FILESIZE'])) ? $this->_tpldata['postrow'][$_postrow_i]['attach'][$_attach_i]['attachrow'][$_attachrow_i]['FILESIZE'] : '') , ' ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['attach'][$_attach_i]['attachrow'][$_attachrow_i]['SIZE_VAR'])) ? $this->_tpldata['postrow'][$_postrow_i]['attach'][$_attach_i]['attachrow'][$_attachrow_i]['SIZE_VAR'] : '') , '
 ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['attach'][$_attach_i]['attachrow'][$_attachrow_i]['L_DOWNLOADED_VIEWED'])) ? $this->_tpldata['postrow'][$_postrow_i]['attach'][$_attach_i]['attachrow'][$_attachrow_i]['L_DOWNLOADED_VIEWED'] : '') , ': ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['attach'][$_attach_i]['attachrow'][$_attachrow_i]['L_DOWNLOAD_COUNT'])) ? $this->_tpldata['postrow'][$_postrow_i]['attach'][$_attach_i]['attachrow'][$_attachrow_i]['L_DOWNLOAD_COUNT'] : '') , '
'; echo '

'; } // END attachrow echo ' '; } // END attach echo '' , ((isset($this->_tpldata['postrow'][$_postrow_i]['SIGNATURE'])) ? $this->_tpldata['postrow'][$_postrow_i]['SIGNATURE'] : '') , '' , ((isset($this->_tpldata['postrow'][$_postrow_i]['EDITED_MESSAGE'])) ? $this->_tpldata['postrow'][$_postrow_i]['EDITED_MESSAGE'] : '') , ' '; echo ' '; $_warning_count = (isset($this->_tpldata['postrow'][$_postrow_i]['warning'])) ? sizeof($this->_tpldata['postrow'][$_postrow_i]['warning']) : 0;for ($_warning_i = 0; $_warning_i < $_warning_count; $_warning_i++){ echo ' '; echo '
' , ((isset($this->_tpldata['postrow'][$_postrow_i]['warning'][$_warning_i]['ICON'])) ? $this->_tpldata['postrow'][$_postrow_i]['warning'][$_warning_i]['ICON'] : '') , '' , ((isset($this->_tpldata['postrow'][$_postrow_i]['warning'][$_warning_i]['DETAILS'])) ? $this->_tpldata['postrow'][$_postrow_i]['warning'][$_warning_i]['DETAILS'] : '') , '
' , ((isset($this->_tpldata['.'][0]['L_REASON'])) ? $this->_tpldata['.'][0]['L_REASON'] : '') , ': ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['warning'][$_warning_i]['MESSAGE'])) ? $this->_tpldata['postrow'][$_postrow_i]['warning'][$_warning_i]['MESSAGE'] : '') , '
'; echo ' '; } // END warning echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' ' , ((isset($this->_tpldata['.'][0]['L_BACK_TO_TOP'])) ? $this->_tpldata['.'][0]['L_BACK_TO_TOP'] : '') , ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo '
' , ((isset($this->_tpldata['postrow'][$_postrow_i]['PROFILE_IMG'])) ? $this->_tpldata['postrow'][$_postrow_i]['PROFILE_IMG'] : '') , ' ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['PM_IMG'])) ? $this->_tpldata['postrow'][$_postrow_i]['PM_IMG'] : '') , ' ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['EMAIL_IMG'])) ? $this->_tpldata['postrow'][$_postrow_i]['EMAIL_IMG'] : '') , ' ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['WWW_IMG'])) ? $this->_tpldata['postrow'][$_postrow_i]['WWW_IMG'] : '') , ' ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['AIM_IMG'])) ? $this->_tpldata['postrow'][$_postrow_i]['AIM_IMG'] : '') , ' ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['YIM_IMG'])) ? $this->_tpldata['postrow'][$_postrow_i]['YIM_IMG'] : '') , ' ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['MSN_IMG'])) ? $this->_tpldata['postrow'][$_postrow_i]['MSN_IMG'] : '') , '' , ((isset($this->_tpldata['postrow'][$_postrow_i]['YELLOW_IMG'])) ? $this->_tpldata['postrow'][$_postrow_i]['YELLOW_IMG'] : '') , ' ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['RED_IMG'])) ? $this->_tpldata['postrow'][$_postrow_i]['RED_IMG'] : '') , '
'; echo ' '; echo ' '; echo ' ' , ((isset($this->_tpldata['postrow'][$_postrow_i]['ADCODE'])) ? $this->_tpldata['postrow'][$_postrow_i]['ADCODE'] : '') , ' '; echo ' '; } // END postrow echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo '
' , ((isset($this->_tpldata['.'][0]['L_DISPLAY_POSTS'])) ? $this->_tpldata['.'][0]['L_DISPLAY_POSTS'] : '') , ': ' , ((isset($this->_tpldata['.'][0]['S_SELECT_POST_DAYS'])) ? $this->_tpldata['.'][0]['S_SELECT_POST_DAYS'] : '') , ' ' , ((isset($this->_tpldata['.'][0]['S_SELECT_POST_ORDER'])) ? $this->_tpldata['.'][0]['S_SELECT_POST_ORDER'] : '') , ' 
'; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo '
' , ((isset($this->_tpldata['.'][0]['L_POST_NEW_TOPIC'])) ? $this->_tpldata['.'][0]['L_POST_NEW_TOPIC'] : '') , '   ' , ((isset($this->_tpldata['.'][0]['L_POST_REPLY_TOPIC'])) ? $this->_tpldata['.'][0]['L_POST_REPLY_TOPIC'] : '') , ' '; $_switch_quick_reply_count = (isset($this->_tpldata['switch_quick_reply'])) ? sizeof($this->_tpldata['switch_quick_reply']) : 0;for ($_switch_quick_reply_i = 0; $_switch_quick_reply_i < $_switch_quick_reply_count; $_switch_quick_reply_i++){ echo '   ' , ((isset($this->_tpldata['.'][0]['L_POST_SQR_TOPIC'])) ? $this->_tpldata['.'][0]['L_POST_SQR_TOPIC'] : '') , ' '; } // END switch_quick_reply echo '   ' , ((isset($this->_tpldata['.'][0]['L_INDEX'])) ? $this->_tpldata['.'][0]['L_INDEX'] : '') , ' '; $_switch_parent_link_count = (isset($this->_tpldata['switch_parent_link'])) ? sizeof($this->_tpldata['switch_parent_link']) : 0;for ($_switch_parent_link_i = 0; $_switch_parent_link_i < $_switch_parent_link_count; $_switch_parent_link_i++){ echo ' -> ' , ((isset($this->_tpldata['.'][0]['PARENT_NAME'])) ? $this->_tpldata['.'][0]['PARENT_NAME'] : '') , ' '; } // END switch_parent_link echo ' -> ' , ((isset($this->_tpldata['.'][0]['FORUM_NAME'])) ? $this->_tpldata['.'][0]['FORUM_NAME'] : '') , '' , ((isset($this->_tpldata['.'][0]['S_TIMEZONE'])) ? $this->_tpldata['.'][0]['S_TIMEZONE'] : '') , '
' , ((isset($this->_tpldata['.'][0]['PAGINATION'])) ? $this->_tpldata['.'][0]['PAGINATION'] : '') , ' '; echo '
' , ((isset($this->_tpldata['.'][0]['PAGE_NUMBER'])) ? $this->_tpldata['.'][0]['PAGE_NUMBER'] : '') , '
'; echo ' '; $_switch_quick_reply_count = (isset($this->_tpldata['switch_quick_reply'])) ? sizeof($this->_tpldata['switch_quick_reply']) : 0;for ($_switch_quick_reply_i = 0; $_switch_quick_reply_i < $_switch_quick_reply_count; $_switch_quick_reply_i++){ echo ' ' , ((isset($this->_tpldata['.'][0]['QRBODY'])) ? $this->_tpldata['.'][0]['QRBODY'] : '') , ' '; } // END switch_quick_reply echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo '
' , ((isset($this->_tpldata['.'][0]['S_WATCH_TOPIC'])) ? $this->_tpldata['.'][0]['S_WATCH_TOPIC'] : '') , '
'; echo '  
'; echo ' ' , ((isset($this->_tpldata['.'][0]['S_TOPIC_ADMIN'])) ? $this->_tpldata['.'][0]['S_TOPIC_ADMIN'] : '') , '
' , ((isset($this->_tpldata['.'][0]['JUMPBOX'])) ? $this->_tpldata['.'][0]['JUMPBOX'] : '') , '' , ((isset($this->_tpldata['.'][0]['S_AUTH_LIST'])) ? $this->_tpldata['.'][0]['S_AUTH_LIST'] : '') , '
'; echo ' '; ?>


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites