Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
1
10php
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yu Kimiduka
10php
Commits
cab3bfe5
Commit
cab3bfe5
authored
Jul 07, 2016
by
君塚 悠
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
プログラム修正(game.php:bashで動くように)
parent
72860410
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
29 deletions
+54
-29
game.php
php/php10/day03-2/game.php
+54
-29
No files found.
php/php10/day03-2/game.php
View file @
cab3bfe5
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment