728x90
반응형
<?php
$word=$_POST['start'];
$count=0;
$strike=0;
$ball=0;
$out=0;
$z=0;
if (empty($word)){
$num=rand(100,999);
$before=$_POST['before'];
$before=$num;
$try=0;
}
else {
$before=$_POST['before'];
for ($count=0; $count<3; $count++){
if ($word[$count]==$before[$count]){
$strike++;
continue;
}
else if ($word[$count]!=$before[$count]){
for ($z=0; $z<3; $z++){
if ($word[$count]==$before[$z]){
$ball++;
break;
}
if ($word[$count]!=$before[$z]&& $z==2){
$out++;
}
}
}
}
}
echo "<center><font size='10' color='#5853EB' face='Impact'>".'Base Ball';
?>
<html>
<head> <title> 숫자야구 </title></head>
<body>
<div style="border:solid 4px #A19CFF; width:400px ; height:250px ; padding:10px;">
<div>
<center>
<?php
if (isset($word)){
$try=$_POST['try'];
$try++;
if (($try%10==0) && ($try!=0)){
echo "<font size='2' color='474747'>"."정답은".$before."입니다."."<br>";
}
if(($try%10==1) && ($try!=1)){
$try=1;
$num=rand(100,999);
$before=$_POST['before'];
$before=$num;
}
}
echo"<font size='6' color='#FFE400' face='Comic Sans MS'>".$strike." "."<b>"."Strike"."<br>";
echo"<font size='6' color='#6ABC64' face='Comic Sans MS'>".$ball." "."<b>"."ball"."<br>";
echo"<font size='6' color='#FF6C6C' face='Comic Sans MS'>".$out." "."<b>"."Out"."<br>"."<br>";
echo "<font size='4' color='474747'>"."시도횟수". $try ;
if ($strike==3){
echo "<script>alert('정답입니다');</script>";
$try=0;
$num=rand(100,999);
$before=$_POST['before'];
$before=$num;
}
?>
<form method="POST" action="">
<input type="text" name="start">
<input type="hidden" name="before" value="<?=$before;?>" />
<input type="hidden" name="try" value="<?=$try;?>" />
<input type="submit">
</form>
</center>
</body>
</html>
728x90
반응형
'WEB' 카테고리의 다른 글
Rest api (1) | 2023.01.08 |
---|---|
Web Storage (0) | 2023.01.07 |
정규표현식 (0) | 2022.12.29 |
HTTP METHOD (0) | 2022.12.29 |
Sever Side & Client Side (0) | 2022.12.29 |