project: number game

 

Objective: students will be able to use the "if" statement, random numbers, and control the flow of an application. Students will also be able to use properties to keep a value.

 

The number game is a little boring - but a good way to start learning about the flow of an application. When you start the number game the game chooses a number secretly and asks you to guess the number. If you guess it, you win! If you are low, it tells you the number is higher, and if you are high, it tells you the number is lower.

Properties - are like variables, but store a value for as long as the window is open. Make a new property (click the "Add Property" button in the code editor). Make it "thenumber as integer".

Places you will put code:

Open event of the window

Pushbutton on the window for making a guess.

Pushbutton for a new game?

If statements - When the computer needs to make a decision you use an if statement.

If theguess = thenumber then
	//you win!!
elseif theguess < thenumber then
	//your guess is too small
else
	//your guess is too large
end


Your assignment is to make the number game work. When you win it should tell you how many guesses it took. Use another property to count the guesses! Once it basically works, you should work to make it better! Some things you could do are:

Make the range of numbers variable - make a property that holds the maximum number, then choose the number.

Make it like hangman using a canvas and drawing commands.