|
Let make a simple guessing game and then add to it. Before we even start to program, even this simple game, we need to have a idea of what we want to do.
1 number guessing game 2 a number between 1 and 100 3 sounds simple lets start
`lets begin by clearing the screen, Window opens a new window each time you start a program and `this really isn't needed, this is habit carried over from the days before Window - Dos
cls
`cls clears the screen
`lets randomize a number. `we will store this value in a variable named 'secret_number'
Secret_number = Rnd(100)+1
`the rnd() command pick a random number it starts with 0, so rnd(100) would generate a number 0-99 `we want 1 to 100 so we just add 1 to it.
`that's all the setup our little game needs 'now lets write to the screen
Print "I know a secret number can you guess it?"
`the print command is the standard command to write text to the screen `it will print whatever is between the "quotation marks"
Print "Guess between 1 and 100 :";
`notice this print command ends with a ; after the " `a print command ends with a carriage return, this means that after it writes to the screen it jump down `to the next line 'we are going to enter our answer right after this line and the ; tell it to ignore the carriage return `getting input from the user
Input my_guess
`the input command get whatever the user types and presses the return key `the input is unique because the user has to press return the enter it, there are other commands you `don't have to do that `this will take the users input and store it in the variable named 'my_guess' `now to compare the two numbers
`if condition then event `if then else, use this if you only have a single command event `or `if else endif, this lets you nest together as many command as you need to"
If my_guess < secret_number then print "Nope, to low" else If my_guess > secret_number then print "Nope, to high" else If my_guess = secret_number then print "Wow, you guessed my secret number"
`the else function tells the program if the first one doesn't work try this one. `without the else command the program would check each condition even if the first was right. `the else command stop the program from doing unnecessary stuff
Wait key
`this pause the program until any key is pressed
End
`this ends the program
|
|