FlyFar

A Simple HTA Script Of Guess Number Game

Oct 25th, 2021 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.67 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Guess Number</title>
  4. <HTA:APPLICATION
  5.  APPLICATIONNAME="GuessNumber"
  6.  ID="GuessNumber"
  7.  VERSION="1.0"
  8.  MAXIMIZEBUTTON="no"
  9.  SCROLL="no"/>
  10. </head>
  11.  
  12. <style>
  13.  
  14. body  {color: #808080;}
  15.  
  16. .txt  {color: #808080;
  17.     background-color: #000000;
  18.     text-align: center;}
  19.  
  20. .sml  {font-size: 9pt;}
  21.  
  22. hr   {color: #808080;}
  23.  
  24. </style>
  25.  
  26. <script language="VBScript">
  27.  
  28. Sub Window_OnLoad
  29.  Randomize
  30.    Dim width,height
  31.    width=350
  32.    height=300
  33.    self.ResizeTo width,height
  34.    BTNR.style.background = "#000000"
  35.    BTNR.style.color = "#808080"
  36.    BTNG.style.background = "#000000"
  37.    BTNG.style.color = "#808080"
  38.    cunt.value = 20
  39.    chk.value = 0
  40.    count.value = 20
  41.    cnum.value = Int((Rnd*9999)+0)
  42.    box.focus
  43. End Sub
  44.  
  45. Sub BTNG_OnMouseOver
  46. BTNG.style.background = "#808080"
  47. BTNG.style.color = "#000000"
  48. End Sub
  49.  
  50. Sub BTNR_OnMouseOver
  51. BTNR.style.background = "#808080"
  52. BTNR.style.color = "#000000"
  53. End Sub
  54.  
  55. Sub BTNG_OnMouseOut
  56. BTNG.style.background = "#000000"
  57. BTNG.style.color = "#808080"
  58. End Sub
  59.  
  60. Sub BTNR_OnMouseOut
  61. BTNR.style.background = "#000000"
  62. BTNR.style.color = "#808080"
  63. End Sub
  64.  
  65. Function Reset
  66. Randomize
  67. cnum.value = Int((Rnd*9999)+0)
  68. cunt.value = 20
  69. count.value = 20
  70. info.value = ""
  71. box.value = ""
  72. chk.value = 0
  73. box.focus
  74. End Function
  75.  
  76. Function Validate
  77. chck = chk.value
  78. num = box.value
  79. cont = cunt.value
  80. If (chck = 1) Then
  81. MsgBox("Reset the game to play again!")
  82. Else If (cont <= 0) Then
  83. MsgBox("You ran out of turns! Reset the game to play again!")
  84. Else If (box.value = "") Then
  85. MsgBox("Enter number!")
  86. Else If Not (IsNumeric(box.value)) Then
  87. MsgBox("Not a valid number!")
  88. Else If (num < 0) Then
  89. MsgBox("Not a valid number!")
  90. Else
  91. StartGame()
  92. End If
  93. End If
  94. End If
  95. End If
  96. End If
  97. End Function
  98.  
  99. Function StartGame
  100. mnum = Int(box.value)
  101. onum = Int(cnum.value)
  102. cunt.value = Int(cunt.value)-1
  103. If (cunt.value <= 0) Then
  104. box.value = ""
  105. info.value = "Reset the game!"
  106. count.value = cunt.value
  107. MsgBox("You ran out of chances!")
  108. Else If (mnum < onum) Then
  109. info.value = "My number is greater than "&mnum&"!"
  110. count.value = cunt.value
  111. Else If (mnum > onum) Then
  112. info.value = "My number is less than "&mnum&"!"
  113. count.value = cunt.value
  114. Else If (mnum = onum) Then
  115. xnum = 20-Int(cunt.value)
  116. info.value = "You Guessed my numer in "&xnum&" turns!"
  117. count.value = cunt.value
  118. chk.value = 1
  119. Else
  120. info.value = "ERROR!"
  121. cunt.value = cunt.value+1
  122. count.value = cunt.value
  123. End If
  124. End If
  125. End If
  126. End If
  127. box.value = ""
  128. box.focus
  129. End Function
  130.  
  131. Function KPress()
  132. If (window.event.keycode = 13) Then
  133. Validate()
  134. Else
  135. End If
  136. box.focus
  137. End Function
  138.  
  139. </script>
  140.  
  141. <body bgcolor="black" onkeypress="KPress()">
  142. <input type="hidden" id="chk">
  143. <input type="hidden" id="cnum">
  144. <input type="hidden" id="cunt">
  145. <table align="center" border="3">
  146. <caption><hr><b>GUESS NUMBER</b><hr></caption>
  147. <tr>
  148. <td>Do you think you can guess a number between 0 and 9999 in less than 20 turns? Play this little game and find out if you can do it!</td>
  149. </tr>
  150. <tr>
  151. <td align="center"><input type="text" id="box" size="5" maxlength="4" class="txt" onkeypress="If (window.event.keycode < 48 Or window.event.keycode > 57) Then window.event.returnvalue = False"> <input type="button" value="Guess" onClick="Validate" id="BTNG"></td>
  152. </tr>
  153. <tr>
  154. <td align="center"># <input type="text" id="count" size="4" class="txt"  maxlength="0" onmousemove="count.value = cunt.value"> <input type="text" id="info" size="32" class="txt" maxlength="0"></td>
  155. </tr>
  156. <tr>
  157. <td align="right"><a class="sml">| Guess Number - By FlyFar  |  Copyright © 2019 |</a> <input type="button" value="Reset" id="BTNR" onClick="Reset"></td>
  158. </tr>
  159. </table>
  160. </body>
  161. </html>
Add Comment
Please, Sign In to add comment