Commit cab3bfe5 authored by 君塚 悠's avatar 君塚 悠

プログラム修正(game.php:bashで動くように)

parent 72860410
session_start(); <!-- session_start(); -->
<html> <!-- <html> -->
<head> <!-- <head> -->
<title>数当てゲーム</title> <!-- <title>数当てゲーム</title> -->
</head> <!-- </head> -->
</html> <!-- </html> -->
<body> <!-- <body> -->
<h1 style="background: #cccccc#>数当てゲーム</h1> <!-- <h1 style="background: #cccccc#>数当てゲーム</h1> -->
<form method="POST" action="game.php"> <!-- <form method="POST" action="game.php"> -->
1~100までの中からいずれかの数を入力してください: <!-- 1~100までの中からいずれかの数を入力してください: -->
<input type="text" name="answer" size="5" <!-- <input type="text" name="answer" size="5" -->
maxlength="3" /> <!-- maxlength="3" /> -->
<input type="submit" value="回答" /> <!-- <input type="submit" value="回答" /> -->
</form> <!-- </form> -->
<hr /> <!-- <hr /> -->
// <?php
// if (is_null($_SESSION['answer'])) {
// mt_srand(microtime()*1000000);
// $_SESSION['answer']=mr_rand(1,100);
// $_SESSION['game_cnt']=0;
// }
// if($_POST['answer']!="") {
// $_SESSION['game_cnt']++;
// if ($_SESSION['answer']==$_POST['answer']) {
// print("おめでとうございます!".
// $_SESSION['game_cnt']."回で正解しました!");
// session_sestroy();
// } else {
// if ($_SESSION['answer'] > $POST['answer']) {
// print("もうすこし大きいです。");
// } else {
// print("もうすこし小さいです。");
// }
// }
// }
// ?>
<!-- </body> -->
<!-- </html> -->
<?php <?php
session_start();
if (is_null($_SESSION['answer'])) { $answer = 30;
if (is_null($answer)) {
mt_srand(microtime()*1000000); mt_srand(microtime()*1000000);
$_SESSION['answer']=mr_rand(1,100); $answer=mr_rand(1,100);
$_SESSION['game_cnt']=0;
} }
if($_POST['answer']!="") {
$_SESSION['game_cnt']++; $cou = 1;
if ($_SESSION['answer']==$_POST['answer']) { for (;;) {
print("おめでとうございます!". $myans = fgets(STDIN);
$_SESSION['game_cnt']."回で正解しました!"); if ($answer==$myans) {
session_sestroy(); echo "おめでとうございます!",
$cou, "回で正解しました!";
break;
} else { } else {
if ($_SESSION['answer'] > $POST['answer']) { $cou++;
if ($answer > $myans) {
print("もうすこし大きいです。"); print("もうすこし大きいです。");
} else { } else {
print("もうすこし小さいです。"); print("もうすこし小さいです。");
} }
} }
} }
?> ?>
</body> \ No newline at end of file
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment