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