📄 mopoidlevels.cpp
字号:
/*
* ============================================================================
* Name : CMopoidLevels from MopoidLevels.cpp
* Part of : Mopoid
* Created : 16.01.2004 by Andreas Jakl / Mopius - http://www.mopius.com/
* Description:
* Loads and manages level definitions.
* Version : 1.02
* Copyright:
* 'Mopoid' is free software; you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* 'Mopoid' is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 'Mopoid'; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* ============================================================================
*/
#include "MopoidLevels.h"
void CMopoidLevels::ParseLevelFileL()
{
TFileName fullName(KLevelsDataFile);
CompleteWithAppPath(fullName);
#ifdef __WINS__
fullName[0] = 'C';
#endif
HBufC8* sourceFile8 = ReadFileL(fullName);
CleanupStack::PushL(sourceFile8);
// parse file
TLex8 lex(sourceFile8->Des());
const TChar KNewLine = 0x000A; // Newline (UNIX!)
TInt length = 0;
TInt curLevel = 0;
TInt curLine = 0;
do
{
// Get the next line
TPtrC8 curString8 = ExtractToken(lex, KNewLine);
// Finished?
length = curString8.Length();
if (length == 0 || length != GRID_COLS)
break;
for (TInt i=0; i < GRID_COLS; i++)
{
TBrick::TBrickType curBrick = TBrick::EBrickInactive;
switch (curString8[i])
{
case '1':
curBrick = TBrick::EBrickNormal;
break;
case '2':
curBrick = TBrick::EBrickDouble;
break;
case '8':
curBrick = TBrick::EBrickInvisible;
break;
case '9':
curBrick = TBrick::EBrickIndestructible;
break;
}
iLevels[curLevel][i][curLine] = curBrick;
}
curLine++;
if (curLine >= GRID_ROWS)
{
curLine = 0;
curLevel ++;
}
} while (length > 0);
CleanupStack::PopAndDestroy(sourceFile8);
}
HBufC8* CMopoidLevels::ReadFileL(const TDesC& inPath)
{
RFs fsSession;
User::LeaveIfError(fsSession.Connect());
CleanupClosePushL(fsSession);
// We have to read the file content and put it in <iMadData>
// Let's open the file
RFile theFile;
User::LeaveIfError(theFile.Open(fsSession, inPath, EFileShareReadersOnly | EFileRead));
CleanupClosePushL(theFile);
// Get the file length
TInt fileLength;
User::LeaveIfError(theFile.Size(fileLength));
// Allocates the memory to read the whole file (and pushes it on CleanupStack)
HBufC8* theData = HBufC8::NewLC(fileLength);
// Creates a dummy descriptor for the Read method
TPtr8 theDescriptor(theData->Des());
// Reads the whole file in our buffer
User::LeaveIfError(theFile.Read(theDescriptor));
// We clean our CleanupStack
CleanupStack::Pop(theData);
// OK, we can Close and destroy the RFile
CleanupStack::PopAndDestroy(1);
CleanupStack::PopAndDestroy(1); // fsSession
// Returns the allocated data
return theData;
}
TPtrC8 CMopoidLevels::ExtractToken(TLex8& aLex, const TChar aSeparator)
{
aLex.Mark();
const TInt index = aLex.Remainder().Locate(aSeparator);
if (index == KErrNotFound)
{
aLex.Inc(aLex.Remainder().Length());
}
else
{
aLex.Inc(index);
}
TPtrC8 result = aLex.MarkedToken();
aLex.Inc();
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -