挖宝游戏

include "wbyx.class.php";

$r = new Wbyx ("12");
$r->wabao();
$r->wabao();
$r->wabao();
$r->wabao();


$r->chakan();
var_dump ($r);

 


?>

 

 

 

 

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 "你遇到了一个怪物!
";

$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 "等级太低,饶你一命!
";
$this->blood = $xue;
}
else
{
echo "怪物把你揍扁了!
";
$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 "悲催,降级了!
血量减少了($x1)点!
攻击减少了($g1)点!
";
echo "防御减少了($f1)点!
";
}
break;
}
else if($B <= 0)
{
$J = floor(rand(5,15));
$Q = floor(rand(5,15));
echo $this->name."维护了世界的和平,奖励($J)点经验,($Q)点金钱!
";
$this->blood = $xue;
$this->jingyan += $J;
$this->qian += $Q;
if($this->jingyan >= 30)
{
echo "恭喜升级!
";
$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 "等级太低,饶你一命!
";
$this->blood = $xue;
}
else
{
echo "怪物把你揍扁了!
";
$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 "悲催,降级了!
血量减少了($x1)点!
攻击减少了($g1)点!
";
echo "防御减少了($f1)点!
";
}
break;
}
else if($B <= 0)
{
$J = floor(rand(5,15));
$Q = floor(rand(5,15));
echo $this->name."维护了世界的和平,奖励($J)点经验,($Q)点金钱!
";
$this->blood = $xue;
$this->jingyan += $J;
$this->qian += $Q;
if($this->jingyan >= 30)
{
echo "恭喜升级!
";
$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 "恭喜升级!
";
$this->jingyan = 0;
$this->level += 1;
$this->gongji();
$this->blood();
$this->fangyu();
}
echo "恭喜你获得了($j)点经验
";
}
function qian ()
{
$q = floor(rand(0,10));
$this->qian += $q;
if($q==0)
{
echo "衰到家了,钱包是空的!
";
}
else
{
echo "恭喜你获得了($q)块钱
";
}
}
function gongji ()
{
$g = floor(rand(1,6));
$this->gongji += $g;
echo "恭喜你增加了($g)点攻击
";
}
function fangyu ()
{
$f = floor(rand(1,3));
$this->fangyu += $f;
echo "恭喜你增加了($f)点防御
";
}
function blood ()
{
$x = floor(rand(1,10));
$this->blood += $x;
echo "恭喜你增加了($x)点血
";
}
function jineng ()
{
$ji = floor(rand(0,3));
switch ($ji)
{
case 0:
array_push ($this->jineng,"火球术");
echo "恭喜学得了火球术
";
break;
case 1:
array_push ($this->jineng,"寒冰箭");
echo "恭喜学得了寒冰箭
";
break;
case 2:
array_push ($this->jineng,"炎爆术");
echo "恭喜学得了炎爆术
";
break;
case 3:
array_push ($this->jineng,"奥术冲击");
echo "恭喜学得了奥术冲击
";
break;
}
}
function dengji()
{
$this->level += 1;
$this->gongji();
$this->blood();
$this->fangyu();
echo "恭喜你升级了
";
}
function xuexi ()
{
$ji = floor(rand(0,12));
if($qian > 30)
{
$qian = $this->qian - 30;
switch ($ji)
{
case 0:
array_push ($this->jineng,"火球术");
echo "恭喜学得了火球术
";
break;
case 1:
array_push ($this->jineng,"寒冰箭");
echo "恭喜学得了寒冰箭
";
break;
case 2:
array_push ($this->jineng,"炎爆术");
echo "恭喜学得了炎爆术
";
break;
case 3:
array_push ($this->jineng,"奥术冲击");
echo "恭喜学得了奥术冲击
";
break;
default :
echo "很遗憾你没有学到技能!
";
break;
}
}
else
{
echo "大哥,你的money不够了!
";
}
}
function chakan ()
{
echo "你的血量是($this->blood)";
echo "你的等级是($this->level)";
echo "你的攻击是($this->gongji)";
echo "你的防御是($this->fangyu)";
echo "你的钱是($this->qian)";
}





}

?>

转载于:https://www.cnblogs.com/1116zsc/p/5470517.html

你可能感兴趣的:(java,php)