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.

Recommended Answers

All 3 Replies

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.

Thanks I will work on it.

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>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.