DP
2023-02-22 21:16:35 0 举报
项目结构
作者其他创作
大纲/内容
工厂模式角色工程ICharacterFactory
GameFacade
RegisterObserver()Notify()
UI系统
GameEventType
士兵工厂SoldierFactory
font color=\"#323232\
SoldierCamp
- const MAX_LV = 4: int- mLevel = 1: int- mWeaponType = WeaponType.Gun: WeaponType
兵营信息UIUICampInfo
AssetsFactory
SoldierIdleState
CharacterSystem
IAttrFactory
NewStageObserverAchiecement
- mAchievementSystem: AchievementSystem- mSubject: NewStageSystem
+ EnemyKilledObserverAchievement(AchievementSystem achievementSystem)+ Update(): void+ SetSubject(IGameEventSubject subject): void
FactoryManager
StartState
显示logo
SoldierBuilder
士兵信息UIUISoldierInfo
角色状态基类使用策略模式实现不同角色根据不同等级策略修改属性ICharacterAttr
# mBaseAttr: CharacterBaseAttr# mCurrentHP: int# mLv: int# mCriticalRate: float# mAttrStrategy: IAttrStrategy
AliveCountVisitor
- enemyCount: int- soldierCount: int
+ GetEnemyCount(): int+ GetSoldierCount(): int+ VisitEnemy(IEnemy enemy): void+ VisitSoldier(ISoldier soldier): void+ Reset(): void
SoldierEnergyCostStrategy
享元模式AttrFactory
+ AttrFactory+ GetCharacterBaseAtatar(System.Type t): CharacterBaseAttr+ InitCharacterBaseAttr(): void
AchievementSystem
IEnemy
CaptiveCamp
- mEnemyType: EnemyType- mWeaponType = WeaponType.Gun: WeaponType
敌人状态基类IEnemyState
EnemyAttrStrategy
SoldierAttackState
- mAttackCoolDownTime: float-mCurrentAttackTime: float;
NewStageSubject
- mStageCount: int
+ StageCount(): int+ Notify(): void
玩家状态UIUIStateInfo
资源管理
角色系统CharacterSystem
游戏循环GameLoop:MonoBehavior
具体士兵类SoldierSergent
# PlaySound(): void# PlayEffect(): void
IWeaponFactory
+ CreatWeapon(WeaponType type): IWeapon
WeaponFactory
具体敌人类EnemyOrge
+ PlayEffect(): void
AchievemenntMemento
+ enemyKilledCount: int+ soldierKilledCount: int+ maxStageLevel: int
+ SaveData(): void+ LoadData(): void
+ EnemyTransition: enum+ EnemyStateId: enum
AddSoldier()
状态模式:负责游戏场景状态管理及切换基类ISceneState
- stateController: StateController - stateName: string
武器基类,与角色类形成桥接模式模板模式实现武器开火IWeapon
攻击属性# mAttkPoint: int# mAttkRange: float// # mCriticalPoint: int 由ICharacterAttr提供对应游戏物体# mGameObject: GameObject# mOwner: ICharacter特效和显示# mParticle: ParticalSystem# mLight: Light# mLineRenderer: LineRenderer# mAudioSource: AudioSource# mEffectPlayTime: float
角色基类访问者模式NodeICharacter
# ICharacterAttr mAttr# mGameObject: GameObject # mNavAgent: NavMeshAgent # mAudioSource: AudioSource # mWeapon: IWeapon # mAnim: Animation# mIsKilled: bool# mCanBeDestroyed: bool# mDestroyTimer: float
+ Update(): void+ CanBeDestroyed: bool+ IsKilled(): bool+ SetWeapon(): void+ Weapon(): IWeapon+ GameObj(): GameObject+ SetCharacterObject: void+ SetAttr(): void+ GetAttr(): ICharacterAttr+ AttackRange: float+ Attack(ICharacter target): void+ virtual UnderAttack(int damage): void+ PlayAnim(string animName): void+ MoveTo(Vector3 destPosition): void+ GetPosition: Vector3+ virtual Killed(): void+ Release(): void# DoPlaySoundGeneric(string soundName): void# DoPlayEffectGeneric(string effectName): void+ abstract Runvisitor(ICharacterVisitor characterVisitor): void
UIStateInfo
具体士兵类SoldierCaptain
CreatCharacter<>()RemoveEnemy()AddSoldier()
具体士兵类SoldierRookie
enemyFactory
备忘录模式实现保存和恢复成就数据AchievementSystem
- mEnemyKilled: int- mSoldierKilled: int- mMaxStageLevel: int
+ Init(): void+ AddEnemyKilledCount(int number): void+ AddSoldierKilledCount(int number): void+ SetMaxStageLevel(int stageLevel): void+ CreateMemento(int number = 1): AchievementMemento+ SetMemento(AchievemenntMemento memento): void
UI系统基类abstract IUISystem
+ mRootUI: GameObject
+ virtual Init(): void+ virtual Update(): void+ virtual End(): void+ Show(): void+ Show(GameObject go): void+ Hide(): void+ Hide(GameObject): void
成就系统 AchievementSystem
...- mMsgTimer: float- mMsgMaxTime: float- mAliveCountVisitor: AliveCountVisitor
MonoBehaviour
具体敌人类EnemyElf
访问者模式实现存活角色计数ICharacterVisitor
+ abstract Visit Enemy(IEnemy enemy): void+ abstract VisitSoldier(ISoldier sodlier): void
TrainCaptiveCommand
- mEnemyType: EnemyType- mWeaponType: WeaponType- mPosition: Vector3- mLevel: int
能量系统
享元模式CharacterBaseAttr
# mName: string# mMaxHP: int# mMoveSpeed: float# mIconSprite: string# mPrafabName: string
assetsFactory
EnemyKilledObserverStageSystem
- mSubject: EnemtKilledSubject- StageSystem: mStageSystem
+ EnemyKilledObserverStageSystem(StageSystem stageSystem)+ SetSubject(IGameEventSubject subject): viud+ Update(): void
weapoFactory
ICharacterFactory
IAssetFactory
UI工具类UIToolkit
+ static GetCanvas(string name = \"Canvas\"): GameObjectfont color=\"#323232\
EnergySystem
EvenSystem
战士状态基类ISoldierState
ConsumeEnergy()RecycleEnergy()ShowMessage()
外观模式,为子系统提供一个统一调用接口同时也是中介者模式的中介者,负责子系统的管理以及交流使用单例模式GameFacade
...//实现CampOnClick与UI之间的解耦+ ShowCampInfo(ICamp camp): void
适配器模式实现战俘士兵SoldierCaptive
- mEnemy: IEnemy
+ SoldierCaptive(IEnemy enemy): void# PlayEffect(): void# PlaySound(): void
StageSystem
- mLevel = 1: int- mSpawnPositions: List<Vector3>- mFirstHandler: NormalStageHandler- mTargetPosition: Vector3- mNumOfEnemyKilled: int
+ Init(): void+ Update(): void- InitSpawnPosition: void- GetRandomPosition(): Vector3- InitStageChain():void+ GetNumOfKilledEnemies(): int+ EnterNextStage(): void+ GetTargetPosition(): Vector3
敌人状态类EnemyAttr
+font color=\"#323232\
事件系统
成就系统
观察者模式实现事件系统IGameEventSubject
- mObservers: List<IGameEventObserver>
+ RegisterObserver(IGameEventObserver observer): void+ RemoveObserver(IGameEventObserver observer): void+ Notify(): void
GamePlayState
游戏进行状态,其中有许多子系统使用外观模式提供子系统的一个统一调用接口
具体敌人类EnemyTroll
Notify()
GameMenuState
开始按钮
+ SoldierTransition: enum+ SoldierStateId: enum
士兵状态类SoldierAttr
EnemyChaseState
- mTargetPosition: Vector3
具体武器类WeaponRifle
关卡系统 StageSystem
SoldierChaseState
ResourceAssetFactory
+ const SoldierPath: string+ const EnemyPath: string+ const WeaponPath: string+ const EffectPath: string+ const AudioPath: string+ const SpritPath: string
- InstantiateGameObject(string path): GameObject- LoadAsset(string path): Object
享元模式IAttrFactory
+ abstract GetCharacterBaseAtatar(System.Type t): CharacterBaseAttr
ISoldier
# SoldierFSMSystem mFSMSystem
+ ISoldier(): Base()- MakeFSM(): void+ UpdateFSM(List<ICharacter> targets): void+ UnderAttack(int damage): void# abstract PlaySound(): void# abstract PlayEffect(): void+ RunVisitor(ICharacterVisitor chracterVisitor): void
具体武器类WeaponRocketLauncher
命令模式waitorICamp
# mGameObject: GameObject# mName: string# mIconSprite: string# mSoldierType: SoldierType# mRallyPosition: Vector3# mTrainTime: float# mTrainCommands: List<ITrainCommand>- mTrainTimerCountDown: float# mEnergyCostStrategy: IEnergyCostStrategy# mCampUpgradeEnergy: int# mWeaponUpgradeEnergy: int# mTrainEnergy
Unity工具类UnityToolkit
状态控制器StateController
private IsceneState sceneState;public void SetState()public void StateUpdate()
关卡系统
EnemyFactory
EventSystem
subject管理类EventSystem
状态策略接口IAttrStrategy
+ GetExtraHP(int Lv): int+ GetExtraSpeed(int Lv): float+ GetExtraCriticalRate(int Lv): float+ GetCriticalPoints(float criticalRate): int
- mIsGameOver: bool- static instance: GameFacade- mAchievementSystem: AchievementSystem- mCharacterSystem: CharacterSystem- mCampSystem: CampSystem- mEnergySystem: EnergySystem- mStageSystem: StageSystem- mUICampInfo: UICampInfo- mUIGamePause: UIGamePause- mUISoldierInfo: UISoldierInfo- mUIStateInfo: UIStateInfo
- GameFacade()+ Instance: instance+ IsGameOver(): bool+ Init(): void+ Update(): void+ End(): void+ GetEnemyTargetPosition: Vector3+ ShowCampInfo(ICamp camp): void+ AddSoldier(ISoldier soldier): void+ RemoveSoldier(ISoldier soldier): void+ AddEnemy(IEnemy enemy): void+ RemoveEnemy(IEnemy enemy): void+ ConsumeEnergy(int energy): bool+ ShowMessage(string msg): void+ RecycleEnergy(int energy): voidfont color=\"#323232\
EnemyKilledSubject
- mEnemyKilledNum: int
+ EnemyKilledNum(): int+ Notify(): void
资源管理工厂IAssetsFactory
+ LoadSoldier(string name): GameObject+ LoadEnemy(string name): GameObject+ LoadWeapon(string name): GameObject+ LoadEffect(string name): GameObject+ LoadAudioClip(string name): GameObject+ LoadSprite(string name): GameObject
工具类DestroyObject
- Start(): void- DestroyGameObject(): void
士兵角色基类ISoldier
+ ISoldier(): Base()- MakeFSM(): void+ UpdateFSM(List<ICharacter> targets): void+ UnderAttack(int damage): void# abstract PlaySound(): void# abstract PlayEffect(): void+ RunVisitor(ICharacterVisitor chracterVisitor): void
UICampInfo
- mCampIcon: Image - mCampName: Text - mCampLevel: Text - mWeaponLevel: Text - mUpgradeCampButton: Button - mUpgradeWeaponButton: Button - mTrainButton: Button - mCancelTrainButton; Button - mAliveCount: Text - mTrainCount: Text - mTrainTime: Text - mCamp: ICamp
+ Init(): void+ Update(): void+ ShowCampInfo(ICamp camp): void+ ShowTrainingInfo(): void- GetWeaponTypeString(WeaponType type): string+ OnTrainButtonClick(): void+ OnCancelButtonClick(): void+ OnWeaponUpgradeButtonClick(): void+ OnCampUpgradeButtonClick(): void
LocalAssetFactory
能量系统 EnergySystem
UISoldierInfo
...
+ Init(): void+ ShowCampInfo(ICamp camp): void
EnemyAttackState
兵营系统
具体武器类WeaponGun
游戏系统基类abstact IGameSystem
public virtual void Init()public virtual void Update()public virtual void End()
战士状态管理类 有限状态机EnemyFSMSystem
- mStates: List<IEnemyState>- mCurrentState: IEnemyState
+ currentState: IEnemyState+ AddState(IEnemyState): void+ AddState(params IEnemyState[] enemyStates): void+ DeleteState(EnemyStateId): void+ PerformTransition(EnemyTransition): void
SoldierKilledSubject
- mSoldierKilledNum: int
敌人基类IEnemy
# EnemyFSMSystem mFSMSystem
+ IEnemyr(): Base()- MakeFSM(): void+ UpdateFSM(List<ICharacter> targets): void+ UnderAttack(int damage): void+ abstract PlayEffect(): void+ Killed(): void+ RunVisitor(ICharacterVisitor chracterVisitor)
EnemyBuilder
UpdateEnergyBar()
策略模式能量消耗策略IEnergyCostStrategy
兵营系统 CampSystem
SoldierAttrStrategy
工厂管理类FactoryManager
- static mAssetsFactory: IAssetsFactory- static mSoldierFactory: ICharacterFactroy- static mEnemyFactory: ICharacterFactory- static mWeaponFactory: IWeaponFactory- static mAttrFactory: IAttrFactory
+ static assetsFactory: IAssetsFactory+ static soldierFactory: ICharacterFactory+ static enemyFactory: ICharacterFactory+ static weaponFactory: IWeaponFactory+ static attrFactory: IAttrFactory
AddEnemy()
角色系统访问者模式ObjectStructureCharacterSystem
- mEnemies: List<ICharacter>- mSoldiers: List<ICharacter>
+ AddEnemy(IEnemy enemy): void+ RemoveEnemy(IEnemy enemy): void+ AddSoldier(ISoldier soldier): void+ RemoveSoldier(ISoldier soldier): void- RemoveKilledCharacters(List<ICharacter> characters)+ Update(): void+ RunVisitor(ICharacterVisitor characterVisitor): void
敌人工厂EnemyFactory
SoldierCaptive
EnemyKilledObserverAchievement
- mAchievementSystem: AchievementSystem
CampSystem
+ Init(): void- InitCamp(SoldierType type): void- InitCamp(EnemyType enemyType): void+ Update(): void
RemoteAssetFactory
- cosnt MAX_ENERGY = 100;- mCurrentEnergy: float- mRecoverSpeed: float
+ Init(): void;+ Update(): void+ ConsumeEnergy(int energy): bool+ RecycleEnergy(int energy): void
建造者模式ICharacterBuilder
# mCharacter: ICharacter# mType: System.Type# mWeaponType: WeaponType# mSpawnPosition: Vector3# mLv: int# mPrefabName: string
职责链模式IStageHandler
# mLevel: int# mEnemyKilledForStage: int# mStageStystem: StageSystem# mNextHandler: IStageHandler
SoldierKilledObserverAchievement
+ SoldierKilledObserverAchievement(AchievementSystem achievementSystem)+ Update(): void+ SetSubject(IGameEventSubject subject): void
战士状态管理类 有限状态机SoldierFSMSystem
- mStates: List<ISoldierState>- mCurrentState: ISoldierState
+ currentState: ISoldierState+ AddState(ISoldierState): void+ AddState(params ISoldierState[] soldierStates): void+ DeleteState(SoldierStateId): void+ PerformTransition(SoldierTransition): void
事件系统 EventSystem
命令模式实现士兵训练ITrainCommand
+ abstract Execute(): void
观察者模式实现事件系统IGameEventObserver
+ abstract Update(): void+ abstract SetSubject(IGameEventSubject subject): void
点击显示兵营UICampOnClick
- mCamp: ICamp
+ SetCamp(ICamp camp): void- OnMouseUpAsButton(): viod
游戏暂停UIUIGamePause
UIGamePauseInfo
+ Init(): void
职责链模式NormalStageHandler
- mEnemyType: EnemyType- mWeaponType: WeaponType_ mEnemyCount: int- mSpawnPosition: Vector3- mSpawnInterval = 1: float- mSpawnTimer: float- mEnemySpawned: int
TrainSoldierCommand
- mSoldierType: SoldierType- mWeaponType: WeaponType- mPosition: Vector3- mLevel: int
收藏
0 条评论
下一页