Question:
Guess the Number game PHP?
Wooly
2012-03-07 03:55:12 UTC
I have to make a "Guess te Number" game with basic PHP without the use off any programs. The only things that is allowed is Notepad++

You have to make a game where the computer chooses a number from 1 till 100 and you will have to guess that. Every time you submit a number it should say whether to go higher or lower. It should also mention the number of guesses at the end.

http://roland.infsjl.nl/spel.php

This is the version my teacher made and is also what it should look like.

He has hid the source code somehow and this is where my questions come in.

1) Is it possible to find the source code of this site?
2) Does anyone know a simple version of this game and will you share that one with me?

Thanks in advance,
W
Three answers:
Kojote
2012-03-07 04:48:40 UTC
Since it's your homework, you should at least try to work out the logic yourself. Copy/pasting it from an online answer won't help you on your exams.



PHP is a server-side scripting language that generates a HTML page for your browser to read, so it's not possible to read the PHP source code.



Look at the structure of the page:

It appears to first have a header with the game name, then a form with a label, a text input and a submit button, and under the form a hyperlink to itself.



When you click the submit button with your particular value, it redirects to itself and gives a message wether your value is too low, too high or is correct (and then the amount of tries it took).



When the page loads for the first time, a session variable will be made and given a random value between 0 and 100. PHP has a simple function for this.



When you click the submit button, the page reloads, so that means the form action redirects to the same page and the game code is on that game.php page. Thus, a check must be done if the submit button was actually pressed and if a value was given with the form (if you've had PHP in class you should already know about $_POST and $_SESSION global arrays) before it can perform the game. Since there is a counter variable that increases each time you submit a number, there should be another session variable that increases everytime the game code is performed.



After this, the game logic is incredibly simple: if the user number is lower as the random number, tell the user that, else if the number is higher as the random number tell the user that, else tell the user he won and also give the number of times he needed.
anonymous
2012-03-07 04:36:14 UTC
"; //gives the user instructions $x = rand (1,100) ; //creates x }

What this code does, is check to see if the game has already started. If it has, all of this is ignored. If it has not, then it randomly chooses a number to be the winning number, $x. It also prints some brief instructions for the user.
?
2016-10-21 05:11:06 UTC
depending on the context of the question, the answer is both a "do-on an identical time" loop or a "placed up-examined" loop. A placed up-examined loop is a loop that makes an technologies and *then* evaluates the attempt expression. A do-on an identical time loop is many of the important properly-properly-known form of placed up-examined loop.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...