overview:
1 What this is about
2 What questions i have
3 What is bugging
1. What this is about
this is about programming a little number game. i think it is also known as mastermind. the game has the following rules.
there are two players
first the starting player types 5 numbers
then the second player types 5 numbers to guess the numbers from the first player
the programm has to echo how many numbers of the second player are at the right place and also how many numbers are correctly guessed.
the programm has to run a fiew times, because player two has several tries
i want to use one formular for both players if possible aka one submit button
i don't want to know how this programm is coded as a whole but i have specific questions for some steps.
2. What questions i have
As you see i did player two as well. But i still have the problem that i cannot count how often player two typed the numbers. I have to count it because i want the game to quit if a certain number is reached.
Also i want to clear the screen for player two without clearing his formular, too. but the formular for player one should vanish after player ones submit.
3. Bugs/Debugging
i tried to use a loop but i couldn't figure out how i can use it without creating several formulars at once. it just should count + 1 for every player two submit of numbers.
<html>
<head>
<title>guess a number</title>
</head>
<body>
<h4> guess a number</h4>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>"method="post">
<!-- player one is starting here -->
<p>Spieler 1</p>
<p>chose your five numbers/Wähle deine 5 Zahlen</p><br />
<input type="password" name="one" size="1" maxlength="1">
<input type="password" name="two" size="1" maxlength="1">
<input type="password" name="three" size="1" maxlength="1">
<input type="password" name="four" size="1" maxlength="1">
<input type="password" name="five" size="1" maxlength="1">
<input type="submit" name="gesendet" value="ok"></button> <br />
</form>
<?php
session_start();
if(isset($_POST['gesendet'])){
$one = $_POST['one'];
$two = $_POST['two'];
$three = $_POST['three'];
$four = $_POST['four'];
$five = $_POST['five'];
// array to safe the input of player one with sessions
$_SESSION['anumberone'][0] = $one;
$_SESSION['anumberone'][1] = $two;
$_SESSION['anumberone'][2] = $three;
$_SESSION['anumberone'][3] = $four;
$_SESSION['anumberone'][4] = $five;
foreach ($_SESSION['anumberone'] as $ausgabe) {
echo "$ausgabe";
}
}
$i = 0; // how can i count the second submits?
while ( $i < 5 ) {
$i = $i + 1;
echo "$i";
//start with player two here!
echo "<br>";
echo "Spieler 2";
echo "<form method='post'>";
echo "Ihre Ziffern:<br>";
echo "<input type='text' name='sechs' size='1' maxlength='1'>";
echo "<input type='text' name='sieben' size='1' maxlength='1'>";
echo "<input type='text' name='acht' size='1' maxlength='1'>";
echo "<input type='text' name='neun' size='1' maxlength='1'>";
echo "<input type='text' name='zehn' size='1' maxlength='1'>";
echo "<input type='submit' name='submitzwei' value='OK'>";
echo "</form>";
if(!empty($_POST['submitzwei'])){
$sechs = $_POST['sechs'];
$sieben = $_POST['sieben'];
$acht = $_POST['acht'];
$neun = $_POST['neun'];
$zehn = $_POST['zehn'];
$_SESSION['anumber2'][0] = $sechs;
$_SESSION['anumber2'][1] = $sieben;
$_SESSION['anumber2'][2] = $acht;
$_SESSION['anumber2'][3] = $neun;
$_SESSION['anumber2'][4] = $zehn;
foreach ($_SESSION['anumber2'] as $ausgabe) {
echo "$ausgabe";
}
}
}
?>
</body>
</html>