<?php
include "wbyx.class.php";
$r = new Wbyx ("12");
$r->wabao();
$r->wabao();
$r->wabao();
$r->wabao();
$r->chakan();
var_dump ($r);
?>
<?php
class Wbyx
{
private $name;
private $blood;
private $gongji;
private $fangyu;
private $level;
private $qian;
private $jingyan;
private $jineng = array();
function __construct ($a)
{
$this->name = $a;
$this->blood = 50;
$this->gongji = 20;
$this->fangyu = 10;
$this->level = 1;
$this->qian = 50;
$this->jingyan = 0;
}
function wabao ()
{
$shu = floor(rand(0,100));
if($shu<53)
{
echo $this->zhandou();
}
else if($shu<65)
{
echo $this->jingyan();
}
else if($shu<75)
{
echo $this->qian();
}
else if($shu<83)
{
echo $this->gongji();
}
else if($shu<90)
{
echo $this->fangyu();
}
else if($shu<99)
{
echo $this->blood();
}
else if($shu<100)
{
echo $this->jineng();
}
else
{
echo $this->dengji();
}
}
function zhandou ()
{
echo "你遇到了一个怪物!<br>";
$B = floor(rand($this->blood-10,$this->blood+10));
$G = floor(rand($this->gongji-5,$this->gongji+5));
$F = floor(rand($this->fangyu-5,$this->fangyu+5));
$xue = $this->blood;
$gongji = $this->gongji;
$fangyu = $this->fangyu;
if ($this->blood > $B)
{
for(;;)
{
$B = $B - ($this->gongji - $F);
$this->blood = $this->blood - ($G - $this->fangyu);
if($this->blood <= 0)
{
if($this->level == 1)
{
echo "等级太低,饶你一命!<br>";
$this->blood = $xue;
}
else
{
echo "怪物把你揍扁了!<br>";
$this->level -=1;
$this->gongji -= floor(rand(1,6));
$this->fangyu -= floor(rand(1,3));
$this->blood = $xue - floor(rand(1,10));
$x1 = $xue-$this->blood;
$g1 = $gongji-$this->gongji;
$f1 = $fangyu-$this->fangyu;
echo "悲催,降级了!<br>血量减少了($x1)点!<br>攻击减少了($g1)点!<br>";
echo "防御减少了($f1)点!<br>";
}
break;
}
else if($B <= 0)
{
$J = floor(rand(5,15));
$Q = floor(rand(5,15));
echo $this->name."维护了世界的和平,奖励($J)点经验,($Q)点金钱!<br>";
$this->blood = $xue;
$this->jingyan += $J;
$this->qian += $Q;
if($this->jingyan >= 30)
{
echo "恭喜升级!<br>";
$this->jingyan = 0;
$this->level += 1;
$this->gongji();
$this->blood();
$this->fangyu();
}
break;
}
}
}
else
{
for(;;)
{
$this->blood = $this->blood - ($G - $this->fangyu);
$B = $B - ($this->gongji - $F);
if($this->blood <= 0)
{
if($this->level == 1)
{
echo "等级太低,饶你一命!<br>";
$this->blood = $xue;
}
else
{
echo "怪物把你揍扁了!<br>";
$this->level -=1;
$this->gongji -= floor(rand(1,6));
$this->fangyu -= floor(rand(1,3));
$this->blood = $xue - floor(rand(1,10));
$x1 = $xue-$this->blood;
$g1 = $gongji-$this->gongji;
$f1 = $fangyu-$this->fangyu;
echo "悲催,降级了!<br>血量减少了($x1)点!<br>攻击减少了($g1)点!<br>";
echo "防御减少了($f1)点!<br>";
}
break;
}
else if($B <= 0)
{
$J = floor(rand(5,15));
$Q = floor(rand(5,15));
echo $this->name."维护了世界的和平,奖励($J)点经验,($Q)点金钱!<br>";
$this->blood = $xue;
$this->jingyan += $J;
$this->qian += $Q;
if($this->jingyan >= 30)
{
echo "恭喜升级!<br>";
$this->jingyan = 0;
$this->level += 1;
$this->gongji();
$this->blood();
$this->fangyu();
}
break;
}
}
}
}
function jingyan ()
{
$j = floor(rand(0,10));
$this->jingyan += $j;
if($this->jingyan >= 30)
{
echo "恭喜升级!<br>";
$this->jingyan = 0;
$this->level += 1;
$this->gongji();
$this->blood();
$this->fangyu();
}
echo "恭喜你获得了($j)点经验<br>";
}
function qian ()
{
$q = floor(rand(0,10));
$this->qian += $q;
if($q==0)
{
echo "衰到家了,钱包是空的!<br>";
}
else
{
echo "恭喜你获得了($q)块钱<br>";
}
}
function gongji ()
{
$g = floor(rand(1,6));
$this->gongji += $g;
echo "恭喜你增加了($g)点攻击<br>";
}
function fangyu ()
{
$f = floor(rand(1,3));
$this->fangyu += $f;
echo "恭喜你增加了($f)点防御<br>";
}
function blood ()
{
$x = floor(rand(1,10));
$this->blood += $x;
echo "恭喜你增加了($x)点血<br>";
}
function jineng ()
{
$ji = floor(rand(0,3));
switch ($ji)
{
case 0:
array_push ($this->jineng,"火球术");
echo "恭喜学得了火球术<br>";
break;
case 1:
array_push ($this->jineng,"寒冰箭");
echo "恭喜学得了寒冰箭<br>";
break;
case 2:
array_push ($this->jineng,"炎爆术");
echo "恭喜学得了炎爆术<br>";
break;
case 3:
array_push ($this->jineng,"奥术冲击");
echo "恭喜学得了奥术冲击<br>";
break;
}
}
function dengji()
{
$this->level += 1;
$this->gongji();
$this->blood();
$this->fangyu();
echo "恭喜你升级了<br>";
}
function xuexi ()
{
$ji = floor(rand(0,12));
if($qian > 30)
{
$qian = $this->qian - 30;
switch ($ji)
{
case 0:
array_push ($this->jineng,"火球术");
echo "恭喜学得了火球术<br>";
break;
case 1:
array_push ($this->jineng,"寒冰箭");
echo "恭喜学得了寒冰箭<br>";
break;
case 2:
array_push ($this->jineng,"炎爆术");
echo "恭喜学得了炎爆术<br>";
break;
case 3:
array_push ($this->jineng,"奥术冲击");
echo "恭喜学得了奥术冲击<br>";
break;
default :
echo "很遗憾你没有学到技能!<br>";
break;
}
}
else
{
echo "大哥,你的money不够了!<br>";
}
}
function chakan ()
{
echo "你的血量是($this->blood)";
echo "你的等级是($this->level)";
echo "你的攻击是($this->gongji)";
echo "你的防御是($this->fangyu)";
echo "你的钱是($this->qian)";
}
}
?>