examples/sfexamples/RockPaperScissorsGameSourceCode_S60/RPS/inc/rpsGameScreens.h

00001 /*
00002 Copyright (c) 2002-2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 #ifndef RPSGAMESCREENS_
00031 #define RPSGAMESCREENS_
00032 
00033 #include "rpsMenuOptions.h"
00034 #include "rpsPlayTimer.h"
00035 #include "roshambo.h"
00036 
00037 const TInt KMaxRpsTextElement = 30;
00038 const TInt KRPSScreensHAlignment = 15;
00039 
00040 extern TInt gScreenWidth;
00041 extern TInt gScreenHeight;
00042 
00043 class CRpsGameEngine;
00044 class CBluetoothManager;
00045 class CGameScreen;
00046 class CWsBitmap;
00047                 
00048 class TGameData
00049         {
00050 public:
00054         TInt iRpsError;
00055         };
00056 
00057 /*
00058 ============================================================================
00059 The screens manager. Manages the RPS's screen to display to the player
00060 ============================================================================
00061 */      
00062 class CGameScreenManager : public CBase
00063         {
00064 public:
00065         enum TGameState
00066                 {
00067                 ESplashScreen,          //Splash screen, displayed as game starts
00068                 EMainScreen,            //Player select one/two players or view the about screen
00069                 EPausedScreen,          //When the app loses the focus the pause screen is displayed
00070                 EPlayScreen,            //Display the Roshambo game
00071                 EWaitOpponentScreen,//Screen presented to th player for waiting the opponent move
00072                 EResultScreen,          //Display the result
00073                 EControlScreen,         //For choosing either master or slave mode
00074                 ENotifierScreen,        //Displays a notifier
00075                 EConnectingScreen,  //Screen presented to the Master during connection to the Slave
00076                 EStartScreen,           //Screen presented to the Master with the option to kick off the game
00077                 EWaitStartScreen,       //Screen presented to the Slave with a msg to wait for the Master to kick off the game
00078                 EWaitConnScreen,        //Screen presented to the Slave with a waiting connection msg
00079                 EErrorScreen,           //Display any errors to the player      
00080                 EAboutScreen,           //About screen
00081                 EGameScreensTotal       //Marks the end of the screen array
00082                 };
00083         enum TPlayMode
00084                 {
00085                 ESinglePlayer,
00086                 ETwoPlayerShortlink,
00087                 };
00088 public:
00095         static CGameScreenManager* NewL(CRpsGameEngine& aEngine);
00096         
00100         ~CGameScreenManager();
00101 public:
00106         void SetGameState(TGameState aNewGameState);    
00107 public:
00112         inline void SetPlayMode(TPlayMode aPlayMode) {iPlayMode = aPlayMode;};
00113 
00118         inline TGameState GameState() const {return (iGameState);};
00119 
00124         inline TPlayMode PlayMode() const {return (iPlayMode);};
00125 
00129         inline CGameScreen* GameScreen() {return (iGameScreens[iGameState]);};
00130 
00134         inline TRoshambo& Roshambo() {return (iRoshambo);};
00135 
00139         inline CRpsGameEngine& GameEngine() {return iEngine;};
00140         
00144         inline CBluetoothManager& BluetoothManager() {return (*iBTManager);};
00145         
00149         inline TGameData& GameData() {return iGameData;};
00150         
00151 private:
00156         void ConstructL();
00157         
00163         CGameScreenManager(CRpsGameEngine& aEngine);
00164 private:
00168         TGameState iGameState;
00169 
00173         TPlayMode iPlayMode;
00174 
00178         CRpsGameEngine& iEngine;
00179 
00183         CGameScreen* iGameScreens[EGameScreensTotal];
00184         
00188         TRoshambo iRoshambo;
00189         
00193         TGameData iGameData;
00194         
00198         CBluetoothManager* iBTManager;
00199         };
00200         
00201 /*
00202 ============================================================================
00203 This is displayed as a line of text on the screen
00204 ============================================================================
00205 */      
00206 class TGameScreenItem
00207         {
00208 public:
00209         TGameScreenItem(RPS::TMenuOption aOption, const TDesC& aText);  
00210         TDblQueLink iDlink; // Double-linked list link  
00211         RPS::TMenuOption iOption;
00212         TBool iHighlighted; // Indicates whether item is highlighted
00213         TInt iX; // X position on screen
00214         TInt iY; // Y position on screen
00215         TBufC<KMaxRpsTextElement> iText;
00216         };
00217         
00218 
00219         /*
00220 ============================================================================
00221 The screen interface class - abstract C class
00222 ============================================================================
00223 */      
00224 class CGameScreen : public CBase
00225                 {
00226         public:
00227                 // Draws the screen
00228                 virtual void DrawGameScreen() =0; 
00229                 // Handles user input and updates game state
00230                 virtual void ProcessInput(TUint& /*aKeyState*/) {}; 
00231                 // Called prior to each screen activation (when switching to it from another state)
00232                 virtual void PreActivate() {}; 
00233                 //Called prior to deactivation (when switching to another game state)
00234                 virtual void DeActivate() {}; 
00235                 virtual ~CGameScreen();
00236         protected:
00237                 CGameScreen(CGameScreenManager& iGameScreenMgr);
00238         protected:
00239                 CGameScreenManager& iGameScreenMgr;
00240                 };      
00241         
00242 /*
00243 ============================================================================
00244 A generic menu screen
00245 ============================================================================
00246 */      
00247 class CMenuScreen : public CGameScreen
00248         {
00249 public:
00250         virtual ~CMenuScreen();
00251 public: // From CGameScreen
00252         virtual void DrawGameScreen();
00253         virtual void ProcessInput(TUint& aKeyState);
00254 protected:      
00255         CMenuScreen(CGameScreenManager& iGameScreenMgr);
00256         virtual void DoProcessInput(RPS::TMenuOption aSelected) =0;
00257 protected:
00258         TDblQue<TGameScreenItem> iItems; // Linked list
00259         TDblQueIter<TGameScreenItem> iIterator;
00260         };
00261         
00262 
00263 /*
00264 ============================================================================
00265 The main menu screen
00266 ============================================================================
00267 */      
00268 class CMainScreen : public CMenuScreen
00269         {
00270 public:
00277         static CGameScreen* NewL(CGameScreenManager& aScreenMgr);
00278 protected:      
00279         virtual void DoProcessInput(RPS::TMenuOption aSelected);
00280 private:
00281         void ConstructL();
00282         CMainScreen(CGameScreenManager& aScreenMgr);
00283         };
00284         
00285 
00286 /*
00287 ============================================================================
00288 Play menu screen
00289 ============================================================================
00290 */      
00291 class CPlayScreen : public CMenuScreen
00292         {
00293 public:
00300         static CGameScreen* NewL(CGameScreenManager& aScreenMgr);
00301         ~CPlayScreen();
00302         void PlayTimeout();
00303 protected:      
00304         virtual void DoProcessInput(RPS::TMenuOption aSelected);
00305         virtual void PreActivate();
00306         virtual void DeActivate();
00307 private:
00308         void ConstructL();
00309         CPlayScreen(CGameScreenManager& aScreenMgr);
00310 private:
00311         CPlayTimer* iPlayTimer;
00312         };      
00313         
00314 /*
00315 ============================================================================
00316 About screen
00317 ============================================================================
00318 */      
00319 class CAboutScreen : public CMenuScreen
00320         {
00321 public:
00328         static CGameScreen* NewL(CGameScreenManager& aScreenMgr);
00329 protected:      // From CMenuScreen
00330         virtual void DrawGameScreen();
00331         virtual void DoProcessInput(RPS::TMenuOption aSelected);
00332 private:
00333         void ConstructL();
00334         CAboutScreen(CGameScreenManager& aScreenMgr);
00335         };
00336         
00337 /*
00338 ============================================================================
00339 Pause screen
00340 ============================================================================
00341 */      
00342 class CPauseScreen : public CGameScreen
00343         {
00344 public:
00351         static CGameScreen* NewL(CGameScreenManager& aScreenMgr);
00352         ~CPauseScreen();
00353 public: // From CGameScreen
00354         virtual void DrawGameScreen();
00355         virtual void ProcessInput(TUint& aKeyState);
00356         virtual void DeActivate(); 
00357 private:
00358         void ConstructL();
00359         CPauseScreen(CGameScreenManager& aScreenMgr);
00360 private:
00361         CWsBitmap* iBmp;
00362         TPoint iPos;
00363         };
00364 /*      
00365 ============================================================================
00366 Splash screen
00367 ============================================================================
00368 */      
00369 class CSplashScreen : public CGameScreen
00370         {
00371 public:
00378         static CGameScreen* NewL(CGameScreenManager& aScreenMgr);
00379         ~CSplashScreen();
00380 public: // From CGameScreen
00381         virtual void DrawGameScreen(); 
00382 private:
00383         void ConstructL();
00384         CSplashScreen(CGameScreenManager& aScreenMgr);
00385 private:
00386         TInt iSplashCounter;
00387         CWsBitmap* iBmp;
00388         TPoint iPos;
00389         };      
00390         
00391 /*
00392 ============================================================================
00393 Result screen
00394 ============================================================================
00395 */      
00396 class CResultScreen : public CGameScreen
00397         {
00398 public:
00405         static CResultScreen* NewL(CGameScreenManager& aScreenMgr);
00406 public: // From CGameScreen
00407         virtual void DrawGameScreen();
00408         virtual void ProcessInput(TUint& aKeyState);
00409 private:
00410         void ConstructL();
00411         CResultScreen(CGameScreenManager& aScreenMgr);
00412         };              
00413 
00414 
00415 /*
00416 ============================================================================
00417 Control menu screen. User chooses to be either a Master (the player controls the game) or 
00418 a Slave (the player waits for other player connection)  
00419 ============================================================================
00420 */      
00421 class CControlScreen : public CMenuScreen
00422         {
00423 public:
00430         static CGameScreen* NewL(CGameScreenManager& aScreenMgr);
00431 protected:      
00432         virtual void DoProcessInput(RPS::TMenuOption aSelected);
00433 private:
00434         void ConstructL();
00435         CControlScreen(CGameScreenManager& aScreenMgr);
00436         };
00437 
00438 /*
00439 ============================================================================
00440 Start the game (Master)
00441 ============================================================================
00442 */      
00443 class CStartScreen : public CMenuScreen
00444         {
00445 public:
00452         static CGameScreen* NewL(CGameScreenManager& aScreenMgr);
00453 protected:      
00454         virtual void DoProcessInput(RPS::TMenuOption aSelected);
00455 private:
00456         void ConstructL();
00457         CStartScreen(CGameScreenManager& aScreenMgr);
00458         };
00459 
00460 /*
00461 ============================================================================
00462 Waiting to start the game (Slave mode)
00463 ============================================================================
00464 */      
00465 class CWaitStartScreen : public CGameScreen
00466         {
00467 public:
00474         static CWaitStartScreen* NewL(CGameScreenManager& aScreenMgr);
00475 public: // From CGameScreen
00476         virtual void DrawGameScreen();
00477 private:
00478         void ConstructL();
00479         CWaitStartScreen(CGameScreenManager& aScreenMgr);
00480         };              
00481 
00482 /*
00483 ============================================================================
00484 Waiting for a connection (Slave mode)
00485 ============================================================================
00486 */      
00487 class CWaitConnScreen : public CGameScreen
00488         {
00489 public:
00496         static CWaitConnScreen* NewL(CGameScreenManager& aScreenMgr);
00497 public: // From CGameScreen
00498         virtual void DrawGameScreen();
00499 private:
00500         void ConstructL();
00501         CWaitConnScreen(CGameScreenManager& aScreenMgr);
00502         };              
00503 
00504 /*
00505 ============================================================================
00506 Display a error message to the player
00507 ============================================================================
00508 */      
00509 class CErrorScreen : public CGameScreen
00510         {
00511 public:
00518         static CErrorScreen* NewL(CGameScreenManager& aScreenMgr);
00519 public: // From CGameScreen
00520         virtual void DrawGameScreen();
00521         virtual void ProcessInput(TUint& aKeyState);
00522         virtual void DeActivate();
00523 private:
00524         void ConstructL();
00525         CErrorScreen(CGameScreenManager& aScreenMgr);
00526         };              
00527 
00528 /*
00529 ============================================================================
00530 Display connecting message to the player (Master mode)
00531 ============================================================================
00532 */      
00533 class CConnectingScreen : public CGameScreen
00534         {
00535 public:
00542         static CConnectingScreen* NewL(CGameScreenManager& aScreenMgr);
00543 public: // From CGameScreen
00544         virtual void DrawGameScreen();
00545         virtual void ProcessInput(TUint& aKeyState);
00546 private:
00547         void ConstructL();
00548         CConnectingScreen(CGameScreenManager& aScreenMgr);
00549         };              
00550         
00551 /*
00552 ============================================================================
00553 Waiting for the opponent move
00554 ============================================================================
00555 */      
00556 class CWaitOpponentScreen : public CGameScreen
00557         {
00558 public:
00565         static CWaitOpponentScreen* NewL(CGameScreenManager& aScreenMgr);
00566 public: // From CGameScreen
00567         virtual void DrawGameScreen();
00568 private:
00569         void ConstructL();
00570         CWaitOpponentScreen(CGameScreenManager& aScreenMgr);
00571         };      
00572         
00573         
00574 class CNotifierScreen : public CGameScreen
00575         {
00576 public:
00577         static CNotifierScreen* NewL(CGameScreenManager& aGameScreenMgr);
00578         ~CNotifierScreen();
00579 public: // From CGameScreen
00580         virtual void DrawGameScreen();
00581 private:
00582         CNotifierScreen(CGameScreenManager& aGameScreenMgr);    
00583         };
00584 
00585 #endif /*RPSGAMESCREENS_*/

Generated by  doxygen 1.6.2