cay89/achieve

Achive 是一个 PHP 的成就实现和管理库。

dev-master 2018-05-25 08:32 UTC

This package is auto-updated.

Last update: 2024-09-26 01:25:28 UTC


README

Achive 是基于 Dovyski/Achieve 的 (https://github.com/Dovyski/Achieve) 理念的成就实现和管理库。要了解其工作原理,请参阅以下文章:https://gamedevelopment.tutsplus.com/tutorials/how-to-code-unlockable-achievements-for-your-game-a-simple-approach--gamedev-6012

入门

安装

composer require cay89/achieve

创建自己的属性和成就类

由于灵活性和对特定应用程序行为的支持,我使用了接口和特性来实现库的业务逻辑。因此,只需实现我的接口并在自己的类中使用我的特性,如果需要,可以重写它们。

属性

use cay89\Achieve\PropertyInterface;
use cay89\Achieve\PropertyTrait;

class Property implements PropertyInterface {
    use PropertyTrait;

    // Database, application-specific operations etc.
}

成就

use cay89\Achieve\AchievementInterface;
use cay89\Achieve\AchievementTrait;

class Achievement implements AchievementInterface {
    use AchievementTrait;

    // Database, application-specific operations etc.
}

定义属性

  1. 属性的名称。
  2. 验证此条件是否满足的函数。
  3. (可选) 将传递给 "condition" 函数的参数。
  4. (可选) 属性的标签。
$property = new Property('Greater then 10', function($params) {
    return ($params['value'] > 10);
}, ['value' => 25], ['level1']);

定义成就

  1. 成就的名称。
  2. 如果这些属性是 "活跃" 的,则成就将被解锁。
$achievement1 = new Achievement('Achievement 1', [$property1, $property2]);

Achieve 类的使用

使用成就对象实例化 Achieve 类,并调用 check() 方法来验证成就的要求。它返回已解锁的成就。

$achieve = new Achieve([$achievement1, $achievement2]);
$achieve->check();

请参阅以下路径以获取更多示例:example/example.php