1 What this is about
2 What questions i have
3 What is bugging
1. What this is about
As this is still the same programm the intro stays the same
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
Player twos input should be counted. I need that information to stop the game at a certain time. i rewrote my question because the first one was properly answered.
How can i do that? How does the loop have to look like? Is it possible to delete player ones formular and echo after it was shown on screen?
Normally i know how a loop works but i did not work with a loop for submissions before.
3. Bugs/Debugging Got my indexes right this time.
the code
<?php
session_start();
$_SESSION['geraten'] = 1;
if($_SESSION['geraten'] == 1) {
echo "<br>";
echo "Spieler 1";
echo "<form method='post'>";
echo "chose your five numbers/Wähle deine 5 Zahlen<br>";
echo "<input type='text' name='one' size='1' maxlength='1'>";
echo "<input type='text' name='two' size='1' maxlength='1'>";
echo "<input type='text' name='three' size='1' maxlength='1'>";
echo "<input type='text' name='four' size='1' maxlength='1'>";
echo "<input type='text' name='five' size='1' maxlength='1'>";
echo "<input type='submit' name='gesendet' value='OK'>";
echo "</form>";
echo "<br>";
echo "{$_SESSION['geraten']}";
//player one is starting here
//<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> -->
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";
}
}
}
// how can i count the second submits?
else {
//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['geraten']++;
$_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";
echo "<br>";
echo "{$_SESSION['geraten']}";
}
}
}
?>