0

Can anyone help me or get me going in the right direction? Here is the problem.
I need to create a script that presents a word guessing game. Allow users to guess the word letter-by-letter by entering a character in a form. Start by assigning a secret word to avariable. After each gues, print the word using astricks for each remaing letter, but fill in the letters that the user guessed correxctly. You need to store the user's guess in a hidden form field. For example, if I want them to guess "suspicious" and they already guessed "S" "I" then store s*s*i*i**s in the hidden form field. I need to have the one document that process and displays the form.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by newbie37
0

The steps you need to take are: create a variable that holds the word, make a textbox for the user to put in a guess. You can use echo to print out the remaining letters and the function substr_replace to replace the letters with asterisks. For the hidden field, set the input type to hidden when you create the field. Try to get the form set up first and then we can help you with the processing if you need it.

Edited by zortec: n/a

0

Thanks I will work on it.

I was thinking to split the string into an array. Do you use the sub_replace after this?
<html>
<head>
<title>Guessing Game</title>

</head>
<body>
<h1>Guessing Game</h1><hr />
<?php

$MysteryWord = "suspicious";
$MysteryWordArray = str_split("suspicious");


echo "<p>Mystery word: **********</p>";
echo "<p>Enter a letter and click the Submit Letter button.</p>";

?>
<form action="GuessingGame.php" method="get" enctype="application/x-www-form-urlencoded">
<p><input type="text" name="letter" />
<input type="hidden" name="progress"
<?php if (isset($Progress)) echo "value='$Progress'"; else echo "value='**********'"; ?> /></p>
<p><input type="submit" value="Submit Letter" />
</form>
</body>
</html>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.