做个猜数字的游戏:
1 随机出一个1-100的数字
2 接受猜猜,告诉是大是小
时间:20分钟
可以试玩一下
<?
@session_start();
echo <<<EOT
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="UTF-8" />
EOT;
class guess{
var $num=0;
var $step=0;
var $newgame=false;
var $message="";
function guess(){
if(!isset($_SESSION['num'])){
$_SESSION['num']=rand(0,100);
$_SESSION['step']=0;
$this->newgame=true;
}
$this->num=$_SESSION['num'];
$this->step=$_SESSION['step'];
//echo $this->num;
}
function add_step(){
$this->step++;
$_SESSION['step']=$this->step;
}
function check(){
if($this->newgame==true){
$this->message="游戏开始";
$this->show_form();
}else{
if(isset($_POST['mynum'])){
$this->add_step();
$this->message="你猜了".$this->step."次,";
if($_POST['mynum']==$this->num){
$this->show_ok();
}else{
if($_POST['mynum']>$this->num)
$this->message.="你猜的数过大";
else
$this->message.="你猜的数过小";
$this->show_form();
}
}else{
$this->show_form();
}
}
}
function show_form(){
$form=$this->message.'<form method=post action="">
<input type="text" name="mynum"><input type="submit">
</form>';
echo $form;
}
function show_ok(){
unset($_SESSION['num']);
unset($_SESSION['step']);
$form=$this->message.'你猜对了!<a href="?">重新开始</a>';
echo $form;
}
}
$a=new guess;
$a->check();
?>
原创内容如转载请注明:来自 阿权的书房
1 随机出一个1-100的数字
2 接受猜猜,告诉是大是小
时间:20分钟
可以试玩一下
<?
@session_start();
echo <<<EOT
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="UTF-8" />
EOT;
class guess{
var $num=0;
var $step=0;
var $newgame=false;
var $message="";
function guess(){
if(!isset($_SESSION['num'])){
$_SESSION['num']=rand(0,100);
$_SESSION['step']=0;
$this->newgame=true;
}
$this->num=$_SESSION['num'];
$this->step=$_SESSION['step'];
//echo $this->num;
}
function add_step(){
$this->step++;
$_SESSION['step']=$this->step;
}
function check(){
if($this->newgame==true){
$this->message="游戏开始";
$this->show_form();
}else{
if(isset($_POST['mynum'])){
$this->add_step();
$this->message="你猜了".$this->step."次,";
if($_POST['mynum']==$this->num){
$this->show_ok();
}else{
if($_POST['mynum']>$this->num)
$this->message.="你猜的数过大";
else
$this->message.="你猜的数过小";
$this->show_form();
}
}else{
$this->show_form();
}
}
}
function show_form(){
$form=$this->message.'<form method=post action="">
<input type="text" name="mynum"><input type="submit">
</form>';
echo $form;
}
function show_ok(){
unset($_SESSION['num']);
unset($_SESSION['step']);
$form=$this->message.'你猜对了!<a href="?">重新开始</a>';
echo $form;
}
}
$a=new guess;
$a->check();
?>
原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
VSFTPD的配置参考
vsftp:500 OOPS: could not bind listening IPv4 socket 解决办法 
