Friday, July 31, 2009

"Guess the number" in C#?

Hi. I created a website in c# (using visual studio), that contains a simple "guess the number" game. I have a textbox, a button and a label. It works so far only if I specify the number that needs to be guessed.


So the problem is - I want to generate a random number from 1 to 100 let's say, but as the user clicks the button, the page refreshes, and a new number is generated.


I want to keep the randomly chosen number until the user guesses it or quits. How can I fix this?

"Guess the number" in C#?
Use the session-hash to store a number.





Example





session["secretNumber"] = GenerateSecretNumber();





On you page, you should read the number from the hash table.





Where/when to create?





1) When a new session is started; or


2) When no session-key is found; and/again


3) When the visitor guessed it


No comments:

Post a Comment