假设我正在制作视频游戏。玩家有一个 X 和一个 Y 坐标,这些值是 Player
对象的成员。我们还假设我正在使用假设的 GAME-X
游戏引擎,它使用 GX_x
和 GX_y
值渲染每个对象。
如果我想将域(Player
)与 View (GAME-X
)分开,我的理解是播放器应该有自己的 X
和 Y
坐标是独立操作的,而 GX_x
和 GX_y
只是“监听”玩家的当前坐标。例如,这样做可以让我选择一个新的游戏引擎,同时保持域层不变。这也意味着游戏基本上可以在严格的域级别上运行。
这是一个好的设计策略吗?如果不是,为什么?如果是这样,该策略的真实名称是什么?我如何在整个系统中改进它?
最佳答案
player should have its own X and Y coordinates which are manipulated independently, and the GX_x and GX_y simply "listen" to the player's current coordinates.
这是正确的策略。由于 GX_x
,GX_y
是表示级的并且可以是特定于设备/分辨率/引擎的。
考虑 2 部分辨率为 480*320
和 960*640
的手机。 x
,y
在你的模型中应该是相同的(在两部手机中运行相同的代码)而 GX_x
和 GX_y
在两种设备上会有所不同。
是Model View Controller你说的模式。
choose a new game engine while leaving the domain layer untouched. It also means that the game can essentially run on a strictly domain level.
这些是使用该模式的优点和原因。
关于oop - 模型/ View 分离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18276025/