0
可能性の重複:彼らはそれを得るいけない場合、ユーザーは、 "1" の映画で3回を推測することができるようにしようと
Loop Iteration in Php Game許可3つの試み - PHP
、それは彼らに正しい答えを伝えます(変数は$ rand_keysです)。また、推測を差し引いて推測量を表示します($ guesses変数でエラーが発生する可能性があります)。
ここで何が問題になりますか?私に可能な解決策を教えてください。
<style type="text/css">
input {border:1px solid #ADD8E6; font-size:1.2em;}
input.spec {background-color:#ddd;}
</style>
<?php
echo "<fieldset><h1><legend>Testing your Academy Award Trivia</h1>";
$ages['Casablanca'] = "1943";
$ages['Around The World in 80 Days'] = "1956";
$ages['Patton'] = "1970";
$ages['Annie Hall'] = "1977";
$ages['Chariots of Fire'] = "1981";
$ages['Dances With Wolves'] = "1990";
$ages['Crash'] = "2005";
$ages['The Departed'] = "2006";
$rand_keys = array_rand($ages, 1);
$guesses = 3;
?>
<form method='post' name="inputyear" onsubmit="return validate(this);">
Give the year below won academy award<br><br>
<Strong>Movie:</strong> <input type='text' name='movie' class="spec" value='<?= $rand_keys ?>' readonly='readonly' /><br><br>
<Strong>Year it Won the Oscar:</Strong> <input type='text' name='year' size="30" /><br/><br>
<strong>You have: </strong> <?php $guesses; ?> guesses left<br><br>
<input type='submit' name='submit' value="Get Result" onClick="makeGuess()" />
</form>
<?php
$movie = isset($_POST['movie']) ? $_POST['movie'] : false;
$guessedYear = isset($_POST['year']) ? (int) $_POST['year'] : false;
if ($movie && $guessedYear) {
$realyear = $ages[$movie];
}
@$_SESSION[$movie]['$guesses']++;
if ($realyear && $_SESSION[$movie]['$guesses'] < 3) {
if ($guessedYear == $realyear) {
echo "Correct! " . "during year " . $realyear;
}
if ($guessedYear < $realyear) {
echo "Wrong, year too low";
$guesses--;
}
if ($guessedYear > $realyear) {
echo "Wrong, year too high";
$guesses--;
}
} elseif ($_SESSION[$movie]['$guesses'] >= 3) {
echo "Sorry, too many tries. the answer was " . $realyear;
} else {
echo "Sorry, You managed not to pick a year. Please try again";
$_SESSION[$movie]['guesscount']--;
}
?>
あなたはすでにこの質問をしています。http://stackoverflow.com/questions/4892506/loop-iteration-in-php-game/4892529 – DeveloperChris
これはうまくいかない理由はあなたの他の質問の答えです。それらを無視して停止! –
さて、誰も働いていませんでした。 – Jshee