|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : SIPExStateLocal.cpp 00004 * Part of : SIPExEngine 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2004-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDES 00017 #include "SIPExStateLocal.h" 00018 #include "SIPExGameEngine.h" 00019 #include "SIPExSIPEngine.h" 00020 #include "SIPExGameConstants.h" 00021 00022 // ----------------------------------------------------------------------------- 00023 // TSIPExStateLocal::CursorPressed 00024 // Game state is updated. 00025 // Move is sent to the remote peer. If WIN the state is Registered. 00026 // otherwise turn is moved to remote. 00027 // ----------------------------------------------------------------------------- 00028 // 00029 void TSIPExStateLocal::CursorPressed( CSIPExEngine* aContext ) 00030 { 00031 TInt y = aContext->CalculatePos(); 00032 if ( y != -1 ) 00033 { 00034 aContext->SetBoard( aContext->Cursor(), y, 1 ); 00035 aContext->IncreaseMovesBy( 1 ); 00036 aContext->SendMessage( aContext->Cursor(), y ); 00037 TInt ret = aContext->IsWin( aContext->Cursor(),y ); 00038 00039 if (ret == 1) 00040 { 00041 ChangeState( aContext, aContext->iStateRemote ); 00042 aContext->StatusInfoL( KYouWin() ); 00043 EndGameL( aContext ); 00044 } 00045 else if ( aContext->Moves() == KMaxMoves ) 00046 { 00047 ChangeState( aContext, aContext->iStateRemote ); 00048 aContext->StatusInfoL( KGameTie() ); 00049 EndGameL( aContext ); 00050 } 00051 else 00052 { 00053 ChangeState( aContext, aContext->iStateRemote ); 00054 aContext->StatusInfoL( KWaitingRemote() ); 00055 } 00056 } 00057 } 00058 00059 // ----------------------------------------------------------------------------- 00060 // TSIPExStateLocal::CursorRight 00061 // Game state is updated. 00062 // ----------------------------------------------------------------------------- 00063 // 00064 void TSIPExStateLocal::CursorRight( CSIPExEngine* aContext ) 00065 { 00066 aContext->SetCursor( aContext->Cursor() + 1 ); 00067 if ( aContext->Cursor() > KBoxCountX - 1 ) 00068 { 00069 aContext->SetCursor( 0 ); 00070 } 00071 } 00072 00073 // ----------------------------------------------------------------------------- 00074 // TSIPExStateLocal::CursorLeft 00075 // Game state is updated. 00076 // ----------------------------------------------------------------------------- 00077 // 00078 void TSIPExStateLocal::CursorLeft( CSIPExEngine* aContext ) 00079 { 00080 aContext->SetCursor( aContext->Cursor() - 1 ); 00081 if ( aContext->Cursor() < 0 ) 00082 { 00083 aContext->SetCursor( KBoxCountX - 1 ); 00084 } 00085 } 00086 00087 // ----------------------------------------------------------------------------- 00088 // TSIPExStateLocal::DrawCursor 00089 // Returns always ETrue, because it is local player's turn we have to draw the 00090 // cursor. 00091 // ----------------------------------------------------------------------------- 00092 // 00093 TBool TSIPExStateLocal::DrawCursor() 00094 { 00095 return ETrue; 00096 } 00097 00098 // ----------------------------------------------------------------------------- 00099 // TSIPExStateLocal::SendInstantMsgL 00100 // Calls base classes function to send the instant message. 00101 // ----------------------------------------------------------------------------- 00102 // 00103 void TSIPExStateLocal::SendInstantMsgL( CSIPExEngine* aContext, 00104 const TDesC& aAddress, const TDesC& aMsg ) 00105 { 00106 HBufC8* addr = HBufC8::NewLC( aAddress.Length() ); 00107 addr->Des().Copy( aAddress ); 00108 00109 HBufC8* msg = HBufC8::NewLC( aMsg.Length() ); 00110 msg->Des().Copy( aMsg ); 00111 00112 aContext->SIPEngine()->CreateIML( *msg, *addr ); 00113 00114 CleanupStack::PopAndDestroy( msg ); 00115 CleanupStack::PopAndDestroy( addr ); 00116 } 00117 00118 // ----------------------------------------------------------------------------- 00119 // TSIPExStateLocal::InviteL 00120 // Notifies the UI. 00121 // ----------------------------------------------------------------------------- 00122 // 00123 void TSIPExStateLocal::InviteL( 00124 CSIPExEngine* aContext, 00125 const TDesC& /*aAddress*/ ) 00126 { 00127 aContext->InfoL( KGameAlreadyRunning() ); 00128 } 00129 00130 // ----------------------------------------------------------------------------- 00131 // TSIPExStateLocal::DisableProfile 00132 // Notifies the UI. 00133 // ----------------------------------------------------------------------------- 00134 // 00135 void TSIPExStateLocal::DisableProfileL( CSIPExEngine* aContext ) 00136 { 00137 aContext->InfoL( KGameAlreadyRunning() ); 00138 } 00139 00140 // ----------------------------------------------------------------------------- 00141 // TSIPExStateLocal::EndGameL 00142 // Notifies the UI and changes the active state to the Registered. 00143 // The socket engine will be deleted and the SIP session ended. 00144 // ----------------------------------------------------------------------------- 00145 // 00146 void TSIPExStateLocal::EndGameL( CSIPExEngine* aContext ) 00147 { 00148 aContext->SIPEngine()->EndSessionL(); 00149 } 00150 00151 // ----------------------------------------------------------------------------- 00152 // TSIPExStateLocal::MoveCursorL 00153 // Moves cursor into the new position. 00154 // ----------------------------------------------------------------------------- 00155 // 00156 void TSIPExStateLocal::MoveCursorL( 00157 CSIPExEngine* aContext, 00158 const TInt aNewPosition ) 00159 { 00160 aContext->SetCursor( aNewPosition ); 00161 } 00162 00163 // End of file 00164
|
© Nokia 2006 |