Posted on 2008-11-19 00:57
Fox 阅读(1888)
评论(3) 编辑 收藏 引用 所属分类:
T技术碎语
State模式对应到C++的多态特性。
State模式适用较广,这儿给出比较常见易懂的三种情况:
1. 当怪物在面对不同职业和特性的玩家时对应不同的AI处理和技能释放:
CSkill* pAttackSkill;
if( pPlayer->MagicImmune() ) pAttackSkill = SomePhysicalAttackSkill;
else if( pPlayer->PhysicalImmune() ) pAttackSkill = SomeMagicAttackSkill;
...
pAttackSkill->Begin();
...
或者使用分支结构:
CSkill* pAttackSkill;
switch( pPlayer->GetOccupation() )
{
case WARRIOR: pAttackSkill = SomeLongRangeSkill; break;
case MAGICIAN: pAttackSkill = SomeForceSkill; break;
case NIMROD: pAttackSkill = SomeMagicSkill; break;
...
}
pAttackSkill->Begin();
...
阅读全文