|
1 /* |
|
2 * Copyright (c) 2005 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 |
|
20 // INCLUDE FILES |
|
21 #include "noughtsandcrossesappui.h" |
|
22 #include "noughtsandcrossesdocument.h" |
|
23 #include "noughtsandcrossesinformationandsettings.h" |
|
24 |
|
25 // ============================ MEMBER FUNCTIONS =============================== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CNoughtsAndCrossesDocument::NewL() |
|
29 // Two-phased constructor. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CNoughtsAndCrossesDocument* CNoughtsAndCrossesDocument::NewL( |
|
33 CEikApplication& aApp) |
|
34 { |
|
35 CNoughtsAndCrossesDocument* self = new (ELeave) CNoughtsAndCrossesDocument (aApp); |
|
36 CleanupStack::PushL (self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(); |
|
39 |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CNoughtsAndCrossesDocument::CNoughtsAndCrossesDocument() |
|
45 // C++ default constructor can NOT contain any code, that might leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CNoughtsAndCrossesDocument::CNoughtsAndCrossesDocument(CEikApplication& aApp) : |
|
49 CAknDocument(aApp) |
|
50 { |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CNoughtsAndCrossesDocument::ConstructL() |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CNoughtsAndCrossesDocument::ConstructL() |
|
59 { |
|
60 iSettings = new (ELeave) CNoughtsAndCrossesInformationAndSettings; |
|
61 |
|
62 CDictionaryStore* iniFile = Application()->OpenIniFileLC (CEikonEnv::Static()->FsSession()); |
|
63 |
|
64 if (iniFile->IsPresentL (Application()->AppDllUid())) |
|
65 { |
|
66 RDictionaryReadStream stream; |
|
67 stream.OpenLC (*iniFile, Application()->AppDllUid()); |
|
68 stream >> *iSettings; |
|
69 CleanupStack::PopAndDestroy(); |
|
70 } |
|
71 |
|
72 CleanupStack::PopAndDestroy (iniFile); |
|
73 |
|
74 if (iSettings->HumanTypeCross()) |
|
75 { |
|
76 iEngine = CNoughtsAndCrossesEngine::NewL (CNoughtsAndCrossesEngine::ECross); |
|
77 } |
|
78 else |
|
79 { |
|
80 iEngine = CNoughtsAndCrossesEngine::NewL (CNoughtsAndCrossesEngine::ENought); |
|
81 } |
|
82 |
|
83 if (!iSettings->HumanPlayFirst()) |
|
84 { |
|
85 MakeComputerMove(); |
|
86 } |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CNoughtsAndCrossesDocument::~CNoughtsAndCrossesDocument() |
|
91 // Destructor. |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 CNoughtsAndCrossesDocument::~CNoughtsAndCrossesDocument() |
|
95 { |
|
96 delete iEngine; |
|
97 delete iSettings; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CNoughtsAndCrossesDocument::CreateAppUiL() |
|
102 // Constructs CreateAppUi. |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 CEikAppUi* CNoughtsAndCrossesDocument::CreateAppUiL() |
|
106 { |
|
107 return new (ELeave) CNoughtsAndCrossesAppUi; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CNoughtsAndCrossesDocument::SetObserver() |
|
112 // |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CNoughtsAndCrossesDocument::SetObserver ( |
|
116 CNoughtsAndCrossesEngine::MObserver* aObserver) |
|
117 { |
|
118 iEngine->SetObserver (aObserver); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CNoughtsAndCrossesDocument::NewGame() |
|
123 // |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CNoughtsAndCrossesDocument::NewGame() |
|
127 { |
|
128 if (iSettings->HumanTypeCross()) |
|
129 { |
|
130 iEngine->StartNewGame (CNoughtsAndCrossesEngine::ECross); |
|
131 } |
|
132 else |
|
133 { |
|
134 iEngine->StartNewGame (CNoughtsAndCrossesEngine::ENought); |
|
135 } |
|
136 |
|
137 if (!iSettings->HumanPlayFirst()) |
|
138 { |
|
139 MakeComputerMove(); |
|
140 } |
|
141 iEngine->SetFirstMove(EFalse); |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // CNoughtsAndCrossesDocument::CanMove() |
|
146 // |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 TBool CNoughtsAndCrossesDocument::CanMove() const |
|
150 { |
|
151 return iEngine->CanMove(); |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CNoughtsAndCrossesDocument::MakeHumanMoveL() |
|
156 // |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 TBool CNoughtsAndCrossesDocument::MakeHumanMoveL(TInt aRow, TInt aColumn) |
|
160 { |
|
161 return iEngine->MakeHumanMoveL(aRow, aColumn); |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CNoughtsAndCrossesDocument::MakeComputerMove() |
|
166 // |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 TBool CNoughtsAndCrossesDocument::MakeComputerMove() |
|
170 { |
|
171 return iEngine->MakeComputerMove(); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // CNoughtsAndCrossesDocument::InformationAndSettings() |
|
176 // |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 CNoughtsAndCrossesInformationAndSettings& |
|
180 CNoughtsAndCrossesDocument::InformationAndSettings() |
|
181 { |
|
182 return *iSettings; |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CNoughtsAndCrossesDocument::InformationAndSettings() |
|
187 // |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 const CNoughtsAndCrossesInformationAndSettings& |
|
191 CNoughtsAndCrossesDocument::InformationAndSettings() const |
|
192 { |
|
193 return *iSettings; |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // CNoughtsAndCrossesDocument::SaveSettingsAndInformationL() |
|
198 // |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 void CNoughtsAndCrossesDocument::SaveSettingsAndInformationL() |
|
202 { |
|
203 CDictionaryStore* iniFile = Application()->OpenIniFileLC (CEikonEnv::Static()->FsSession()); |
|
204 |
|
205 iniFile->RemoveL (Application()->AppDllUid()); |
|
206 |
|
207 RDictionaryWriteStream stream; |
|
208 |
|
209 stream.AssignLC (*iniFile, Application()->AppDllUid()); |
|
210 stream << *iSettings; |
|
211 stream.CommitL(); |
|
212 CleanupStack::PopAndDestroy(); // stream |
|
213 |
|
214 iniFile->Commit(); |
|
215 |
|
216 CleanupStack::PopAndDestroy (iniFile); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // CNoughtsAndCrossesDocument::Board() |
|
221 // |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 const CNoughtsAndCrossesDocument::TBoard& CNoughtsAndCrossesDocument::Board() const |
|
225 { |
|
226 return iEngine->Board(); |
|
227 } |
|
228 |
|
229 // End of File |