Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

CGameAppUi Class Reference

Game UI. More...

#include <CGameAppUi.h>

Collaboration diagram for CGameAppUi:

Collaboration graph
[legend]
List of all members.

Public Methods

void ConstructL ()
 2nd phase construction. More...

 ~CGameAppUi ()
 destructor. More...


Private Methods

void HandleCommandL (TInt aCommand)
 handle a menu item or cba button press. More...

TBool NextLevelL ()
 Set iMapNo and iLevel to next level. More...

void LoadLevelL ()
 Load level defined by iMapNo and iLevel. More...

void DynInitMenuPaneL (TInt aMenuId, CEikMenuPane *aMenuPane)
 Update menu items from game state. More...

void HelpDialogL ()
 Tell the user about the game. More...

void AboutDialogL ()
 Tell the user who wrote the game. More...


Private Attributes

CGameAppViewiAppView
 Application view. More...

CGameStateiGameState
 Game state. More...

CGameFrameworkiGame
 Game Framework. More...

CGameFramework::TGameState iFrameworkState
 state returned by last call to CGameFramework::RunL. More...

TInt iLevel
 Currently playing level number. More...

TInt iMapNo
 Map number within level. More...


Detailed Description

Game UI.

This handles the non-playing side of the ui. It calls into CGameFramework to load levels and play levels.

Definition at line 40 of file CGameAppUi.h.


Constructor & Destructor Documentation

CGameAppUi::~CGameAppUi  
 

destructor.

Definition at line 53 of file CGameAppUi.cpp.

References iAppView, and iGame.

00053                         {       
00054   delete iAppView;
00055   delete iGame;
00056 }


Member Function Documentation

void CGameAppUi::ConstructL  
 

2nd phase construction.

Create the game state, appview and game framework

Definition at line 39 of file CGameAppUi.cpp.

References CGameAppView::ConstructL(), CGameFramework::EDied, CGameState::ENoGame, iAppView, iFrameworkState, iGame, iGameState, iLevel, iMapNo, CGameFramework::NewL(), and CGameState::SetState().

00039                             {    
00040   BaseConstructL();
00041   iGameState=((CGameDocument*)iDocument)->GameState();
00042   iAppView=new(ELeave) CGameAppView;
00043   iAppView->ConstructL(ClientRect(), iGameState);
00044   iGame= CGameFramework::NewL();
00045   iFrameworkState=CGameFramework::EDied;
00046   iLevel=0;
00047   iMapNo=0;
00048   iGameState->SetState(CGameState::ENoGame);
00049 }

void CGameAppUi::HandleCommandL TInt    aCommand [private]
 

handle a menu item or cba button press.

This will start/continue or cancel games by calling CGameFramework

Parameters:
aCommand  these will be defined in TGameMenuCommands

Definition at line 66 of file CGameAppUi.cpp.

References AboutDialogL(), CGameFramework::CancelL(), ECmdAbout, ECmdCancelGame, ECmdContinueGame, ECmdHelp, ECmdStartGame, CGameFramework::EDied, CGameFramework::ELevelCompleted, CGameState::ENextLevel, CGameState::ENoGame, CGameState::EPaused, CGameFramework::EPaused, CHighScores::GoodEnough(), HelpDialogL(), CGameState::HighScores(), iAppView, iFrameworkState, iGame, iGameState, iLevel, iMapNo, LoadLevelL(), NextLevelL(), CScoreDialog::RunDlgLD(), CGameFramework::RunL(), CGameFramework::Score(), CGameState::SetState(), CGameState::State(), and CGameFramework::TGameState.

00066                                              {
00067   switch (aCommand) {
00068     
00069   case ECmdStartGame:
00070   case ECmdContinueGame:
00071     {
00072       if(iGameState->State()==CGameState::ENoGame ||
00073          iGameState->State()==CGameState::ENextLevel) {
00074         LoadLevelL();
00075       }    
00076       
00077       // play a game
00078       // reset if we aren't starting the next level or have a paused game
00079       CGameFramework::TGameState state=
00080         iGame->RunL(iGameState->State()==CGameState::ENoGame ? ETrue : EFalse);
00081       
00082       switch(state) {
00083       case CGameFramework::EPaused:
00084         iGameState->SetState(CGameState::EPaused);
00085         break;
00086       case CGameFramework::ELevelCompleted:
00087         if(NextLevelL()==EFalse) {
00088           // congrats dialog
00089           CEikDialog* dialog = new (ELeave) CEikDialog();
00090           dialog->ExecuteLD(R_FINISHED_DIALOG);
00091           iGameState->SetState(CGameState::ENoGame);
00092         } else {
00093           iGameState->SetState(CGameState::ENextLevel);
00094         }
00095         break;
00096       case CGameFramework::EDied:
00097         iGameState->SetState(CGameState::ENoGame);
00098         break;      
00099       }
00100       
00101       // either died, or completed the game
00102       if(iGameState->State()==CGameState::ENoGame) {
00103         iMapNo=0;
00104         iLevel=0;
00105         iGameState->SetState(CGameState::ENoGame);
00106         if(iGameState->HighScores().GoodEnough(iGame->Score())) {
00107           CScoreDialog::RunDlgLD(iGameState->HighScores(),iGame->Score());
00108         }
00109       }
00110     }
00111     break;
00112   
00113   case ECmdCancelGame:
00114     switch(iGameState->State()) {
00115     case CGameState::ENoGame:
00116       break;
00117     case CGameState::EPaused:  // paused so we need to let the thread end
00118       iGame->CancelL();
00119       iMapNo=0;
00120       iLevel=0;
00121       iGameState->SetState(CGameState::ENoGame);
00122       iFrameworkState=CGameFramework::EDied;
00123       break;
00124     case CGameState::ENextLevel: // then set level to start
00125       iMapNo=0;
00126       iLevel=0;
00127       iGameState->SetState(CGameState::ENoGame);
00128       iFrameworkState=CGameFramework::EDied;
00129       iAppView->DrawNow();
00130       break;
00131     }
00132     
00133     break;
00134 
00135 
00136   case ECmdHelp:
00137     HelpDialogL();
00138     break;
00139 
00140   case ECmdAbout:
00141     AboutDialogL();
00142     break;
00143 
00144 
00145   case EEikCmdExit:
00146     Exit();
00147     break;
00148   }
00149 }

TBool CGameAppUi::NextLevelL   [private]
 

Set iMapNo and iLevel to next level.

Searches the directory the dll came from for level and map files. If there is another level/map file combination available it sets iMapNo and iLevel to that otherwise sets them to zero.

Returns:
ETrue if another level was found EFalse otherwise

Definition at line 198 of file CGameAppUi.cpp.

References iLevel, iMapNo, KLevelTypeUid, KMapTypeUid, and KUidExampleGame.

Referenced by HandleCommandL().

00198                              {
00199   TBool anotherLevel=EFalse;
00200   TParse parse;
00201   parse.Set(Application()->DllName(),NULL,NULL);
00202 
00203   RFs fs;
00204   User::LeaveIfError(fs.Connect());
00205   CleanupClosePushL(fs);
00206 
00207 
00208   // get a list of all the level files, ie files with first uid
00209   // KUidExampleGame and second uid KLevelTypeUid,
00210   TUidType levelType(KUidExampleGame,KLevelTypeUid);
00211   CDir* dir=NULL;
00212   User::LeaveIfError(fs.GetDir(parse.DriveAndPath(),levelType,ESortByUid | EAscending,dir));
00213   CleanupStack::PushL(dir);
00214 
00215   while(iLevel < dir->Count() && anotherLevel==EFalse) {
00216     TUid levelId=(*dir)[iLevel].MostDerivedUid();
00217     CDir* mapDir=NULL;
00218 
00219     // get a list of all map files for this level, ie with first uid
00220     // KUidExampleGame, second uid KMapTypeUid, and third ui levelId
00221     TUidType mapType(KUidExampleGame,KMapTypeUid,levelId);
00222     User::LeaveIfError(fs.GetDir(parse.DriveAndPath(),mapType,ESortByName | EAscending,mapDir));
00223 
00224     // if we have another map for this level use it,
00225     if(iMapNo+1<mapDir->Count()) {
00226       iMapNo++;
00227       anotherLevel=ETrue;
00228     } else {
00229       // else try the next level
00230       iMapNo=-1;
00231       iLevel++;
00232     }
00233     delete mapDir;
00234   }
00235 
00236   CleanupStack::PopAndDestroy(2,&fs); // dir
00237 
00238   if(anotherLevel==EFalse) {
00239     // back to first level
00240     iLevel=0;
00241     iMapNo=0;
00242   }
00243   return anotherLevel;
00244 }

void CGameAppUi::LoadLevelL   [private]
 

Load level defined by iMapNo and iLevel.

Searches the directory the dll came from for level and map files and tries to load the correct one.

Definition at line 253 of file CGameAppUi.cpp.

References CGameState::ENoGame, iGame, iGameState, iLevel, iMapNo, KLevelTypeUid, KMapTypeUid, KUidExampleGame, CGameFramework::LoadLevelL(), and CGameState::State().

Referenced by HandleCommandL().

00253                             {
00254   TParse parse;
00255   parse.Set(Application()->DllName(),NULL,NULL);
00256   RFs fs;
00257   User::LeaveIfError(fs.Connect());
00258   CleanupClosePushL(fs);
00259 
00260   // get a list of all the level files, ie files with first uid
00261   // KUidExampleGame and second uid KLevelTypeUid,
00262   TUidType levelType(KUidExampleGame,KLevelTypeUid);
00263   CDir* dir=NULL;
00264   User::LeaveIfError(fs.GetDir(parse.DriveAndPath(),levelType,ESortByUid | EAscending,dir));
00265   CleanupStack::PushL(dir);
00266 
00267   if(iLevel >= dir->Count()) {
00268     iLevel=0;
00269     User::Leave(KErrNotFound);
00270   }
00271 
00272   TUid levelId=(*dir)[iLevel].MostDerivedUid();
00273   CDir* mapDir=NULL;
00274   // get a list of all map files for this level, ie with first uid
00275   // KUidExampleGame, second uid KMapTypeUid, and third ui levelId
00276   TUidType mapType(KUidExampleGame,KMapTypeUid,levelId);
00277   User::LeaveIfError(fs.GetDir(parse.DriveAndPath(),mapType,ESortByName | EAscending,mapDir));
00278   CleanupStack::PushL(mapDir);
00279 
00280   if(iMapNo >= mapDir->Count()) {
00281     iMapNo=0;
00282     User::Leave(KErrNotFound);
00283   }
00284 
00285   // get the file entries for the level and map files
00286   const TEntry& levelEntry=(*dir)[iLevel];
00287   const TEntry& mapEntry=(*mapDir)[iMapNo];
00288 
00289   // get the full path and file names of the level and map files
00290   HBufC* levelFileName= HBufC::NewLC(levelEntry.iName.Length()+
00291                                      parse.DriveAndPath().Length());
00292   levelFileName->Des().Append(parse.DriveAndPath());
00293   levelFileName->Des().Append(levelEntry.iName);
00294 
00295   HBufC* mapFileName= HBufC::NewLC(mapEntry.iName.Length()+
00296                                    parse.DriveAndPath().Length());
00297   mapFileName->Des().Append(parse.DriveAndPath());
00298   mapFileName->Des().Append(mapEntry.iName);  
00299 
00300 
00301   // pass the filenames to CGameFramework::LoadLevelL()
00302   // reset the ship if it is a new game.
00303   if(iGameState->State()==CGameState::ENoGame)
00304     iGame->LoadLevelL(*levelFileName,*mapFileName,ETrue);
00305   else //iGameState->State()==CGameState::ENextLevel
00306     iGame->LoadLevelL(*levelFileName,*mapFileName,EFalse);
00307     
00308 
00309 
00310 
00311   CleanupStack::PopAndDestroy(5,&fs); // dir, mapDir,levelFileName,mapFileName
00312 }

void CGameAppUi::DynInitMenuPaneL TInt    aMenuId,
CEikMenuPane *    aMenuPane
[private]
 

Update menu items from game state.

This function is called before a menu is displayed, so it is used to dim out the functions not available depending on the game state

Parameters:
aMenuId  resource id of the menu to be displayed
aMenuPane  menu being displayed

Definition at line 161 of file CGameAppUi.cpp.

References ECmdCancelGame, ECmdContinueGame, ECmdStartGame, CGameState::ENextLevel, CGameState::ENoGame, CGameState::EPaused, iGameState, and CGameState::State().

00161                                                                       {
00162   if (aMenuId == R_GAME_GAME_MENU) {    
00163     switch(iGameState->State()) {
00164     case CGameState::ENoGame:
00165       aMenuPane->SetItemDimmed(ECmdCancelGame,ETrue);        
00166       aMenuPane->SetItemDimmed(ECmdContinueGame,ETrue);
00167       aMenuPane->SetItemDimmed(ECmdStartGame,EFalse);
00168       break;
00169     case CGameState::EPaused:
00170     case CGameState::ENextLevel:
00171       aMenuPane->SetItemDimmed(ECmdCancelGame,EFalse);        
00172       aMenuPane->SetItemDimmed(ECmdContinueGame,EFalse);
00173       aMenuPane->SetItemDimmed(ECmdStartGame,ETrue);
00174       break;
00175     }
00176   }
00177 }

void CGameAppUi::HelpDialogL   [private]
 

Tell the user about the game.

Definition at line 317 of file CGameAppUi.cpp.

Referenced by HandleCommandL().

00317                              {
00318   CEikonEnv* eikonEnv=CEikonEnv::Static();
00319   HBufC *title= eikonEnv->AllocReadResourceL(R_HELP_DIALOG_TITLE);
00320   CleanupStack::PushL(title);
00321   HBufC *body= eikonEnv->AllocReadResourceL(R_HELP_DIALOG_BODY);
00322   CleanupStack::PushL(body);
00323   CCknInfoDialog::RunDlgLD(*title,*body);
00324   CleanupStack::PopAndDestroy(2,title); // body
00325 }

void CGameAppUi::AboutDialogL   [private]
 

Tell the user who wrote the game.

Definition at line 330 of file CGameAppUi.cpp.

Referenced by HandleCommandL().

00330                               {
00331   CEikonEnv* eikonEnv=CEikonEnv::Static();
00332   HBufC *title= eikonEnv->AllocReadResourceL(R_ABOUT_DIALOG_TITLE);
00333   CleanupStack::PushL(title);
00334   HBufC *body= eikonEnv->AllocReadResourceL(R_ABOUT_DIALOG_BODY);
00335   CleanupStack::PushL(body);
00336   CCknInfoDialog::RunDlgLD(*title,*body);
00337   CleanupStack::PopAndDestroy(2,title); // body
00338 }


Member Data Documentation

CGameAppView* CGameAppUi::iAppView [private]
 

Application view.

Definition at line 53 of file CGameAppUi.h.

Referenced by ConstructL(), HandleCommandL(), and ~CGameAppUi().

CGameState* CGameAppUi::iGameState [private]
 

Game state.

Definition at line 55 of file CGameAppUi.h.

Referenced by ConstructL(), DynInitMenuPaneL(), HandleCommandL(), and LoadLevelL().

CGameFramework* CGameAppUi::iGame [private]
 

Game Framework.

Definition at line 56 of file CGameAppUi.h.

Referenced by ConstructL(), HandleCommandL(), LoadLevelL(), and ~CGameAppUi().

CGameFramework::TGameState CGameAppUi::iFrameworkState [private]
 

state returned by last call to CGameFramework::RunL.

Definition at line 57 of file CGameAppUi.h.

Referenced by ConstructL(), and HandleCommandL().

TInt CGameAppUi::iLevel [private]
 

Currently playing level number.

Definition at line 58 of file CGameAppUi.h.

Referenced by ConstructL(), HandleCommandL(), LoadLevelL(), and NextLevelL().

TInt CGameAppUi::iMapNo [private]
 

Map number within level.

Definition at line 59 of file CGameAppUi.h.

Referenced by ConstructL(), HandleCommandL(), LoadLevelL(), and NextLevelL().


The documentation for this class was generated from the following files:
Documentation for Game (Beta) version 1.44.