|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : IMOpenAPIExampleModel.cpp 00004 * Part of : IMOpenAPIExample 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2005-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 // INCLUDE FILES 00017 #include <imconnection.h> 00018 #include <imclient.h> 00019 #include <bamdesca.h> 00020 #include <badesca.h> 00021 #include <imerrors.h> 00022 #include <e32math.h> 00023 #include "IMOpenAPIExamplemodel.h" 00024 #include "IMOpenAPIExampleDocument.h" 00025 #include "IMOpenAPIExampleAppUi.h" 00026 #include "IMOpenAPIExamplemsg.h" 00027 00028 // ================= MEMBER FUNCTIONS ======================= 00029 // 00030 // ---------------------------------------------------------- 00031 // CIMOpenAPIExamplemodel::ConstructL() 00032 // takes a pointer to document 00033 // ---------------------------------------------------------- 00034 // 00035 void CIMOpenAPIExamplemodel::ConstructL(CIMOpenAPIExampleDocument* aDocument) 00036 { 00037 TRAPD(err,iIMConnection = CImConnection::NewL(KNullDesC)); 00038 if (err!=KErrNone) 00039 { 00040 iNotSupported = ETrue; 00041 iState = EStateNotLogin; 00042 } 00043 else 00044 { 00045 iIMConnection->RegisterObserverL(this); // registering the connection 00046 iIMClient = iIMConnection->CreateImClientL();// creating the client 00047 iIMClient->RegisterObserverL(this); // registering the client 00048 00049 // Check the IM status and set the application accordingly 00050 if (iIMConnection->ImConnectionStatus() == ELoggedIn) 00051 iState = EStateLoginIdle; 00052 else 00053 00054 iNotSupported=EFalse; 00055 } 00056 00057 iDocument = aDocument; 00058 ResetGameData(); // reset game data grid 00059 00060 00061 iArrayOfIDs = new (ELeave) CDesCArrayFlat(1); 00062 00063 // msg sent ids are zero in the begining 00064 iMsgID = 0; 00065 iSending = EFalse; 00066 iLastMsg = MsgEndChallenge; 00067 SetOppID(KNullDesC); 00068 } 00069 00070 // ---------------------------------------------------------- 00071 // CIMOpenAPIExamplemodel::NewLC() 00072 // 00073 // ---------------------------------------------------------- 00074 // 00075 CIMOpenAPIExamplemodel* CIMOpenAPIExamplemodel::NewLC(CIMOpenAPIExampleDocument* aDocument) 00076 { 00077 CIMOpenAPIExamplemodel* self = new (ELeave) CIMOpenAPIExamplemodel; 00078 CleanupStack::PushL(self); 00079 self->ConstructL(aDocument); 00080 return self; 00081 } 00082 00083 // ---------------------------------------------------------- 00084 // CIMOpenAPIExamplemodel::NewL() 00085 // 00086 // ---------------------------------------------------------- 00087 // 00088 CIMOpenAPIExamplemodel* CIMOpenAPIExamplemodel::NewL(CIMOpenAPIExampleDocument* aDocument) 00089 { 00090 CIMOpenAPIExamplemodel* self = NewLC(aDocument); 00091 CleanupStack::Pop(self); 00092 return self; 00093 } 00094 00095 // ---------------------------------------------------- 00096 // CIMOpenAPIExamplemodel::~CIMOpenAPIExamplemodel() 00097 // Destructor 00098 // Frees reserved resources 00099 // ---------------------------------------------------- 00100 // 00101 CIMOpenAPIExamplemodel::~CIMOpenAPIExamplemodel() 00102 { 00103 if( iIMClient ) 00104 { 00105 iIMClient->UnregisterObserver(); 00106 delete iIMClient; 00107 iIMClient = NULL; 00108 } 00109 00110 if (iIMConnection) 00111 { 00112 iIMConnection->UnregisterObserver(); 00113 delete iIMConnection; 00114 iIMConnection = NULL; 00115 } 00116 00117 if(iOppID) 00118 delete iOppID; 00119 iOppID = NULL; 00120 00121 if (iArrayOfIDs) 00122 { 00123 iArrayOfIDs->Reset(); 00124 delete iArrayOfIDs; 00125 } 00126 } 00127 00128 00129 // ---------------------------------------------------- 00130 // CIMOpenAPIExamplemodel::CIMOpenAPIExamplemodel() 00131 // 00132 // ---------------------------------------------------- 00133 // 00134 CIMOpenAPIExamplemodel::CIMOpenAPIExamplemodel() 00135 { 00136 } 00137 00138 // FUNCTIONS FROM THE BASE CLASSES 00139 // ---------------------------------------------------- 00140 // CIMOpenAPIExamplemodel::HandleLoginL(const TInt aErrorCode) 00141 // 00142 // ---------------------------------------------------- 00143 // 00144 void CIMOpenAPIExamplemodel::HandleLoginL(const TInt aErrorCode) 00145 { 00146 iDocument->UI()->HandleMessageIMConnectionFromModel(Connected, aErrorCode); 00147 if (aErrorCode == KErrNone) 00148 { 00149 SetGameState(EStateLoginIdle); 00150 } 00151 } 00152 00153 // ---------------------------------------------------- 00154 // CIMOpenAPIExamplemodel::HandleLogoutL() 00155 // 00156 // ---------------------------------------------------- 00157 // 00158 void CIMOpenAPIExamplemodel::HandleLogoutL(const TInt aErrorCode) 00159 { 00160 iDocument->UI()->HandleMessageIMConnectionFromModel(DisConnected, aErrorCode); 00161 SetGameState(EStateNotLogin); 00162 } 00163 00164 // ---------------------------------------------------- 00165 // CIMOpenAPIExamplemodel::HandleLogoutL() 00166 // 00167 // ---------------------------------------------------- 00168 // 00169 void CIMOpenAPIExamplemodel::HandleCancelLoginL(const TInt /*aErrorCode*/) 00170 { 00171 00172 00173 } 00174 00175 // ---------------------------------------------------- 00176 // CIMOpenAPIExamplemodel::HandleMessageSentL() 00177 // 00178 // ---------------------------------------------------- 00179 // 00180 void CIMOpenAPIExamplemodel::HandleMessageSentL( const TInt /*aOpCode*/, const TInt aErrorCode ) 00181 { 00182 iSending = EFalse; 00183 switch (iLastMsg) 00184 { 00185 case MsgChallenge: 00186 SetGameState(EStateChallenged); 00187 iDocument->UI()->HandleMessageFromModel(ChallengeSent, aErrorCode, KNullDesC); 00188 break; 00189 00190 case MsgChallengeAccepted: 00191 SetGameState(EStateReadytoStart); 00192 break; 00193 00194 case MsgChallengeRejected: 00195 SetGameState(EStateLoginIdle); 00196 break; 00197 00198 case MsgStartGameYourTurn: 00199 if (GetGameState() == EStateReadytoStart) 00200 SetGameState(EStateWaitingForOppMove); 00201 break; 00202 00203 case MsgStartGameOppTurn: 00204 if (GetGameState() == EStateReadytoStart) 00205 SetGameState(EStateWaitingForOwnMove); 00206 break; 00207 00208 case MsgExitGame: 00209 iDocument->UI()->HandleMessageFromModel(EndGameRec, aErrorCode, KNullDesC); 00210 SetGameState(EStateReadytoStart); 00211 break; 00212 00213 case MsgPlayedIndex: 00214 break; 00215 00216 case MsgEndChallenge: 00217 iDocument->UI()->HandleMessageFromModel(EndChallengeRec, aErrorCode, KNullDesC); 00218 SetGameState(EStateLoginIdle); 00219 break; 00220 00221 case MsgAlreadyInGame: 00222 break; 00223 00224 default: 00225 break; 00226 } 00227 } 00228 00229 // ---------------------------------------------------- 00230 // CIMOpenAPIExamplemodel::HandleSendErrorL() 00231 // 00232 // ---------------------------------------------------- 00233 // 00234 void CIMOpenAPIExamplemodel::HandleSendErrorL(const TInt /*aOpCode*/, 00235 const TInt aErrorCode, 00236 MImClientDetailedError* /*aDetailedError*/) 00237 { 00238 iSending = EFalse; 00239 00240 00241 switch (aErrorCode) 00242 { 00243 case KImApiErrNotLogged: 00244 SetGameState(EStateNotLogin); 00245 iDocument->UI()->HandleMessageErrorFromModel(aErrorCode,KNullDesC ); 00246 break; 00247 00248 default: 00249 iDocument->UI()->HandleMessageErrorFromModel(aErrorCode,KNullDesC ); 00250 break; 00251 } 00252 } 00253 00254 00255 // ---------------------------------------------------- 00256 // CIMOpenAPIExamplemodel::HandleNewPToPMessageL() 00257 // 00258 // ---------------------------------------------------- 00259 // 00260 void CIMOpenAPIExamplemodel::HandleNewPToPMessageL( 00261 const TInt aErrorCode, 00262 const TContactItemId /*aContactId*/, 00263 const TDesC& aUserId, 00264 const TDesC& /*aMessageType*/, 00265 const TDesC16& aContent ) 00266 { 00267 TInt integerInfo = 0; 00268 TLex16 receivedMsgLex; 00269 TPtrC16 receivedMsg; 00270 TBool isDraw = EFalse; 00271 00272 00273 // checking for played index, which is different from other messages 00274 if (aContent.Find(KPlayedIndex) != KErrNotFound) 00275 { 00276 receivedMsgLex.Assign(aContent.Right(1)); 00277 receivedMsgLex.Val(integerInfo); 00278 receivedMsg.Set( aContent.Left(11) ); 00279 } 00280 else 00281 receivedMsg.Set(aContent); 00282 00283 switch (iState) 00284 { 00285 // In login idle state we only expect a Challenge from any other user 00286 case EStateLoginIdle: 00287 if ( receivedMsg.Compare(KChallenge) == 0) 00288 { 00289 SetOppID(aUserId); 00290 iDocument->UI()->HandleChallengeRec(aUserId); 00291 } 00292 break; 00293 00294 // In Challenged state we only expects challenge accepted or rejected from our opp 00295 case EStateChallenged: 00296 if ( aUserId.Compare(*iOppID) != 0) 00297 break; 00298 else if ( receivedMsg.Compare(KChallengeAccepted) == 0) 00299 { 00300 SetGameState(EStateReadytoStart); 00301 iDocument->UI()->HandleMessageFromModel(ChallengeAcceptedRec, aErrorCode, aContent); 00302 } 00303 else if ( receivedMsg.Compare(KChallengeRejected) == 0) 00304 { 00305 SetGameState(EStateLoginIdle); 00306 iDocument->UI()->HandleMessageFromModel(ChallengeRejectedRec, aErrorCode, aContent); 00307 } 00308 else if ( receivedMsg.Compare(KAlreadyInGame) == 0) 00309 { 00310 SetGameState(EStateLoginIdle); 00311 iDocument->UI()->HandleMessageFromModel(AlreadyInGameRec, aErrorCode, aContent); 00312 } 00313 // if opp also sent the challenge at the same time, we will reply already in game 00314 else if ( receivedMsg.Compare(KChallenge) == 0) 00315 { 00316 SetGameState(EStateLoginIdle); 00317 iDocument->UI()->HandleMessageFromModel(AlreadyInGameRec, aErrorCode, aContent); 00318 } 00319 // in all othe requests we will not take any action 00320 break; 00321 00322 00323 case EStateReadytoStart: 00324 if ( aUserId.Compare(*iOppID) != 0) 00325 break; 00326 else if ( receivedMsg.Compare(KStartGameYourTurn) == 0) 00327 { 00328 SetGameState(EStateWaitingForOwnMove); 00329 iDocument->UI()->HandleMessageFromModel(StartGameRec, aErrorCode, aContent); 00330 } 00331 else if ( receivedMsg.Compare(KStartGameOppTurn) == 0) 00332 { 00333 SetGameState(EStateWaitingForOppMove); 00334 iDocument->UI()->HandleMessageFromModel(StartGameRec, aErrorCode, aContent); 00335 } 00336 else if ( receivedMsg.Compare(KExitGame) == 0) 00337 { 00338 iDocument->UI()->HandleMessageFromModel(EndGameRec, aErrorCode, aContent); 00339 SetGameState(EStateReadytoStart); 00340 } 00341 else if ( receivedMsg.Compare(KEndChallenge) == 0) 00342 { 00343 iDocument->UI()->HandleMessageFromModel(EndChallengeRec, aErrorCode, KNullDesC); 00344 SetGameState(EStateLoginIdle); 00345 } 00346 else 00347 SendEndChallenge(); 00348 break; 00349 00350 00351 case EStateWaitingForOppMove: 00352 if ( aUserId.Compare(*iOppID) != 0) 00353 break; 00354 else if ( receivedMsg.Compare(KPlayedIndex) == 0) 00355 { 00356 iDocument->UI()->HandleMessageFromModel(PlayedIndexRec, integerInfo, aContent); 00357 iGameData.At(integerInfo) = iOppSign; 00358 if ( IsGameFinnished(isDraw) ) 00359 { 00360 if (isDraw) 00361 iDocument->UI()->HandleMessageFromModel(GameDraw, aErrorCode, aContent); 00362 else 00363 iDocument->UI()->HandleMessageFromModel(YouLost, aErrorCode, aContent); 00364 ResetGameData(); 00365 SetGameState(EStateReadytoStart); 00366 break; 00367 } 00368 SetGameState(EStateWaitingForOwnMove); 00369 } 00370 else if ( receivedMsg.Compare(KExitGame) == 0) 00371 { 00372 iDocument->UI()->HandleMessageFromModel(EndGameRec, aErrorCode, aContent); 00373 SetGameState(EStateReadytoStart); 00374 } 00375 else 00376 SendEndChallenge(); 00377 break; 00378 00379 00380 case EStateWaitingForOwnMove: 00381 if ( aUserId.Compare(*iOppID) != 0) 00382 break; 00383 if ( receivedMsg.Compare(KExitGame) == 0) 00384 { 00385 iDocument->UI()->HandleMessageFromModel(EndGameRec, aErrorCode, aContent); 00386 SetGameState(EStateReadytoStart); 00387 } 00388 else 00389 SendEndChallenge(); 00390 break; 00391 00392 00393 default: 00394 break; 00395 00396 } 00397 00398 } 00399 00400 // ---------------------------------------------------- 00401 // CIMOpenAPIExamplemodel::HandleNewPToPMessageL 00402 // Sends messages to IM 00403 // ---------------------------------------------------- 00404 // 00405 void CIMOpenAPIExamplemodel::HandleNewPToPMessageL( 00406 const TInt /*aErrorCode*/, 00407 const TContactItemId /*aContactId*/, 00408 const TDesC& /*aUserId*/, 00409 const TDesC& /*aMessageType*/, 00410 const TDesC8& /*aContent*/ ) 00411 { 00412 } 00413 00414 // ---------------------------------------------------- 00415 // CIMOpenAPIExamplemodel::LoginL 00416 // 00417 // ---------------------------------------------------- 00418 // 00419 void CIMOpenAPIExamplemodel::LoginL(const TDesC& aServerAddress, const TDesC& aUserId, 00420 const TDesC& aPassword, const TInt aAccessPoint) 00421 { 00422 // We are using TRAPD at the UI level, because it has GUI to display 00423 if (iNotSupported) 00424 User::Leave(KErrNotSupported); 00425 iIMConnection->LoginL(aServerAddress, aUserId, aPassword, aAccessPoint); 00426 } 00427 00428 // ---------------------------------------------------- 00429 // CIMOpenAPIExamplemodel::LogoutL 00430 // 00431 // ---------------------------------------------------- 00432 // 00433 void CIMOpenAPIExamplemodel::LogoutL() 00434 { 00435 // We are using TRAPD at the UI level, because it has GUI to display 00436 iIMConnection->LogoutL(); 00437 } 00438 00439 // ---------------------------------------------------- 00440 // CIMOpenAPIExamplemodel::SendMsg 00441 // Sends messages to IM 00442 // ---------------------------------------------------- 00443 // 00444 TInt CIMOpenAPIExamplemodel::SendMsg(TDesC16& aContent) 00445 { 00446 iSending = ETrue; 00447 //SetGameState (EStateSending); 00448 return iIMClient->SendPToPMessageL(*iArrayOfIDs, aContent); 00449 } 00450 00451 // ---------------------------------------------------- 00452 // CIMOpenAPIExamplemodel::SendChallenge 00453 // ---------------------------------------------------- 00454 // 00455 void CIMOpenAPIExamplemodel::SendChallenge() 00456 { 00457 iMessageToSend.Copy(KChallenge); 00458 iMsgID = SendMsg(iMessageToSend); 00459 iLastMsg = MsgChallenge; 00460 iMySign = ECrossSign; 00461 iOppSign = EZeroSign; 00462 } 00463 00464 // ---------------------------------------------------- 00465 // CIMOpenAPIExamplemodel::SendChallengeAccepted 00466 // ---------------------------------------------------- 00467 // 00468 void CIMOpenAPIExamplemodel::SendChallengeAccepted() 00469 { 00470 iMessageToSend.Copy(KChallengeAccepted); 00471 iMsgID = SendMsg(iMessageToSend); 00472 iLastMsg = MsgChallengeAccepted; 00473 iMySign = EZeroSign; 00474 iOppSign = ECrossSign; 00475 } 00476 00477 // ---------------------------------------------------- 00478 // CIMOpenAPIExamplemodel::SendChallengeRejected 00479 // ---------------------------------------------------- 00480 // 00481 void CIMOpenAPIExamplemodel::SendChallengeRejected() 00482 { 00483 iMessageToSend.Copy(KChallengeRejected); 00484 iMsgID = SendMsg(iMessageToSend); 00485 iLastMsg = MsgChallengeRejected; 00486 SetOppID(KNullDesC); 00487 } 00488 00489 // ---------------------------------------------------- 00490 // CIMOpenAPIExamplemodel::SendAlreadyInGame 00491 // ---------------------------------------------------- 00492 // 00493 void CIMOpenAPIExamplemodel::SendAlreadyInGame() 00494 { 00495 iMessageToSend.Copy(KAlreadyInGame); 00496 iMsgID = SendMsg(iMessageToSend); 00497 iLastMsg = MsgAlreadyInGame; 00498 } 00499 00500 // ---------------------------------------------------- 00501 // CIMOpenAPIExamplemodel::SendStartGame 00502 // ---------------------------------------------------- 00503 // 00504 void CIMOpenAPIExamplemodel::SendStartGame() 00505 { 00506 TBool turn; 00507 00508 // Find a randomize turn 00509 turn = ( Math::Rand(iSeed) ) % 2; 00510 00511 if (turn) 00512 { 00513 iMessageToSend.Copy(KStartGameOppTurn); 00514 iMsgID = SendMsg(iMessageToSend); 00515 iLastMsg = MsgStartGameOppTurn; 00516 } 00517 else 00518 { 00519 iMessageToSend.Copy(KStartGameYourTurn); 00520 iMsgID = SendMsg(iMessageToSend); 00521 iLastMsg = MsgStartGameYourTurn; 00522 } 00523 } 00524 00525 // ---------------------------------------------------- 00526 // CIMOpenAPIExamplemodel::SendExitGame 00527 // ---------------------------------------------------- 00528 // 00529 void CIMOpenAPIExamplemodel::SendExitGame() 00530 { 00531 iMessageToSend.Copy(KExitGame); 00532 iMsgID = SendMsg(iMessageToSend); 00533 iLastMsg = MsgExitGame; 00534 } 00535 00536 // ---------------------------------------------------- 00537 // CIMOpenAPIExamplemodel::SendPlayedIndex 00538 // ---------------------------------------------------- 00539 // 00540 void CIMOpenAPIExamplemodel::SendPlayedIndex(TInt aIndex) 00541 { 00542 TBool isDraw = EFalse; 00543 00544 iMessageToSend.Copy(KPlayedIndex); 00545 iMessageToSend.AppendNumUC(aIndex,EDecimal); 00546 iMsgID = SendMsg(iMessageToSend); 00547 iLastMsg = MsgPlayedIndex; 00548 00549 iGameData.At(aIndex) = iMySign; 00550 if ( IsGameFinnished(isDraw) ) 00551 { 00552 if (isDraw) 00553 iDocument->UI()->HandleMessageFromModel(GameDraw, KErrNone, KNullDesC); 00554 else 00555 iDocument->UI()->HandleMessageFromModel(YouWon, KErrNone, KNullDesC); 00556 ResetGameData(); 00557 SetGameState(EStateReadytoStart); 00558 return; 00559 } 00560 SetGameState(EStateWaitingForOppMove); 00561 } 00562 00563 // ---------------------------------------------------- 00564 // CIMOpenAPIExamplemodel::SendEndChallenge 00565 // ---------------------------------------------------- 00566 // 00567 void CIMOpenAPIExamplemodel::SendEndChallenge() 00568 { 00569 iMessageToSend.Copy(KEndChallenge); 00570 iMsgID = SendMsg(iMessageToSend); 00571 iLastMsg = MsgEndChallenge; 00572 } 00573 // ---------------------------------------------------- 00574 // CIMOpenAPIExamplemodel::IsGameFinnished 00575 // ---------------------------------------------------- 00576 // 00577 TBool CIMOpenAPIExamplemodel::IsGameFinnished(TBool& aIsDraw) 00578 { 00579 // checking for sign ECrossSign (*) win in the matrix 00580 if ( CheckForSeries(ECrossSign,ECrossSign,EZeroSign) || CheckForSeries(ECrossSign,3,EZeroSign) || 00581 CheckForSeries(ECrossSign,6,EZeroSign) || CheckForSeries(ECrossSign,ECrossSign,3) || 00582 CheckForSeries(ECrossSign,EZeroSign,3) || CheckForSeries(ECrossSign,EEmptySign,3) || 00583 CheckForSeries(ECrossSign,ECrossSign,4) || CheckForSeries(ECrossSign,EEmptySign,EEmptySign) ) 00584 { 00585 aIsDraw = EFalse; 00586 return ETrue; 00587 } 00588 00589 // checking for sign EZeroSign (o) win in the matrix 00590 else if ( CheckForSeries(EZeroSign,ECrossSign,EZeroSign) || CheckForSeries(EZeroSign,3,EZeroSign) || CheckForSeries(EZeroSign,6,EZeroSign) || 00591 CheckForSeries(EZeroSign,ECrossSign,3) || CheckForSeries(EZeroSign,EZeroSign,3) || CheckForSeries(EZeroSign,EEmptySign,3) || 00592 CheckForSeries(EZeroSign,ECrossSign,4) || CheckForSeries(EZeroSign,EEmptySign,EEmptySign) ) 00593 { 00594 aIsDraw = EFalse; 00595 return ETrue; 00596 } 00597 00598 else if (IsGameDraw()) 00599 { 00600 aIsDraw = ETrue; 00601 return ETrue; 00602 } 00603 00604 return EFalse; 00605 } 00606 00607 // ---------------------------------------------------- 00608 // CIMOpenAPIExamplemodel::IsGameDraw() 00609 // checks if the game has draw, should be called after checking for winner 00610 // ---------------------------------------------------- 00611 // 00612 TBool CIMOpenAPIExamplemodel::IsGameDraw() 00613 { 00614 for (TInt i=0;i<9;i++) 00615 { 00616 if (iGameData.At(i) == EEmptySign) 00617 return false; 00618 } 00619 return true; 00620 } 00621 00622 // ---------------------------------------------------- 00623 // CIMOpenAPIExamplemodel::CheckForSeries(TInt8 value, TInt8 startIndex, TInt8 indexIncrement) 00624 // Check for a series of 3 consective 'value', give start index and increment by number 00625 // ---------------------------------------------------- 00626 // 00627 TBool CIMOpenAPIExamplemodel::CheckForSeries(TGameSign aValue, TInt aStartIndex, TInt aIndexIncrement) 00628 { 00629 return ( (iGameData.At(aStartIndex) == aValue) && 00630 (iGameData.At(aStartIndex+aIndexIncrement) == aValue) && 00631 (iGameData.At(aStartIndex+aIndexIncrement+aIndexIncrement) == aValue) ); 00632 00633 } 00634 00635 // ---------------------------------------------------- 00636 // CIMOpenAPIExamplemodel::GetGameState() 00637 // returns Game current state, only call from outside this class 00638 // ---------------------------------------------------- 00639 // 00640 TGameState CIMOpenAPIExamplemodel::GetGameState() const 00641 { 00642 if(iSending) 00643 return EStateSending; 00644 return iState; 00645 } 00646 00647 // ---------------------------------------------------- 00648 // CIMOpenAPIExamplemodel::SetGameState() 00649 // Sets game status, in all the game 00650 // ---------------------------------------------------- 00651 // 00652 void CIMOpenAPIExamplemodel::SetGameState(TGameState const aState) 00653 { 00654 iState = aState; 00655 iDocument->UI()->SetGameState(aState); 00656 if (iState == EStateReadytoStart) 00657 ResetGameData(); 00658 else if (iState == EStateLoginIdle) 00659 SetOppID(KNullDesC); 00660 } 00661 00662 // ---------------------------------------------------- 00663 // CIMOpenAPIExamplemodel::SetOppID(TDesC16& aOppID) 00664 // Sets the oponent id and pushed it into an array 00665 // ---------------------------------------------------- 00666 // 00667 void CIMOpenAPIExamplemodel::SetOppID(const TDesC16& aOppID) 00668 { 00669 TBuf<KMaxUserIDLength> oppID(aOppID); 00670 oppID.LowerCase(); 00671 delete iOppID; 00672 iOppID = NULL; 00673 iOppID = oppID.AllocL(); 00674 iArrayOfIDs->Reset(); 00675 iArrayOfIDs->AppendL(*iOppID); 00676 } 00677 00678 // ---------------------------------------------------- 00679 // CIMOpenAPIExamplemodel::MatchOppID(TDesC16& aOppID) 00680 // matches incoming opp id to existing opp id, returns true if success 00681 // ---------------------------------------------------- 00682 // 00683 TBool CIMOpenAPIExamplemodel::MatchOppID(TDesC16& aOppID) 00684 { 00685 if ( iOppID->Compare(aOppID) == 0 ) 00686 return ETrue; 00687 return EFalse; 00688 } 00689 00690 // ---------------------------------------------------- 00691 // CIMOpenAPIExamplemodel::GetOppSign() 00692 // Gets opponent sign 00693 // ---------------------------------------------------- 00694 // 00695 TGameSign CIMOpenAPIExamplemodel::GetOppSign() const 00696 { 00697 return iOppSign; 00698 } 00699 00700 // ---------------------------------------------------- 00701 // CIMOpenAPIExamplemodel::ResetGameData() 00702 // ---------------------------------------------------- 00703 // 00704 void CIMOpenAPIExamplemodel::ResetGameData() 00705 { 00706 for (TInt8 i=0; i<9; i++) // set all game matrix data to 'empty' 00707 iGameData.At(i) = EEmptySign; 00708 } 00709 00710 // ---------------------------------------------------- 00711 // CIMOpenAPIExamplemodel::IsIndexPositionEmpty 00712 // ---------------------------------------------------- 00713 // 00714 TBool CIMOpenAPIExamplemodel::IsIndexPositionEmpty(TInt aIndex) 00715 { 00716 if ( iGameData.At(aIndex) == EEmptySign ) 00717 return ETrue; 00718 return EFalse; 00719 } 00720 00721 // ---------------------------------------------------- 00722 // CIMOpenAPIExamplemodel::PrepareToExit() 00723 // ---------------------------------------------------- 00724 // 00725 void CIMOpenAPIExamplemodel::PrepareToExit() 00726 { 00727 if ( (iState != EStateNotLogin) && (iState != EStateLoginIdle) ) 00728 SendEndChallenge(); 00729 } 00730 00731 // End of File 00732
|
© Nokia 2006 |