|
1 |
|
2 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 // All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Nokia Corporation - initial contribution. |
|
11 // |
|
12 // Contributors: |
|
13 // |
|
14 // Description: |
|
15 // |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "SIPExStateLocal.h" |
|
21 #include "SIPExGameEngine.h" |
|
22 #include "SIPExSIPEngine.h" |
|
23 #include "SIPExGameConstants.h" |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // TSIPExStateLocal::CursorPressed |
|
27 // Game state is updated. |
|
28 // Move is sent to the remote peer. If WIN the state is Registered. |
|
29 // otherwise turn is moved to remote. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 void TSIPExStateLocal::CursorPressed( CSIPExEngine* aContext ) |
|
33 { |
|
34 TInt y = aContext->CalculatePos(); |
|
35 if ( y != -1 ) |
|
36 { |
|
37 aContext->SetBoard( aContext->Cursor(), y, 1 ); |
|
38 aContext->IncreaseMovesBy( 1 ); |
|
39 aContext->SendMessage( aContext->Cursor(), y ); |
|
40 TInt ret = aContext->IsWin( aContext->Cursor(),y ); |
|
41 |
|
42 if (ret == 1) |
|
43 { |
|
44 ChangeState( aContext, aContext->iStateRemote ); |
|
45 aContext->StatusInfoL( KYouWin() ); |
|
46 EndGameL( aContext ); |
|
47 } |
|
48 else if ( aContext->Moves() == KMaxMoves ) |
|
49 { |
|
50 ChangeState( aContext, aContext->iStateRemote ); |
|
51 aContext->StatusInfoL( KGameTie() ); |
|
52 EndGameL( aContext ); |
|
53 } |
|
54 else |
|
55 { |
|
56 ChangeState( aContext, aContext->iStateRemote ); |
|
57 aContext->StatusInfoL( KWaitingRemote() ); |
|
58 } |
|
59 } |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // TSIPExStateLocal::CursorRight |
|
64 // Game state is updated. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void TSIPExStateLocal::CursorRight( CSIPExEngine* aContext ) |
|
68 { |
|
69 aContext->SetCursor( aContext->Cursor() + 1 ); |
|
70 if ( aContext->Cursor() > KBoxCountX - 1 ) |
|
71 { |
|
72 aContext->SetCursor( 0 ); |
|
73 } |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // TSIPExStateLocal::CursorLeft |
|
78 // Game state is updated. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void TSIPExStateLocal::CursorLeft( CSIPExEngine* aContext ) |
|
82 { |
|
83 aContext->SetCursor( aContext->Cursor() - 1 ); |
|
84 if ( aContext->Cursor() < 0 ) |
|
85 { |
|
86 aContext->SetCursor( KBoxCountX - 1 ); |
|
87 } |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // TSIPExStateLocal::DrawCursor |
|
92 // Returns always ETrue, because it is local player's turn we have to draw the |
|
93 // cursor. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 TBool TSIPExStateLocal::DrawCursor() |
|
97 { |
|
98 return ETrue; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // TSIPExStateLocal::SendInstantMsgL |
|
103 // Calls base classes function to send the instant message. |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void TSIPExStateLocal::SendInstantMsgL( CSIPExEngine* aContext, |
|
107 const TDesC& aAddress, const TDesC& aMsg ) |
|
108 { |
|
109 HBufC8* addr = HBufC8::NewLC( aAddress.Length() ); |
|
110 addr->Des().Copy( aAddress ); |
|
111 |
|
112 HBufC8* msg = HBufC8::NewLC( aMsg.Length() ); |
|
113 msg->Des().Copy( aMsg ); |
|
114 |
|
115 aContext->SIPEngine()->CreateIML( *msg, *addr ); |
|
116 |
|
117 CleanupStack::PopAndDestroy( msg ); |
|
118 CleanupStack::PopAndDestroy( addr ); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // TSIPExStateLocal::InviteL |
|
123 // Notifies the UI. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void TSIPExStateLocal::InviteL( |
|
127 CSIPExEngine* aContext, |
|
128 const TDesC& /*aAddress*/ ) |
|
129 { |
|
130 aContext->InfoL( KGameAlreadyRunning() ); |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // TSIPExStateLocal::DisableProfile |
|
135 // Notifies the UI. |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void TSIPExStateLocal::DisableProfileL( CSIPExEngine* aContext ) |
|
139 { |
|
140 aContext->InfoL( KGameAlreadyRunning() ); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // TSIPExStateLocal::EndGameL |
|
145 // Notifies the UI and changes the active state to the Registered. |
|
146 // The socket engine will be deleted and the SIP session ended. |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void TSIPExStateLocal::EndGameL( CSIPExEngine* aContext ) |
|
150 { |
|
151 aContext->SIPEngine()->EndSessionL(); |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // TSIPExStateLocal::MoveCursorL |
|
156 // Moves cursor into the new position. |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void TSIPExStateLocal::MoveCursorL( |
|
160 CSIPExEngine* aContext, |
|
161 const TInt aNewPosition ) |
|
162 { |
|
163 aContext->SetCursor( aNewPosition ); |
|
164 } |
|
165 |
|
166 // End of file |