cGameStateManager
Methode :
public static void AddGroupe( cStateGroupe NewGroupe );
public static cStateGroupe GetGroupe( String GroupeId );
public static void GiveFocusToParent( ref cStateGroupe NewStateGroupe );
public static void GiveFocusToChildren( String ChildrenId );
public static void Update( ref cStateGroupe CurrentState );
شرح الدوال بالترتيب : cGameStateManager.AddGroupe(new cStateGroupe("Root", "Root"));
cGameStateManager.AddGroupe(new cStateGroupe("Logo", "Root"));
cGameStateManager.AddGroupe(new cStateGroupe("Game Intro", "Logo"));
cGameStateManager.AddGroupe(new cMainMenu("Main Menu", "Game Intro"));
بهذه الطريقة نكون قد سجلنا 3 حالات ( الحالة الاولى نعتبرها الحالة الاصلية للعبة، و ليس لها دور عدا الخروج من اللعبة): public bool HaveFocus
public StringId
public virtual void Update( GameTime gameTime )
public virtual void OnInit()
public virtual bool IsSelecte()
public virtual bool OnSelecte()
public virtual void OnShutDown()
public virtual void OnEnter()
public virtual bool OnExit()
public virtual void OnDraw( GameTime gameTime )
العناصر الخاصة بهذا الصنف :public Stack< cAbstractGameStates> StateStack; //1
public Dictionary<string,cabstractgamestates> StateMap;//2
public int StateIndexer;//2
public cStateGroupe Parent;//3
public string ParentId;//4
public String ChildrenId ;//5
public cAbstractGameStates GetState( String StateId )//6
public void PushState( String NewStateId )//7
public void PopState( String NewStateId )//8
public void AddState( cAbstractGameStates NewGameState )//9
public bool TheStateIsMine( String StateId )//10
public bool TheGroupIsMine( String GroupeId )//11
public void ChangeState( cAbstractGameStates NewGameState )//12
1- مكدس يحتوي على الحالات التي تعمل( احتاج الى المساعدة في هذه النقطة لمن لديه فكرة افضل). // creat the Main Menu Groupe
cGameStateManager.AddGroupe(new cMainMenu("Main Menu", "Game Intro"));
// creat the Main Menu States
cGameStateManager.GetGroupe("Main Menu").AddState(new cPlayState("New Game", "Main Menu"));
cGameStateManager.GetGroupe("Main Menu").AddState(new cPlayState("Load Game", "Main Menu"));
cGameStateManager.AddGroupe(new cStateGroupe("Game Option", "Main Menu"));
cGameStateManager.GetGroupe("Main Menu").AddState(new cExitState("Exit", "Main Menu"));
cGameStateManager.GetGroupe("Game Option").AddState(new cPlayState("Sons", "Game Option"));
cGameStateManager.GetGroupe("Game Option").AddState(new cPlayState("Commande", "Game Option"));
cGameStateManager.GetGroupe("Game Option").AddState(new cPlayState("Graphisme", "Game Option"));
cGameStateManager.GetGroupe("Game Option").AddState(new cPlayState("Cheat", "Game Option"));
سنتحصل على القائمة التالية :Main Menu
New Game : when select StartThe Game
Load Game : When Select Load The Game
Option : When Select Go To Sub Menu
SubMenu Option :
Sons
Commande
Graphisme
Cheat
Exit Game : When Select Exit The Game
كل من هذه الحالات يمكن ان يعرف بصنف خاص به مادام الجميع ينحدر من نفس الصنف cAbstractGameStates
// creat the Main Menu Groupe
cGameStateManager.AddGroupe(new cStateGroupe("Main Menu", "Game Intro"));
// creat the Main Menu States
cGameStateManager.GetGroupe("Main Menu").AddState(new cPlayState("New Game", "Main Menu"));
cGameStateManager.GetGroupe("Main Menu").AddState(new cPlayState("Load Game", "Main Menu"));
cGameStateManager.AddGroupe(new cStateGroupe("Game Option", "Main Menu"));
cGameStateManager.GetGroupe("Main Menu").AddState(new cExitState("Exit", "Main Menu"));
لاحظوا السطر الاول : نوع الحالة المرسلة : cStateGroupe // creat the Main Menu Groupe
cGameStateManager.AddGroupe(new cMainMenu("Main Menu", "Game Intro"));
// creat the Main Menu States
cGameStateManager.GetGroupe("Main Menu").AddState(new cPlayState("New Game", "Main Menu"));
cGameStateManager.GetGroupe("Main Menu").AddState(new cPlayState("Load Game", "Main Menu"));
cGameStateManager.AddGroupe(new cStateGroupe("Game Option", "Main Menu"));
cGameStateManager.GetGroupe("Main Menu").AddState(new cExitState("Exit", "Main Menu"));
السطر الاول تغير و ذلك لننشئ صنف : cMainMenu using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace XNATesting
{
public class Game1 : Microsoft.Xna.Framework.Game
{
public static Game1 TheGame{
get { return game; }
}
private static Game1 game;
public GraphicsDeviceManager graphics;
public SpriteBatch spriteBatch;
public SpriteFont font,smallFont,largeFont;
cStateGroupe firstgroupe;
.....
.....
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
audio = new AudioLibrary();
audio.LoadContent(Content);
Services.AddService(typeof(AudioLibrary), audio);
...
...
/////////////////////////////////////////////////////////////////////////////////
// creat the root parent
cGameStateManager.AddGroupe(new cStateGroupe("Root", "Root"));
cGameStateManager.AddGroupe(new cStateGroupe("Logo", "Root"));
cGameStateManager.AddGroupe(new cStateGroupe("Game Intro", "Logo"));
cGameStateManager.AddGroupe(new cStateGroupe("Menu 01", "Game Intro"));
cGameStateManager.AddGroupe(new cStateGroupe("Menu 02", "Game Intro"));
// creat the Main Menu Groupe
cGameStateManager.AddGroupe(new cMainMenu("Main Menu", "Game Intro"));
// creat the Main Menu States
cGameStateManager.GetGroupe("Main Menu").AddState(new cPlayState("New Game", "Main Menu"));
cGameStateManager.GetGroupe("Main Menu").AddState(new cPlayState("Load Game", "Main Menu"));
cGameStateManager.AddGroupe(new cStateGroupe("Game Option", "Main Menu"));
cGameStateManager.GetGroupe("Main Menu").AddState(new cExitState("Exit", "Main Menu"));
cGameStateManager.GetGroupe("Game Option").AddState(new cPlayState("Sons", "Game Option"));
cGameStateManager.GetGroupe("Game Option").AddState(new cPlayState("Commande", "Game Option"));
cGameStateManager.GetGroupe("Game Option").AddState(new cPlayState("Graphisme", "Game Option"));
cGameStateManager.GetGroupe("Game Option").AddState(new cPlayState("Cheat", "Game Option"));
cGameStateManager.GetGroupe("Game Intro").AddState(cGameStateManager.GetGroupe("Main Menu"));
cGameStateManager.GetGroupe("Game Intro").AddState(cGameStateManager.GetGroupe("Game Intro"));
firstgroupe = cGameStateManager.GetGroupe("Logo");
firstgroupe.HaveFocus = true;
firstgroupe.OnEnter();
////////////////////////////////////////////////////////////////////////////////////
}
protected override void Update( GameTime gameTime )
{
/////////////////////////////////////////
cInput.Input.UpdateInput();
/////////////////////////////////////////
// Allows the game to exit
if ( GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed )
this.Exit();
// TODO: Add your update logic here
firstgroupe.Update(gameTime);
cGameStateManager.Update(ref firstgroupe);
base.Update(gameTime);
}
protected override void Draw( GameTime gameTime )
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
////////////////////////////////////////////
firstgroupe.OnDraw(gameTime);
///////////////////////////////////////////
spriteBatch.End();
base.Draw(gameTime);
}
}
}
في 27/شوال/1431 09:51 ص، قال انس بهدوء وتؤدة:
لو سمحت لي استاذ وسام وحتى تسهل علي المهمة، كيف برايك يمكن الاستفادة من هذا النظام في حالة : حالات اللاعب او الوحوش ؟class cBehavior{
public virtuel bool OnStop();
public virtuel bool OnAction();
public virtuel bool ChangeBehavior( String BehaviorID );
public virtuel void RestBehavior();
public virtuel void AddBehavior();
public virtuel void GetBehavior();
}
class cPlayerBehavior : cBehavior{
// implemente the virtuel methode
// and add methode if necessery
}
class cPlayer{
cPlayerBehavior MyBehavior;
///
}
في 27/شوال/1431 11:02 ص، غمغم انس باستغراب قائلاً:
هل هذا التصميم سليم ؟