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

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

parent 72860410
session_start();
<html>
<head>
<title>数当てゲーム</title>
</head>
</html>
<body>
<h1 style="background: #cccccc#>数当てゲーム</h1>
<form method="POST" action="game.php">
1~100までの中からいずれかの数を入力してください:
<input type="text" name="answer" size="5"
maxlength="3" />
<input type="submit" value="回答" />
</form>
<hr />
<!-- session_start(); -->
<!-- <html> -->
<!-- <head> -->
<!-- <title>数当てゲーム</title> -->
<!-- </head> -->
<!-- </html> -->
<!-- <body> -->
<!-- <h1 style="background: #cccccc#>数当てゲーム</h1> -->
<!-- <form method="POST" action="game.php"> -->
<!-- 1~100までの中からいずれかの数を入力してください: -->
<!-- <input type="text" name="answer" size="5" -->
<!-- maxlength="3" /> -->
<!-- <input type="submit" value="回答" /> -->
<!-- </form> -->
<!-- <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
session_start();
if (is_null($_SESSION['answer'])) {
$answer = 30;
if (is_null($answer)) {
mt_srand(microtime()*1000000);
$_SESSION['answer']=mr_rand(1,100);
$_SESSION['game_cnt']=0;
$answer=mr_rand(1,100);
}
if($_POST['answer']!="") {
$_SESSION['game_cnt']++;
if ($_SESSION['answer']==$_POST['answer']) {
print("おめでとうございます!".
$_SESSION['game_cnt']."回で正解しました!");
session_sestroy();
$cou = 1;
for (;;) {
$myans = fgets(STDIN);
if ($answer==$myans) {
echo "おめでとうございます!",
$cou, "回で正解しました!";
break;
} else {
if ($_SESSION['answer'] > $POST['answer']) {
$cou++;
if ($answer > $myans) {
print("もうすこし大きいです。");
} else {
print("もうすこし小さいです。");
......@@ -35,5 +62,3 @@ if($_POST['answer']!="") {
}
}
?>
\ No newline at end of file
</body>
</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