PHP设计模式:建造者模式

前言

建造者模式(Builder Pattern)使用多个简单的对象一步一步构建成一个复杂的对象。这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式。

代码

 
        唱:攻击时给予友方精神亢奋BUFF。
        跳:有一定几率闪避地方攻击,
        rap,攻击时附加精神伤害
        隐藏技能绿狮含:召唤上古绿色雄狮含住敌方,成功含住后有一定几率使敌方陷入鬼畜状态' . PHP_EOL;
    }
}

//定义一个普通玩家
class NormalPlayer extends Equipment
{

    public function helmets()
    {
        echo '含羞头巾:作为loser的你只能绑一根草' . PHP_EOL;
    }

    public function clothes()
    {
        echo '一身胸毛:可能能起到御寒作用' . PHP_EOL;
    }

    public function jackets()
    {
        echo '破洞裤:陈旧的鹿皮' . PHP_EOL;
    }

    public function belt()
    {
        echo '树皮腰带:偶尔还能吸引蚂蚁' . PHP_EOL;
    }


    public function wrists()
    {
        echo '红丝带:纪念品' . PHP_EOL;
    }

    public function shoes()
    {
        echo '草环戒指:气血+1' . PHP_EOL;
    }

    public function jewelry()
    {
        echo '破旧的帆布鞋:移动速度+1' . PHP_EOL;
    }

    public function weapons()
    {
        echo '小木棒:攻击+1' . PHP_EOL;
    }

    public function mounts()
    {
        echo '巨大的蚂蚁:一只变异的蚂蚁,偶尔会嗜主' . PHP_EOL;
    }
}

class BuilderFace
{
    public $face;

    public function __construct($face)
    {
        $this->face = $face;
    }

    //定义一个创建装备的方法
    public function createFace()
    {
        $this->face->helmets();
        $this->face->clothes();
        $this->face->jackets();
        $this->face->wrists();
        $this->face->shoes();
        $this->face->jewelry();
        $this->face->weapons();
        $this->face->mounts();
    }
}

$handsome = new BuilderFace(new RmbPlayer());
echo 'RMB玩家' . PHP_EOL;
$handsome->createFace();
echo '-------------' . PHP_EOL;
echo '普通玩家' . PHP_EOL;
$handsome = new BuilderFace(new NormalPlayer());
$handsome->createFace();

输出

image.png

你可能感兴趣的:(PHP设计模式:建造者模式)