examples/SFExamples/RockPaperScissorsGameSourceCode_S60/RPS/src/rpsGameScreens.cpp

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 // INCLUDE FILES
00031 #include <eikenv.h>
00032 #include <coemain.h>
00033 #include <rps_0xA00054BC.mbg>
00034 #include "common.hrh" 
00035 #include "rps.hrh"
00036 #include "rpsGameScreens.h" 
00037 #include "rpsPlayTimer.h"
00038 #include "rpsgameengine.h"
00039 #include "bluetoothmanager.h"
00040 
00041 _LIT(KRPSVersionString, "1.0");
00042 
00043 _LIT(KRock, "Rock");
00044 _LIT(KPaper, "Paper");
00045 _LIT(KScissors, "Scissors");
00046 
00047 //----------------------------------------------------
00048 CGameScreenManager* CGameScreenManager::NewL(CRpsGameEngine& aEngine)
00049         {
00050         CGameScreenManager* me = new (ELeave) CGameScreenManager(aEngine);
00051         CleanupStack::PushL(me);
00052         me->ConstructL();
00053         CleanupStack::Pop(me);
00054         return (me);
00055         }
00056 CGameScreen::CGameScreen(CGameScreenManager& aGameScreenMgr)
00057 :       iGameScreenMgr(aGameScreenMgr)
00058         {}
00059 
00060 CGameScreen::~CGameScreen()
00061 {}
00062 
00063 //----------------------------------------------------
00064 
00065 CGameScreenManager::CGameScreenManager(CRpsGameEngine& aEngine)
00066 : iGameState(ESplashScreen), iPlayMode(ESinglePlayer), iEngine(aEngine)
00067 {}
00068 
00069 void CGameScreenManager::ConstructL()
00070         {
00071         iGameScreens[ESplashScreen] = CSplashScreen::NewL(*this);       
00072         iGameScreens[EMainScreen] = CMainScreen::NewL(*this);   
00073         iGameScreens[EPausedScreen] = CPauseScreen::NewL(*this);
00074         iGameScreens[EPlayScreen] = CPlayScreen::NewL(*this);
00075         iGameScreens[EWaitOpponentScreen] = CWaitOpponentScreen::NewL(*this);
00076         iGameScreens[EResultScreen] = CResultScreen::NewL(*this);
00077         iGameScreens[EControlScreen] = CControlScreen::NewL(*this);
00078         iGameScreens[ENotifierScreen] = CNotifierScreen::NewL(*this);
00079         iGameScreens[EConnectingScreen] = CConnectingScreen::NewL(*this);
00080         iGameScreens[EStartScreen] = CStartScreen::NewL(*this);
00081         iGameScreens[EWaitStartScreen] = CWaitStartScreen::NewL(*this);
00082         iGameScreens[EWaitConnScreen] = CWaitConnScreen::NewL(*this);
00083         iGameScreens[EErrorScreen] = CErrorScreen::NewL(*this); 
00084         iGameScreens[EAboutScreen] = CAboutScreen::NewL(*this);
00085         
00086         // Bluetooth manager
00087         iBTManager = CBluetoothManager::NewL(*this);
00088         }
00089 
00090 CGameScreenManager::~CGameScreenManager()
00091         {
00092         for (TInt index = 0; index < EGameScreensTotal;  index++)
00093                 delete iGameScreens[index];
00094         
00095         delete iBTManager;
00096         }
00097 
00098 void CGameScreenManager::SetGameState(TGameState aNewGameState)
00099         {
00100         CGameScreen* currentScreen = iGameScreens[iGameState];
00101         ASSERT(currentScreen);
00102         currentScreen->DeActivate(); // Processing required before screen is deactivated
00103         
00104         iGameState = aNewGameState;
00105         CGameScreen* newScreen = iGameScreens[iGameState];
00106         ASSERT(newScreen);
00107         newScreen->PreActivate(); // Processing required before screen is displayed
00108         }
00109 // -------------------------------------------------------------------------------
00110 
00111 TGameScreenItem::TGameScreenItem(RPS::TMenuOption aOption, const TDesC& aText)  
00112 : iOption(aOption), iHighlighted(EFalse), iX(0), iY(0), iText(aText)
00113 {}
00114 
00115 // -------------------------------------------------------------------------------
00116 
00117 CMenuScreen::CMenuScreen(CGameScreenManager& aGameScreenMgr)
00118 :       CGameScreen(aGameScreenMgr),
00119         iItems(_FOFF(TGameScreenItem, iDlink)),
00120         iIterator(iItems)
00121                 {
00122                 }       
00123 
00124 CMenuScreen::~CMenuScreen()
00125         {
00126         TGameScreenItem* anyItem;
00127         iIterator.SetToFirst();
00128         while ((anyItem = iIterator++) != NULL)
00129             {
00130             anyItem->iDlink.Deque();
00131             delete anyItem;
00132             };
00133         }
00134         
00135 void CMenuScreen::DrawGameScreen()
00136         {
00137         CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00138         gc.SetPenStyle(CGraphicsContext::ENullPen);     
00139         gc.UseFont(CCoeEnv::Static()->NormalFont());
00140         gc.SetPenColor(KRgbGray);
00141         
00142         TGameScreenItem* item=NULL;
00143         iIterator.SetToFirst();
00144         while((item = iIterator++) != NULL)
00145         {
00146         if (item->iHighlighted)
00147                 {
00148                 gc.SetPenColor(KRgbRed);
00149                 gc.DrawText(item->iText, TPoint(item->iX, item->iY));
00150                 gc.SetPenColor(KRgbGray);
00151                 }
00152         else    
00153                 gc.DrawText(item->iText, TPoint(item->iX, item->iY));        
00154         };     
00155         }
00156 
00157 
00158 void CMenuScreen::ProcessInput(TUint& aKeyState)
00159         {
00160         iIterator.SetToFirst();
00161         TGameScreenItem* item=iIterator;
00162         
00163         while(item!= NULL)
00164         {
00165         if (!item->iHighlighted)
00166                 {
00167                 iIterator++; // No pre-increment operator is available
00168                 item = iIterator;
00169                 }
00170         else // Found the currently highlighted item
00171                 { 
00172                 if (aKeyState & KControllerUp)
00173                         {// The up key was pressed
00174                         if (iItems.IsFirst(iIterator)) // At the first in the list 
00175                                 iIterator.SetToLast(); // Roll around
00176                         else
00177                                 iIterator--; // No pre-decrement operator is available
00178                         
00179                         TGameScreenItem* previous = iIterator;
00180                         ASSERT(previous);
00181                         if(previous != item)//only one item in the double list?
00182                                 {                                       
00183                                 previous->iHighlighted = ETrue;
00184                                 item->iHighlighted = EFalse;
00185                                 }
00186                                 
00187                         aKeyState &= ~KControllerUp; // Clear the input now it's been handled
00188                         }
00189                 else if (aKeyState & KControllerDown)
00190                         {// The down key was pressed
00191                         if (iItems.IsLast(iIterator)) // At the end of the list
00192                                 iIterator.SetToFirst(); // Roll around to the first
00193                         else
00194                                 iIterator++; // No preincrement operator is available
00195                         
00196                         TGameScreenItem* next = iIterator;
00197                         ASSERT(next);
00198                         if(next != item)//only one item in the double list?
00199                                 {
00200                                 next->iHighlighted = ETrue;
00201                                 item->iHighlighted = EFalse;
00202                                 }
00203                                         
00204                         aKeyState &= ~KControllerDown;  // Clear the input now it's been handled
00205                         } 
00206                 else if (aKeyState & KControllerCentre)
00207                         {
00208                         DoProcessInput(item->iOption);
00209                         aKeyState &= ~KControllerCentre;
00210                         }               
00211                 break; // Input has been handled or is not relevant to this screen
00212                 }
00213         }       
00214         }
00215 
00216 // ---------------------------------
00217 
00218 CGameScreen* CMainScreen::NewL(CGameScreenManager& aScreenMgr)
00219         {
00220         CMainScreen* me = new (ELeave) CMainScreen(aScreenMgr);
00221         CleanupStack::PushL(me);
00222         me->ConstructL();
00223         CleanupStack::Pop(me);
00224         return (static_cast<CGameScreen*>(me));
00225         }
00226 
00227 CMainScreen::CMainScreen(CGameScreenManager& aScreenMgr)
00228 : CMenuScreen(aScreenMgr)
00229 {}
00230 
00231 void CMainScreen::ConstructL()
00232         {
00233         _LIT(KSingle, "Single Player");
00234         _LIT(KTwo, "Two Players");
00235         _LIT(KAbout, "About");
00236         
00237         TGameScreenItem* item = new (ELeave) TGameScreenItem(RPS::ESinglePlayer, KSingle);
00238         item->iX = KRPSScreensHAlignment;
00239         item->iY = gScreenHeight/3;
00240         item->iHighlighted = ETrue;
00241         iItems.AddFirst(*item);
00242         iIterator.SetToFirst();
00243         
00244         item = new (ELeave) TGameScreenItem(RPS::ETwoPlayers, KTwo);
00245         item->iX = KRPSScreensHAlignment;
00246         item->iY = gScreenHeight/2;
00247         TGameScreenItem* current = iIterator;
00248         ASSERT(current);
00249         item->iDlink.Enque(&current->iDlink);
00250         iIterator.Set(*item);
00251 
00252         item = new (ELeave) TGameScreenItem(RPS::EAbout, KAbout);
00253         item->iX = KRPSScreensHAlignment;
00254         item->iY = 2*gScreenHeight/3;
00255         current = iIterator;
00256         ASSERT(current);
00257         item->iDlink.Enque(&current->iDlink);
00258         }
00259 
00260 // Handles item selection according to menu
00261 // Here, the next appropriate screen is displayed
00262 void CMainScreen::DoProcessInput(RPS::TMenuOption aSelected)
00263         {
00264         switch (aSelected)
00265                 {
00266                 case(RPS::ESinglePlayer):
00267                         iGameScreenMgr.SetPlayMode(CGameScreenManager::ESinglePlayer);
00268                         iGameScreenMgr.SetGameState(CGameScreenManager::EPlayScreen);
00269                         break;
00270                 case (RPS::ETwoPlayers):
00271                         iGameScreenMgr.SetPlayMode(CGameScreenManager::ETwoPlayerShortlink); 
00272                         iGameScreenMgr.SetGameState(CGameScreenManager::EControlScreen);
00273                         break;
00274                 case (RPS::EAbout):
00275                         iGameScreenMgr.SetGameState(CGameScreenManager::EAboutScreen);
00276                         break;
00277                 default:
00278                         ASSERT(EFalse);
00279                 }
00280         }
00281 
00282 // ------------------------------------------------
00283 //Play menu
00284 
00285 CGameScreen* CPlayScreen::NewL(CGameScreenManager& aScreenMgr)
00286         {
00287         CPlayScreen* me = new (ELeave) CPlayScreen(aScreenMgr);
00288         CleanupStack::PushL(me);
00289         me->ConstructL();
00290         CleanupStack::Pop(me);
00291         return (static_cast<CGameScreen*>(me));
00292         }
00293 
00294 CPlayScreen::CPlayScreen(CGameScreenManager& aScreenMgr)
00295 : CMenuScreen(aScreenMgr)
00296 {}
00297 
00298 CPlayScreen::~CPlayScreen()
00299         {
00300         delete iPlayTimer;
00301         }
00302 
00303 void CPlayScreen::ConstructL()
00304         {
00305         iPlayTimer = CPlayTimer::NewL(10000000, *this); // 10 second timeout
00306         
00307         TGameScreenItem* item = new (ELeave) TGameScreenItem(RPS::ERock, KRock);
00308         item->iX = KRPSScreensHAlignment;
00309         item->iY = gScreenHeight/4;
00310         item->iHighlighted = ETrue;
00311         iItems.AddFirst(*item);
00312         iIterator.SetToFirst();
00313         
00314         item = new (ELeave) TGameScreenItem(RPS::EPaper, KPaper);
00315         item->iX = KRPSScreensHAlignment;
00316         item->iY = gScreenHeight/2;
00317         TGameScreenItem* current = iIterator;
00318         ASSERT(current);
00319         item->iDlink.Enque(&current->iDlink);
00320         iIterator.Set(*item);
00321         
00322         item = new (ELeave) TGameScreenItem(RPS::EScissors, KScissors);
00323         item->iX = KRPSScreensHAlignment;
00324         item->iY = 3*gScreenHeight/4;
00325         current = iIterator;
00326         ASSERT(current);
00327         item->iDlink.Enque(&current->iDlink);
00328         }
00329 
00330 void CPlayScreen::PreActivate()
00331         {
00332         iGameScreenMgr.Roshambo().ResetPlayers();
00333         iPlayTimer->Start();
00334         }
00335 
00336 void CPlayScreen::DeActivate()
00337         {
00338         // Cancel the play timer
00339         iPlayTimer->Cancel();
00340         
00341         // If the game is moving to pause because of inactivity, make sure to  
00342     // send a response to the opponent in a multiplayer game (no selection)
00343         if (iGameScreenMgr.GameData().iRpsError == KErrTimedOut)
00344                 {
00345                 if (iGameScreenMgr.PlayMode()==CGameScreenManager::ETwoPlayerShortlink)
00346                         {
00347                         iGameScreenMgr.BluetoothManager().SendData(TRoshambo::ENone);
00348                         }
00349                 iGameScreenMgr.GameData().iRpsError = KErrNone;
00350                 }
00351         }
00352 
00353 // The play timer went off - the user didn't take a move within the time limit
00354 void CPlayScreen::PlayTimeout()
00355         {
00356         if(iGameScreenMgr.PlayMode()==CGameScreenManager::ESinglePlayer)
00357                 {                       
00358                 iGameScreenMgr.Roshambo().SinglePlayerGame(TRoshambo::ENone);
00359                 iGameScreenMgr.SetGameState(CGameScreenManager::EResultScreen);
00360                 }
00361         else
00362                 {
00363                 ASSERT(iGameScreenMgr.PlayMode()==CGameScreenManager::ETwoPlayerShortlink);
00364                 iGameScreenMgr.BluetoothManager().SendData(TRoshambo::ENone);   
00365                 }
00366         }
00367 
00368 // Handles item selection according to menu
00369 // Here, the next appropriate screen is displayed
00370 void CPlayScreen::DoProcessInput(RPS::TMenuOption aSelected)
00371         {
00372         if (iGameScreenMgr.PlayMode()==CGameScreenManager::ESinglePlayer)
00373                 {
00374                 switch (aSelected)
00375                         {
00376                         case(RPS::ERock):
00377                                 iGameScreenMgr.Roshambo().SinglePlayerGame(TRoshambo::ERock);
00378                                 break;
00379                         case (RPS::EPaper):
00380                                 iGameScreenMgr.Roshambo().SinglePlayerGame(TRoshambo::EPaper);
00381                                 break;
00382                         case (RPS::EScissors):
00383                                 iGameScreenMgr.Roshambo().SinglePlayerGame(TRoshambo::EScissors);
00384                                 break;
00385                                         
00386                         default:
00387                                 ASSERT(EFalse);
00388                         }
00389                 iGameScreenMgr.SetGameState(CGameScreenManager::EResultScreen);
00390                 }
00391         else
00392                 { // Multiplayer mode code here
00393                 TRoshambo::TElement element(TRoshambo::ENone);
00394                 switch (aSelected)
00395                         {
00396                         case(RPS::ERock):
00397                                 element = TRoshambo::ERock;
00398                                 break;
00399                         case (RPS::EPaper):
00400                                 element = TRoshambo::EPaper;
00401                                 break;
00402                         case (RPS::EScissors):
00403                                 element = TRoshambo::EScissors;
00404                                 break;
00405                                         
00406                         default:
00407                                 ASSERT(EFalse);
00408                         }
00409                 iGameScreenMgr.BluetoothManager().SendData(element);
00410                 }
00411         }
00412 
00413 // -------------------------------------------------------------
00414 // About Screen
00415 // -------------------------------------------------------------
00416 CGameScreen* CAboutScreen::NewL(CGameScreenManager& aScreenMgr)
00417         {
00418         CAboutScreen* me = new (ELeave) CAboutScreen(aScreenMgr);
00419         CleanupStack::PushL(me);
00420         me->ConstructL();
00421         CleanupStack::Pop(me);
00422         return (static_cast<CGameScreen*>(me));
00423         }
00424 
00425 CAboutScreen::CAboutScreen(CGameScreenManager& aScreenMgr)
00426 : CMenuScreen(aScreenMgr)
00427 {}
00428 
00429 void CAboutScreen::ConstructL()
00430         {
00431         _LIT(KBack, "Back");
00432         
00433         TGameScreenItem* item = new (ELeave) TGameScreenItem(RPS::EReturnToMainScreen, KBack);
00434         item->iX = KRPSScreensHAlignment;
00435         item->iY = 8*gScreenHeight/9;
00436         item->iHighlighted = ETrue;
00437         iItems.AddFirst(*item);
00438         iIterator.SetToFirst(); 
00439         }
00440 
00441 // Handles item selection (in this case, returns to the main menu)
00442 void CAboutScreen::DoProcessInput(RPS::TMenuOption aSelected)
00443         {
00444         switch (aSelected)
00445                 {
00446                 case(RPS::EReturnToMainScreen):
00447                         iGameScreenMgr.SetGameState(CGameScreenManager::EMainScreen);
00448                         break;
00449                 default:
00450                         ASSERT(EFalse);
00451                 }
00452         }
00453 
00454 void CAboutScreen::DrawGameScreen()
00455         {
00456         CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00457         gc.SetPenStyle(CGraphicsContext::ENullPen);     
00458         gc.UseFont(CCoeEnv::Static()->NormalFont());
00459         gc.SetPenColor(KRgbGray);
00460         
00461         _LIT(KVersion, "RPS version ");
00462         _LIT(KCreatedBy, "Created by");
00463         _LIT(KMS, "Maurizio Scotti");
00464         _LIT(KJCS, "Jo Stichbury");
00465         _LIT(KWithThanks, "With thanks to");
00466         _LIT(KSymsource, "Symsource Ltd");
00467         
00468         TBuf<KMaxRpsTextElement> versionText(KVersion);
00469         versionText.Append(KRPSVersionString());
00470         
00471         gc.DrawText(versionText, TPoint(KRPSScreensHAlignment, gScreenHeight/9)); 
00472         gc.DrawText(KCreatedBy, TPoint(KRPSScreensHAlignment, 2*gScreenHeight/9));    
00473         gc.DrawText(KMS, TPoint(KRPSScreensHAlignment, gScreenHeight/3));       
00474         gc.DrawText(KJCS, TPoint(KRPSScreensHAlignment, 4*gScreenHeight/9)); 
00475         gc.DrawText(KWithThanks, TPoint(KRPSScreensHAlignment, 5*gScreenHeight/9)); 
00476         gc.DrawText(KSymsource, TPoint(KRPSScreensHAlignment, 2*gScreenHeight/3)); 
00477         
00478         CMenuScreen::DrawGameScreen();
00479         }
00480 
00481 // -----------------------------------------------------------------------------                
00482 // Pause Screen 
00483 // -----------------------------------------------------------------------------                
00484         
00485 CGameScreen* CPauseScreen::NewL(CGameScreenManager& aScreenMgr)
00486         {
00487         CPauseScreen* me = new (ELeave) CPauseScreen(aScreenMgr);
00488         CleanupStack::PushL(me);
00489         me->ConstructL();
00490         CleanupStack::Pop(me);
00491         return (static_cast<CGameScreen*>(me));
00492         }
00493 
00494 void CPauseScreen::DrawGameScreen()
00495         {
00496         ASSERT(iBmp);
00497         CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00498         gc.BitBlt(iPos, iBmp);
00499         }
00500 
00501 void CPauseScreen::ProcessInput(TUint& aKeyState)
00502         {
00503         if (aKeyState & KKey5)
00504                 {// The '5' key has been pressed, return to the main screen
00505                 iGameScreenMgr.SetGameState(CGameScreenManager::EMainScreen);
00506                 aKeyState &= ~KKey5; // Clear the input now it's been handled
00507                 }
00508         }
00509 
00510 void CPauseScreen::DeActivate()
00511         {
00512         if (iGameScreenMgr.PlayMode()==CGameScreenManager::ETwoPlayerShortlink)
00513                 iGameScreenMgr.BluetoothManager().QuitMultiplayerGame();
00514         
00515         iGameScreenMgr.GameEngine().UnpauseGame();
00516         }
00517 
00518 CPauseScreen::CPauseScreen(CGameScreenManager& aScreenMgr)
00519 : CGameScreen(aScreenMgr)
00520         {}
00521 
00522 CPauseScreen::~CPauseScreen()
00523         {
00524         delete iBmp;
00525         }
00526 
00527 void CPauseScreen::ConstructL()
00528         {
00529         _LIT(KRpsBmps, "\\resource\\apps\\rps_0xA00054BC.mbm");
00530         CEikonEnv* eikonEnv = CEikonEnv::Static();
00531         iBmp = eikonEnv->CreateBitmapL(KRpsBmps, EMbmRps_0xa00054bcPausemenu);
00532         
00533         TSize size = iBmp->SizeInPixels();
00534         TInt width = size.iWidth;
00535         TInt height = size.iHeight;
00536         iPos = TPoint(0,0);
00537         if (gScreenWidth > width)
00538                 iPos.iX = (gScreenWidth - width)/2;
00539                 
00540         if (gScreenHeight > height)
00541                 iPos.iY = (gScreenHeight - height)/2;
00542         }
00543 
00544 // -----------------------------------------------------------------------------                
00545 // Splash Screen        
00546 // -----------------------------------------------------------------------------                
00547         
00548 CGameScreen* CSplashScreen::NewL(CGameScreenManager& aScreenMgr)
00549         {
00550         CSplashScreen* me = new (ELeave) CSplashScreen(aScreenMgr);
00551         CleanupStack::PushL(me);
00552         me->ConstructL();
00553         CleanupStack::Pop(me);
00554         return (static_cast<CGameScreen*>(me));
00555         }
00556 
00557 void CSplashScreen::DrawGameScreen()
00558         {
00559         // Game ticks at between 20 and 30 fps
00560         // Display splash screen for 150 ticks (approx 6 seconds)
00561         const TInt KSplashTimeout = 150;
00562         
00563         if (++iSplashCounter<KSplashTimeout)
00564                 {
00565                 ASSERT(iBmp);
00566                 CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00567                 gc.BitBlt(iPos, iBmp);
00568                 }
00569         else
00570                 {
00571                 iGameScreenMgr.SetGameState(CGameScreenManager::EMainScreen);
00572                 }
00573         }
00574 
00575 CSplashScreen::CSplashScreen(CGameScreenManager& aScreenMgr)
00576 : CGameScreen(aScreenMgr)
00577         {}
00578 
00579 CSplashScreen::~CSplashScreen()
00580         {
00581         delete iBmp;
00582         }
00583 
00584 void CSplashScreen::ConstructL()
00585         {
00586         _LIT(KRpsBmps, "\\resource\\apps\\rps_0xA00054BC.mbm");
00587         CEikonEnv* eikonEnv = CEikonEnv::Static();
00588         iBmp = eikonEnv->CreateBitmapL(KRpsBmps, EMbmRps_0xa00054bcSplashscreen);
00589         
00590         TSize size = iBmp->SizeInPixels();
00591         TInt width = size.iWidth;
00592         TInt height = size.iHeight;
00593         iPos = TPoint(0,0);
00594         if (gScreenWidth > width)
00595                 iPos.iX = (gScreenWidth - width)/2;
00596         else
00597                 iPos.iX =(width = gScreenWidth)/2;
00598                 
00599         if (gScreenHeight > height)
00600                 iPos.iY = (gScreenHeight - height)/2;
00601         else
00602                 iPos.iY = (height - gScreenHeight)/2;
00603         }
00604 
00605 CResultScreen* CResultScreen::NewL(CGameScreenManager& aScreenMgr)
00606         {
00607         CResultScreen* me = new (ELeave) CResultScreen(aScreenMgr);
00608         return (me);
00609         }
00610 
00611 // -----------------------------------------------------------------------------                
00612 // Results Screen       
00613 // -----------------------------------------------------------------------------                
00614 void CResultScreen::DrawGameScreen()
00615         {
00616         CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00617         gc.SetPenStyle(CGraphicsContext::ENullPen);     
00618         gc.UseFont(CCoeEnv::Static()->NormalFont());
00619         gc.SetPenColor(KRgbGray);
00620         
00621         TRoshambo roshambo = iGameScreenMgr.Roshambo();
00622         _LIT(KChoiceText, "You: ");
00623         _LIT(KNoChoice, " Nothing");
00624         
00625         TBuf<KMaxRpsTextElement> choiceText(KChoiceText);
00626         
00627         if (roshambo.LocalPlayer()==TRoshambo::ERock)
00628                 {
00629                 choiceText.Append(KRock());
00630                 }
00631         else if (roshambo.LocalPlayer()==TRoshambo::EPaper)
00632                 {
00633                 choiceText.Append(KPaper());
00634                 }
00635         else if (roshambo.LocalPlayer()==TRoshambo::EScissors)
00636                 {
00637                 choiceText.Append(KScissors());
00638                 }
00639         else 
00640                 {
00641                 ASSERT(roshambo.LocalPlayer()==TRoshambo::ENone);
00642                 choiceText.Append(KNoChoice());
00643                 }
00644 
00645         gc.DrawText(choiceText, TPoint(KRPSScreensHAlignment, gScreenHeight/6));    
00646         
00647         _LIT(KGameOppChoice, "Opponent: ");
00648         TBuf<KMaxRpsTextElement> oppChoiceText(KGameOppChoice);
00649         
00650         if (roshambo.Opponent()==TRoshambo::ERock)
00651                 {
00652                 oppChoiceText.Append(KRock());
00653                 }
00654         else if (roshambo.Opponent()==TRoshambo::EPaper)
00655                 {
00656                 oppChoiceText.Append(KPaper());
00657                 }
00658         else if (roshambo.Opponent()==TRoshambo::EScissors)
00659                 {
00660                 oppChoiceText.Append(KScissors());
00661                 }
00662         else 
00663                 {
00664                 ASSERT(roshambo.Opponent()==TRoshambo::ENone);
00665                 oppChoiceText.Append(KNoChoice());
00666                 }
00667         
00668         gc.DrawText(oppChoiceText, TPoint(KRPSScreensHAlignment, gScreenHeight/3));    
00669         
00670         TRoshambo::TResult result = roshambo.CalculateResult();
00671         
00672         _LIT(KGameResult, "You ");
00673         TBuf<KMaxRpsTextElement> resultText(KGameResult);
00674         
00675         if (result==TRoshambo::EWin)
00676                 {
00677                 _LIT(KWin, "Win!");
00678                 resultText.Append(KWin);
00679                 }
00680         else if (result==TRoshambo::ELose)
00681                 {
00682                 _LIT(KLose, "Lose!");
00683                 resultText.Append(KLose);
00684                 }
00685         else if (result==TRoshambo::EDraw)
00686                 {
00687                 _LIT(KDraw, "Drew!");
00688                 resultText.Append(KDraw);
00689                 }
00690         else
00691                 {
00692                 ASSERT(result==TRoshambo::ENoContest);
00693                 _LIT(KAbandoned, "Game was abandoned");
00694                 resultText = KAbandoned();
00695                 }
00696         
00697         //Draw the rps result
00698         gc.DrawText(resultText, TPoint(KRPSScreensHAlignment, gScreenHeight/2)); 
00699         
00700         _LIT(KPressKey, "Again? Press center key");
00701         gc.DrawText(KPressKey, TPoint(KRPSScreensHAlignment, 2*gScreenHeight/3));
00702         
00703         _LIT(KPressQuit, "Quit? Press 5");
00704         gc.DrawText(KPressQuit, TPoint(KRPSScreensHAlignment, 5*gScreenHeight/6));      
00705         }
00706 
00707 void CResultScreen::ProcessInput(TUint& aKeyState)
00708         {
00709         if (aKeyState & KControllerCentre)
00710                 {// The center  key has been pressed, return to the play screen
00711                 if(iGameScreenMgr.PlayMode()==CGameScreenManager::ESinglePlayer)
00712                         {                       
00713                         iGameScreenMgr.SetGameState(CGameScreenManager::EPlayScreen);
00714                         }
00715                 else
00716                         {                       
00717                         iGameScreenMgr.BluetoothManager().ReplayGame();
00718                         }
00719                 aKeyState &= ~KControllerCentre; // Clear the input now it's been handled
00720                 }
00721         else if (aKeyState & KKey5)
00722                 {// The '5' key has been pressed to quit, return to the main screen
00723                 iGameScreenMgr.SetGameState(CGameScreenManager::EMainScreen);
00724                 iGameScreenMgr.BluetoothManager().QuitMultiplayerGame();
00725                 aKeyState &= ~KKey5; // Clear the input now it's been handled
00726                 }
00727         }
00728 
00729 
00730 CResultScreen::CResultScreen(CGameScreenManager& aScreenMgr)
00731 : CGameScreen(aScreenMgr)       
00732 {}
00733 
00734 // -----------------------------------
00735 // CNotifierScreen 
00736 // -----------------------------------
00737 
00738 CNotifierScreen* CNotifierScreen::NewL(CGameScreenManager& aGameScreenMgr)
00739         {
00740         CNotifierScreen* me = new (ELeave) CNotifierScreen(aGameScreenMgr);
00741         return (me);
00742         }
00743 
00744 CNotifierScreen::CNotifierScreen(CGameScreenManager& aGameScreenMgr)
00745 :CGameScreen(aGameScreenMgr){}
00746 
00747 CNotifierScreen::~CNotifierScreen()
00748 {}
00749 
00750 // This is a dummy screen that doesn't re-draw - thus allowing a notifier to be visible
00751 void CNotifierScreen::DrawGameScreen()
00752         {
00753         
00754         }

Generated by  doxygen 1.6.2