+ -
当前位置:首页 → 问答吧 → (opp)我编写的php"爱情规则"代码

(opp)我编写的php"爱情规则"代码

时间:2007-04-18

来源:互联网

复制PHP内容到剪贴板
PHP代码:
以下是爱情类: 
love_class.php 
--------------------------------------- 
<?php 

//Created By Terry 
//2007-04-17 
//www.meiu.cn 

class 人 { 
 public $姓名 ; 
 public $年龄 ; 
 public $感情 ; 
 public $生日 ; 
 public $位置 ; 
 protected function  __construct ( $人 ) { 
   $this->姓名 = $人["姓名"] ; 
   $this->年龄 = $人["年龄"] ; 
   $this->生日 = $人["生日"] ; 
   $this->感情 = $人["感情"] ; 
   $this->位置 = $人["位置"] ; 
 } 
 public function 去 ( $地方 ){ 
  $this->位置 = $地方; 
  echo "<strong>". $this->姓名 ."</strong>去了<strong>".$地方 ."</strong><br />" ; 
 } 
 public function 来 ( $地方 ){ 
  $this->位置 = $地方; 
  echo "<strong>". $this->姓名 ."</strong>来了<strong>".$地方 ."</strong><br />" ; 
 } 

class 男人 extends 人 { 
  private $钱 ; 
  private $车 ; 
  private $房 ; 
  public function  __construct($人 ) { 
   parent::__construct( $人 );  
   $this->钱 = $人["钱"] ; 
   $this->车 = $人["车"] ; 
   $this->房 = $人["房"] ; 
  } 
  public function 有房() { 
   if( $this->房 >0 ){ 
    return true; 
   } 
   else{ 
    return false; 
   } 
  } 
  public function 有车() { 
   if( $this->车 >0 ){ 
    return true; 
   } 
   else{ 
    return false; 
   } 
  } 
  public function 拼命赚钱 ( $time ) { 
   $this->钱 =  $this->钱 + 500 ; 
   echo date("Y年m月d日 ",$time)."<strong>".$this->姓名 ."</strong>拼命赚钱,现在拥有<strong>".$this->钱 ."</strong>元<br />"; 
   if($this->钱 >=90000 && $this->车 == 0 ){ 
    $this->车 = $this->车 + 1; 
    $this->钱 = $this->钱 - 90000; 
    echo "<strong>".$this->姓名 ."</strong>买了车<br />"; 
   } 
   if($this->钱 >=500000 && $this->房 == 0 ){ 
    $this->房 = $this->房 + 1; 
    $this->钱 = $this->钱 - 500000; 
    echo "<strong>".$this->姓名 ."</strong>买了房<br />"; 
   } 
  } 
  public function 获得钱的数量() { 
   return $this->钱 ; 
  } 
  public function 送玫瑰($女孩) { 
   /*产生随机数*/ 
   mt_srand((double)microtime() * 10000000); 
            $randval_1 = mt_rand(); 
            mt_srand((double)microtime() * 99999999); 
            $randval_2 = mt_rand(); 
            $randval = $randval_1 + $randval_2; 
             $randval = substr ($randval, 2, 8); 
             /*产生随机数结束*/ 
     if($randval%2==0){//如果是偶数就送玫瑰 
   $女孩->玫瑰数增加(); 
      echo "<strong>".$this->姓名 ."</strong>送".$女孩->姓名 ."玫瑰, 玫瑰数为". $女孩->获得玫瑰数() ."<br />"; 
   return true; 
     }else //奇数就不送 
     return false; 
  } 
  public function 送生日礼物($女孩) { 
   /*产生随机数*/ 
     mt_srand((double)microtime() * 10000000); 
            $randval_1 = mt_rand(); 
            mt_srand((double)microtime() * 99999999); 
            $randval_2 = mt_rand(); 
            $randval = $randval_1 + $randval_2; 
             $randval = substr ($randval, 2, 8); 
             /*产生随机数结束*/ 
     if($randval%2==0){//如果是偶数就送礼物 
   echo "<strong>".$this->姓名 ."</strong>送".$女孩->姓名 ."生日礼物<br />"; 
   return true; 
     }else //奇数就不送 
     return false; 
  } 

class 女人 extends 人 { 
  private $玫瑰数 ; 
  public function  __construct($人 ){ 
   parent::__construct( $人 );  
   $this->玫瑰数 = $人["玫瑰数"] ; 
  } 
  public function 获得感情值() { 
   return $this->感情; 
  } 
  public function 获得玫瑰数() { 
   return $this->玫瑰数; 
  } 
  public function 玫瑰数增加() { 
   $this->玫瑰数 ++; 
  } 
  public function 愿意等() { 
   /*产生随机数*/ 
     mt_srand((double)microtime() * 10000000); 
            $randval_1 = mt_rand(); 
            mt_srand((double)microtime() * 99999999); 
            $randval_2 = mt_rand(); 
            $randval = $randval_1 + $randval_2; 
             $randval = substr ($randval, 2, 8); 
             /*产生随机数结束*/ 
     if($randval%2==0){//如果是偶数就愿意等 
      echo "<strong>".$this->姓名 ."</strong>愿意等!<br />"; 
      return true; 
     }else{ 
      echo "<strong>".$this->姓名 ."</strong>不愿意等!<br />"; 
      return false; 
     } 
  } 
  public function 嫁给 ( $男孩 ) { 
   echo "<strong>".$this->姓名 ."</strong>嫁给了<strong>".$男孩 ->姓名 ."</strong>,感情值为". $this->获得感情值() .",得到的玫瑰数为".$this->获得玫瑰数() .".<br />此时男孩".$男孩 ->年龄 ."岁,住在".$男孩 ->位置 .",女孩".$this ->年龄 ."岁,住在".$this ->位置 ."<br />"; 
  } 
  public function 嫁给他人 () { 
   echo "<strong>".$this->姓名 ."</strong>嫁给了其他男孩.<br />"; 
  } 


class 爱情 
{                                  

public $男孩 ; 
public $女孩 ; 
public $开始时间 ; 
public $想持续时间 ; 

 public function  __construct($男 , $女 ,$开始时间 ,$想持续时间 ){ 
 $this->男孩 = new 男人($男) ; 
 $this->女孩 = new 女人($女) ; 
 $this->开始时间 = strtotime($开始时间 ); 
 $this->想持续时间 = $想持续时间 ; 
 echo "<strong>".$this->男孩 -> 姓名. "</strong>和<strong>".$this->女孩 -> 姓名 ."</strong>开始恋爱了<br />"; 
 echo "男孩的资料<br />"; 
  while(list( $key , $value ) = each ( $男 )){ 
   echo $key.":".$value."<br />"; 
  } 
 echo "女孩的资料<br />"; 
  while(list( $key , $value ) = each ( $女 )){ 
   echo $key.":".$value."<br />"; 
  } 
 } 
  
 public function 获得他们的位置() { 
 echo "<strong>".$this->男孩 -> 姓名. "</strong>在<strong>".$this->男孩 -> 位置. "</strong>,<strong>".$this->女孩 -> 姓名 ."</strong>在<strong>".$this->女孩 -> 位置. "</strong><br />"; 
 } 
  
 public function 女孩感情增加() { 
 $this->女孩 -> 感情 ++; 
 echo "<strong>".$this->女孩 ->姓名 ."</strong>的感情增加到<strong>".$this->女孩 -> 感情 ."</strong><br />"; 
 } 
  
 public function 女孩感情减少() { 
 $this->女孩 -> 感情 --; 
 echo "<strong>".$this->女孩 ->姓名 ."</strong>的感情减少到<strong>".$this->女孩 -> 感情 ."</strong><br />"; 
 } 
 public function 两人的年龄增加() { 
  $this->女孩 -> 年龄 ++; 
  $this->男孩 -> 年龄 ++; 
  echo "两人都长了一岁!<br />"; 
 } 

?> 
------------------------------------------------ 
以下是实例: 
love.php 
------------------------------------------------ 
<?php 
require_once("love_class.php"); 

//Created By Terry 
//2007-04-17 
//www.meiu.cn 

//两个人的资料 
$男孩 = array( 
 "姓名"=> "男孩", 
 "年龄"=>23, 
 "生日"=>"11.25", 
 "感情"=>0, 
 "位置"=>"苏州", 
 "钱"=>0, 
 "车"=>0, 
 "房"=>0 
); 
$女孩 = array( 
 "姓名"=> "女孩", 
 "年龄"=>24, 
 "生日"=>"07.29", 
 "感情"=>0, 
 "位置"=>"湖南", 
 "玫瑰数"=>0 
); 
$开始时间="2005-11-25" ; 
$想持续时间="1000" ; //单位天 
//创建爱情 
$我们的爱情 = new 爱情 ($男孩 , $女孩 ,$开始时间 , $想持续时间 ); 
$我们的爱情->获得他们的位置() ; 
$我们的爱情->男孩->去("湖南") ; 
$我们的爱情->获得他们的位置() ; 
$我们的爱情->女孩感情增加() ; 
$我们的爱情->男孩->去("苏州") ; 
$我们的爱情->女孩->来("苏州") ; 
$我们的爱情->获得他们的位置() ; 
//如果男孩有车,有房,女孩嫁给男孩 
if ( $我们的爱情->男孩->有房() && $我们的爱情->男孩->有车()) 
$我们的爱情->女孩->嫁给($我们的爱情->男孩) ; 
else if ( $我们的爱情->女孩->愿意等() ){//女孩愿意等男孩 
 $starttime=$我们的爱情->开始时间 ; 
 $time=$starttime; 
 while(!($我们的爱情->男孩->获得钱的数量() >= 1000000) && ($time-$starttime)<=86400000){ 
  for($j=0;$j<$我们的爱情->想持续时间 ;$j++){ 
   $time=$time+86400;//时间加一天 
   if(date("m.d",$time)==$我们的爱情->女孩->生日) { //如果是女孩的生日的话 
    if($我们的爱情->男孩->送生日礼物($我们的爱情->女孩)) { 
    $我们的爱情->女孩感情增加() ; 
    }else{ 
    $我们的爱情->女孩感情减少() ; 
    } 
   } 
   if(date("m.d",$time)=="01.01") { 
    $我们的爱情->两人的年龄增加() ; 
   } 
   if(date("m.d",$time)=="02.14") { //如果是情人节的话 
    if($我们的爱情->男孩->送玫瑰($我们的爱情->女孩)) { 
    $我们的爱情->女孩感情增加() ; 
    }else{ 
    $我们的爱情->女孩感情减少() ; 
    } 
   } 
   $我们的爱情->男孩->拼命赚钱 ($time) ; 
  } 
 } 
 if ( $我们的爱情->男孩->有房() && $我们的爱情->男孩->有车() && ( $我们的爱情->女孩->获得感情值() >= 5 || $我们的爱情->女孩->获得玫瑰数()>=3 ) ) 
 $我们的爱情->女孩->嫁给($我们的爱情->男孩) ; 
 else 
 $我们的爱情->女孩->嫁给他人() ; 
}else{ 
 $我们的爱情->女孩->嫁给他人() ; 

?>
------------------------------------------------
预览效果:http://www.weblinux.cn/love.php

[ 本帖最后由 wksvo 于 2007-4-18 09:45 编辑 ]

作者: wksvo   发布时间: 2007-04-18

楼主相当有创意,很不错.

作者: 月黑风高   发布时间: 2007-04-18

这个在utf-8编码下能运行吗?

作者: tom_x   发布时间: 2007-04-18

引用:
原帖由 tom_x 于 2007-4-18 13:07 发表
这个在utf-8编码下能运行吗?
不知道。应该可以吧。等会儿试试。

作者: wksvo   发布时间: 2007-04-18

这么多

作者: skyjhz   发布时间: 2007-04-18

还能用中文,php就是好

作者: heixiake   发布时间: 2007-04-18

男人好累

作者: 月黑风高   发布时间: 2007-04-19

我靠

作者: 星野天河   发布时间: 2007-05-12

最后女孩嫁给了其他男孩;P

作者: yt   发布时间: 2007-05-14

好强呀!

作者: rednetcn   发布时间: 2007-06-05