examples/SFExamples/RockPaperScissorsGameSourceCode_S60/RPS/src/rpsMultiplayerScreens.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 <coemain.h>
00032 #include "common.hrh" 
00033 #include "rpsGameScreens.h" 
00034 #include "rpsgameengine.h"
00035 #include "bluetoothmanager.h"
00036 
00037 /*
00038 ============================================================================
00039 Control menu screen. User chooses to be either a Master (the player controls the game) or 
00040 a Slave (the player waits for other player connection)  
00041 ============================================================================
00042 */      
00043 CGameScreen* CControlScreen::NewL(CGameScreenManager& aScreenMgr)
00044         {
00045         CControlScreen* me = new (ELeave) CControlScreen(aScreenMgr);
00046         CleanupStack::PushL(me);
00047         me->ConstructL();
00048         CleanupStack::Pop(me);
00049         return (static_cast<CGameScreen*>(me));
00050         }
00051 
00052 CControlScreen::CControlScreen(CGameScreenManager& aScreenMgr)
00053 : CMenuScreen(aScreenMgr)
00054 {}
00055 
00056 void CControlScreen::ConstructL()
00057         {       
00058         _LIT(KMaster, "Control Game");
00059         _LIT(KSlave, "Wait Connection");
00060 
00061         TGameScreenItem* item = new (ELeave) TGameScreenItem(RPS::EMaster, KMaster);
00062         item->iX = KRPSScreensHAlignment;
00063         item->iY = gScreenHeight/3;
00064         item->iHighlighted = ETrue;
00065         iItems.AddFirst(*item);
00066         iIterator.SetToFirst();
00067         
00068         item = new (ELeave) TGameScreenItem(RPS::ESlave, KSlave);
00069         item->iX = KRPSScreensHAlignment;
00070         item->iY = 2*gScreenHeight/3;
00071         TGameScreenItem* current = iIterator;
00072         ASSERT(current);
00073         item->iDlink.Enque(&current->iDlink);   
00074         }
00075 
00076 // Handles item selection according to menu
00077 // Here, the next appropriate screen is displayed
00078 void CControlScreen::DoProcessInput(RPS::TMenuOption aSelected)
00079         {
00080         switch (aSelected)
00081                 {
00082                 case(RPS::EMaster):
00083                         iGameScreenMgr.BluetoothManager().StartBtMaster();
00084                         break;
00085                 case(RPS::ESlave):
00086                         iGameScreenMgr.BluetoothManager().StartBtSlave();
00087                         break;
00088                 default:
00089                         ASSERT(EFalse);
00090                 }
00091         }
00092 
00093 //-----------------------------------------------------------------------------
00094 
00095 //-----------------------------------------------------------------------------         
00096 //CStartScreen
00097 //-----------------------------------------------------------------------------         
00098         
00099 CGameScreen* CStartScreen::NewL(CGameScreenManager& aScreenMgr)
00100         {
00101         CStartScreen* me = new (ELeave) CStartScreen(aScreenMgr);
00102         CleanupStack::PushL(me);
00103         me->ConstructL();
00104         CleanupStack::Pop(me);
00105         return (static_cast<CGameScreen*>(me));
00106         }
00107 
00108 CStartScreen::CStartScreen(CGameScreenManager& aScreenMgr)
00109 : CMenuScreen(aScreenMgr)
00110 {}
00111 
00112 void CStartScreen::ConstructL()
00113         {       
00114         _LIT(KStartMsg, "Start Game");
00115 
00116         TGameScreenItem* item = new (ELeave) TGameScreenItem(RPS::EStart, KStartMsg);
00117         item->iX = KRPSScreensHAlignment;
00118         item->iY = gScreenHeight/2;
00119         item->iHighlighted = ETrue;
00120         iItems.AddFirst(*item);
00121         iIterator.SetToFirst();
00122         }
00123 
00124 // Handles item selection according to menu
00125 // Here, the next appropriate screen is displayed
00126 void CStartScreen::DoProcessInput(RPS::TMenuOption aSelected)
00127         {
00128         switch (aSelected)
00129                 {
00130                 case(RPS::EStart):
00131                         iGameScreenMgr.BluetoothManager().StartGame();
00132                         break;
00133                 default:
00134                         ASSERT(EFalse);
00135                 }
00136         }
00137 
00138 //-----------------------------------------------------------------------------
00139 
00140 //-----------------------------------------------------------------------------         
00141 //CWaitStartScreen
00142 //-----------------------------------------------------------------------------         
00143 
00144 CWaitStartScreen* CWaitStartScreen::NewL(CGameScreenManager& aScreenMgr)
00145         {
00146         CWaitStartScreen* me = new (ELeave) CWaitStartScreen(aScreenMgr);
00147         return (me);
00148         }
00149 
00150 void CWaitStartScreen::DrawGameScreen()
00151         {
00152         CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00153         gc.SetPenStyle(CGraphicsContext::ENullPen);     
00154         gc.UseFont(CCoeEnv::Static()->NormalFont());
00155         gc.SetPenColor(KRgbGray);
00156         
00157         _LIT(KWaitingText, "Waiting to start...");
00158                 
00159         gc.DrawText(KWaitingText, TPoint(KRPSScreensHAlignment, gScreenHeight/2)); 
00160         }
00161 
00162 
00163 CWaitStartScreen::CWaitStartScreen(CGameScreenManager& aScreenMgr)
00164 :       CGameScreen(aScreenMgr)
00165         {}
00166 //-----------------------------------------------------------------------------
00167 
00168 //-----------------------------------------------------------------------------         
00169 //CWaitConnScreen
00170 //-----------------------------------------------------------------------------         
00171 
00172 CWaitConnScreen* CWaitConnScreen::NewL(CGameScreenManager& aScreenMgr)
00173         {
00174         CWaitConnScreen* me = new (ELeave) CWaitConnScreen(aScreenMgr);
00175         return (me);
00176         }
00177 
00178 void CWaitConnScreen::DrawGameScreen()
00179         {
00180         CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00181         gc.SetPenStyle(CGraphicsContext::ENullPen);     
00182         gc.UseFont(CCoeEnv::Static()->NormalFont());
00183         gc.SetPenColor(KRgbGray);
00184         
00185         _LIT(KWaitingText, "Waiting to connect...");
00186                 
00187         gc.DrawText(KWaitingText, TPoint(KRPSScreensHAlignment, gScreenHeight/2)); 
00188         }
00189 
00190 CWaitConnScreen::CWaitConnScreen(CGameScreenManager& aScreenMgr)
00191 :       CGameScreen(aScreenMgr) 
00192         {}
00193 
00194 
00195 //-----------------------------------------------------------------------------
00196 
00197 //-----------------------------------------------------------------------------         
00198 //CErrorScreen
00199 //-----------------------------------------------------------------------------         
00200 
00201 CErrorScreen* CErrorScreen::NewL(CGameScreenManager& aScreenMgr)
00202         {
00203         CErrorScreen* me = new (ELeave) CErrorScreen(aScreenMgr);
00204         return (me);
00205         }
00206 
00207 void CErrorScreen::DrawGameScreen()
00208         {
00209         CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00210         gc.SetPenStyle(CGraphicsContext::ENullPen);     
00211         gc.UseFont(CCoeEnv::Static()->NormalFont());
00212         gc.SetPenColor(KRgbGray);
00213         
00214         if(iGameScreenMgr.GameData().iRpsError == KErrDisconnected)
00215                 {
00216                  _LIT(KDisconnectedText, "Lost Connection");
00217                  gc.DrawText(KDisconnectedText, TPoint(KRPSScreensHAlignment, gScreenHeight/3));
00218                 }
00219         else if(iGameScreenMgr.GameData().iRpsError == KErrTimedOut)
00220                 {
00221                  _LIT(KTimedOutText, "Timed out");
00222                  gc.DrawText(KTimedOutText, TPoint(KRPSScreensHAlignment, gScreenHeight/3));
00223                 }
00224          else
00225                  {
00226                   _LIT(KGeneralErrText, "An error occurred");
00227                   gc.DrawText(KGeneralErrText, TPoint(KRPSScreensHAlignment, gScreenHeight/3));
00228                  }
00229         _LIT(KPressQuit, "Press 5 continue");
00230         gc.DrawText(KPressQuit, TPoint(KRPSScreensHAlignment, 2*gScreenHeight/3));
00231         }
00232 
00233 void CErrorScreen::ProcessInput(TUint& aKeyState)
00234         {
00235         if (aKeyState & KKey5)
00236                 {// Quit and return to the main screen
00237                 iGameScreenMgr.SetGameState(CGameScreenManager::EMainScreen);
00238                 aKeyState &= ~KKey5; // Clear the input now it's been handled
00239                 }
00240         }
00241 
00242 void CErrorScreen::DeActivate()
00243         {
00244         if (iGameScreenMgr.PlayMode()==CGameScreenManager::ETwoPlayerShortlink)
00245                 iGameScreenMgr.BluetoothManager().QuitMultiplayerGame();
00246         }
00247 
00248 CErrorScreen::CErrorScreen(CGameScreenManager& aScreenMgr)
00249 :       CGameScreen(aScreenMgr) 
00250         {}
00251 
00252 //-----------------------------------------------------------------------------         
00253 //CConnectingScreen
00254 //-----------------------------------------------------------------------------         
00255 
00256 CConnectingScreen* CConnectingScreen::NewL(CGameScreenManager& aScreenMgr)
00257         {
00258         CConnectingScreen* me = new (ELeave) CConnectingScreen(aScreenMgr);
00259         return (me);
00260         }
00261 
00262 void CConnectingScreen::DrawGameScreen()
00263         {
00264         CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00265         gc.SetPenStyle(CGraphicsContext::ENullPen);     
00266         gc.UseFont(CCoeEnv::Static()->NormalFont());
00267         gc.SetPenColor(KRgbGray);
00268         
00269         _LIT(KDisconnectedText, "Connecting...");
00270         gc.DrawText(KDisconnectedText, TPoint(KRPSScreensHAlignment, gScreenHeight/3));
00271         _LIT(KPressQuit, "Press 5 to cancel");
00272         gc.DrawText(KPressQuit, TPoint(KRPSScreensHAlignment, 2*gScreenHeight/3));
00273         }
00274 
00275 void CConnectingScreen::ProcessInput(TUint& aKeyState)
00276         {
00277         if (aKeyState & KKey5)
00278                 {// Quit and return to main screen
00279                 iGameScreenMgr.SetGameState(CGameScreenManager::EMainScreen);
00280                 iGameScreenMgr.BluetoothManager().QuitMultiplayerGame();
00281                 aKeyState &= ~KKey5; // Clear the input now it's been handled
00282                 }
00283         }
00284 
00285 CConnectingScreen::CConnectingScreen(CGameScreenManager& aScreenMgr)
00286 :       CGameScreen(aScreenMgr) 
00287         {}
00288 
00289 
00290 //-----------------------------------------------------------------------------         
00291 //CWaitOpponentScreen
00292 //-----------------------------------------------------------------------------         
00293 
00294 CWaitOpponentScreen* CWaitOpponentScreen::NewL(CGameScreenManager& aScreenMgr)
00295         {
00296         CWaitOpponentScreen* me = new (ELeave) CWaitOpponentScreen(aScreenMgr);
00297         return (me);
00298         }
00299 
00300 void CWaitOpponentScreen::DrawGameScreen()
00301         {
00302         CWindowGc& gc = CCoeEnv::Static()->SystemGc();
00303         gc.SetPenStyle(CGraphicsContext::ENullPen);     
00304         gc.UseFont(CCoeEnv::Static()->NormalFont());
00305         gc.SetPenColor(KRgbGray);
00306         
00307         _LIT(KWaitingText, "Waiting for opponent...");
00308                 
00309         gc.DrawText(KWaitingText, TPoint(KRPSScreensHAlignment, gScreenHeight/2)); 
00310         }
00311 
00312 
00313 
00314 CWaitOpponentScreen::CWaitOpponentScreen(CGameScreenManager& aScreenMgr)
00315 :       CGameScreen(aScreenMgr) 
00316         {}

Generated by  doxygen 1.6.2