AutoHotkey Community

It is currently May 27th, 2012, 4:57 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: March 21st, 2010, 1:56 pm 
Offline

Joined: March 20th, 2010, 9:49 am
Posts: 224
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2010, 5:56 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Neat. Here's a GUI version for comparison. :)
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2010, 5:53 am 
Offline

Joined: January 2nd, 2010, 6:13 pm
Posts: 105
Wow! This brought back nostalgic feelings! In our school days we did this using GW-BASIC. Oh! the memories of golden days. :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2010, 4:42 pm 
Offline

Joined: March 20th, 2010, 9:49 am
Posts: 224
arsan wrote:
Wow! This brought back nostalgic feelings! In our school days we did this using GW-BASIC. Oh! the memories of golden days. :D
gwbasic is so not ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2010, 6:03 pm 
Offline

Joined: January 2nd, 2010, 6:13 pm
Posts: 105
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. :D
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2010, 2:40 pm 
Offline

Joined: March 20th, 2010, 9:49 am
Posts: 224
yeah i also did that LOGO turtle thing
but never really mastered it

ahk is awsum!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2010, 8:38 pm 
Offline

Joined: April 14th, 2010, 11:18 am
Posts: 18
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 :D 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:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group