【发布时间】:2017-11-26 07:04:44
【问题描述】:
我有一个游戏,玩家可以完成一些任务。
我已将任务的行为部分与其 ORM 部分分开。 最终,任务的副本会保存在玩家文档的某个位置(对于这个特定问题来说并不重要)。
问题是,我不确定将我发送给客户端的额外信息放在哪里,这些信息对于行为本身来说不是必需的,但需要显示有关任务本身的玩家信息。
这是我的任务界面:
interface ITask
{
/**
* @param Player $player
*/
public function init(Player $player);
/**
* @param PlayerAction $action
*/
public function progress(PlayerAction $action);
public function reset();
/**
* @return bool
*/
public function isComplete();
}
这是我的抽象任务:
abstract class BaseTask implements ITask
{
/**
* @var int
*/
public $id;
/**
* @var int
*/
protected $currentValue;
/**
* @var int
*/
protected $targetValue;
public function __construct($targetValue)
{
$this->currentValue = 0;
$this->targetValue = $targetValue;
}
/**
* @param int
*/
public abstract function setCurrentValue($current);
/**
* @return int
*/
public abstract function getCurrentValue();
/**
* @return int
*/
public abstract function getID();
/**
* @param int
*/
public abstract function setID($id);
/**
* @return int
*/
public abstract function getTargetValue();
/**
* @param int
*/
public abstract function setTargetValue($target);
/**
* @return boolean
*/
public function isComplete()
{
if ($this->getCurrentValue() >= $this->getTargetValue())
{
return true;
}
return false;
}
}
现在我需要决定如何放置额外数据,例如描述、标题、主题等...
- 我想了两个选择:我可以把它放在基础任务上 本身,但是如果我不需要它会发生什么?我只是离开它 空白的?感觉对我来说是个错误的地方。
- 我可以创建一个包装器 将举行任务的班级,但随后我将需要始终 调用包装器来完成任务,感觉有点像 错了。
寻找替代建议。
【问题讨论】:
标签: php design-patterns orm