AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Guess the number - tiny little game

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
XYZ



Joined: 20 Mar 2010
Posts: 224

PostPosted: Sun Mar 21, 2010 12:56 pm    Post subject: Guess the number - tiny little game Reply with quote

having almost zero programming experience, and getting a lot of inspiration from the community

i made my first game in scripting, and not graphically like in GAMEMAKER
i read about this one on a piece of paper lying on the road...

i am amazed to see how RANDOM, var, x-y
command works

code=
Code:

Random, rand, 1, 50
MsgBox,4, Guess the Number Game, I have a Number between 1 and 50. Would you like to guess the number?

IfMsgBox Yes
   InputBox, num, Guess, Please type your first guess.
   if (num="") {
   Return
}
Else {
   Gosub, guess
   }

guess:
if (num<rand) {
   MsgBox,,Result,The number was too low.
   InputBox, num, Guess, Please type your next guess.
}
else if(num>rand){
   MsgBox,,Result,The number was too high.
   InputBox, num, Guess, Please type your next guess.   
}
else if (num=rand){
   MsgBox,,Result, Correct! You guessed the number.
   return
}

Gosub, guess
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Tue Mar 23, 2010 4:56 pm    Post subject: Reply with quote

Neat. Here's a GUI version for comparison. Smile
Code:
Gui, Add, Text,,Guess a number from 1 through 50.
Gui, Add, Text,   wp vMsg
Gui, Add, Edit,   wp vNum Number
Gui, Add, Button, wp Default, OK

Gui, Show,,Number Guess
return
GuiClose:
 ExitApp

ButtonOK:
 If !rand
  Random, rand, 1, 50
 Gui, Submit, NoHide
 If (Num = rand) {
  GuiControl,,Msg, (%Num%) Just right!
  GuiControl,,Num, Guess again to start a new game.
  rand = 0
  return
 }
 If (Num < rand)
  GuiControl,,Msg, (%Num%) Too low.
 Else If (Num > rand)
  GuiControl,,Msg, (%Num%) Too high.
 GuiControl,,Num
return
Back to top
View user's profile Send private message Visit poster's website
arsan



Joined: 02 Jan 2010
Posts: 105

PostPosted: Wed Mar 24, 2010 4:53 am    Post subject: Reply with quote

Wow! This brought back nostalgic feelings! In our school days we did this using GW-BASIC. Oh! the memories of golden days. Very Happy
Back to top
View user's profile Send private message
XYZ



Joined: 20 Mar 2010
Posts: 224

PostPosted: Tue Apr 13, 2010 3:42 pm    Post subject: Reply with quote

arsan wrote:
Wow! This brought back nostalgic feelings! In our school days we did this using GW-BASIC. Oh! the memories of golden days. Very Happy
gwbasic is so not ahk
Back to top
View user's profile Send private message
arsan



Joined: 02 Jan 2010
Posts: 105

PostPosted: Tue Apr 13, 2010 5:03 pm    Post subject: Reply with quote

UMAR wrote:
arsan wrote:
Wow! This brought back nostalgic feelings! In our school days we did this using GW-BASIC. Oh! the memories of golden days. Very Happy
gwbasic is so not ahk

In fact, as far as capabilities and usefulness is concerned, GW-BASIC cannot be compared to any programming language of modern times. It is so primitive and outdated. However, in my early school days, when we were introduced to computers, we did LOGO (age 8 ) and GW-BASIC (age 9), which provided good not-so-complex introduction to logical thinking to young children then, before moving to real useful languages like C etc.. And this game was what we were taught as one of the early examples of GW-BASIC programming! I don't think anyone would even think of using GW-BASIC now. It would be a total waste of time.
Back to top
View user's profile Send private message
XYZ



Joined: 20 Mar 2010
Posts: 224

PostPosted: Wed Apr 14, 2010 1:40 pm    Post subject: Reply with quote

yeah i also did that LOGO turtle thing
but never really mastered it

ahk is awsum!
Back to top
View user's profile Send private message
ratchetclan4



Joined: 14 Apr 2010
Posts: 18

PostPosted: Wed Apr 14, 2010 7:38 pm    Post subject: Reply with quote

just two tiny little improvments here for the non gui version
ive added so that it tells you what the last number you picked was
and at the end it asks you if you want a rematch! i just felt it was missing these Very Happy and reopening the file was awkward, you could also make it so it keeps track of how many guesses it took you too win in a txt file
so you can see how good you are



Code:
start:
Random, rand, 1, 50
MsgBox,4, Guess the Number Game, I have a Number between 1 and 50. Would you like to guess the number?

IfMsgBox Yes
   InputBox, num, Guess, Please type your first guess.
   if (num="") {
   Return
}
Else {
   Gosub, guess
   }

guess:
if (num<rand) {
   MsgBox,,Result,The number was too low.
   InputBox, num, Guess, Please type your next guess go higher this time your last guess was %num%
}
else if(num>rand){
   MsgBox,,Result,The number was too high.
   InputBox, num, Guess, Please type your next guess go lower this time your last guess was %num%
}
else if (num=rand){
   MsgBox,,Result, Correct! You guessed the number. WELL DONE!!!
   return
}

Gosub, guess

Msgbox, 4,, Would You Like To Play Again?
ifmsgbox yes
goto, start
else
goto, end


end:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group