icebloxx.cpp

来自「Source code (C++) of the Icebloxx game f」· C++ 代码 · 共 103 行

CPP
103
字号
/*
 * Copyright (C) 2002 Robert Ernst <robert.ernst@linux-solutions.at>
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See COPYING for GPL licensing information.
 *
 */

#include "PlayField.h"
#include "Icebloxx.h"
#include <stdlib.h>
#include <time.h>
#include <eikenv.h>
#include <eikappui.h>
#include <eikapp.h>
const TUid KIceBloxxSettings = {0x12341280};
Icebloxx::Icebloxx(CIceBloxxView * aParent, const char * /*name*/, TInt /*f*/) 
{
    /* initialize random number generator */
    srand(::time(0));

    /* create the play field as the central widget */
	m_speed = 6;
	m_strength = 12;
	m_coins = 5;
    m_field = new PlayField(aParent);

    /* read the configuration file */
    readConfig();

}

Icebloxx::~Icebloxx()
{
	delete m_field;
}

void Icebloxx::readConfig(void)
{
	CEikonEnv* env=CEikonEnv::Static();
	CDictionaryStore* iniFile = env->EikAppUi()->Application()->OpenIniFileLC(env->FsSession());
	if (iniFile->IsPresentL(KIceBloxxSettings))
	{
		RDictionaryReadStream	readStream;
		readStream.OpenLC(*iniFile, KIceBloxxSettings);
		m_speed= readStream.ReadInt32L();
		m_strength= readStream.ReadInt32L();
		m_coins= readStream.ReadInt32L();
		m_field->InternalizeL(readStream);
		CleanupStack::PopAndDestroy();//readStream
	}
	CleanupStack::PopAndDestroy(); // iniFile		

    m_field->updateSpeed(m_speed);

    m_field->updateStrength(m_strength);
 
    m_field->updateCoins(m_coins);	
}

void Icebloxx::writeConfig(void)
{
	CEikonEnv* env=CEikonEnv::Static();
	CDictionaryStore* iniFile = env->EikAppUi()->Application()->OpenIniFileLC(env->FsSession());
	RDictionaryWriteStream writeStream;
	writeStream.AssignLC(*iniFile, KIceBloxxSettings);
	writeStream.WriteInt32L(m_speed);
	writeStream.WriteInt32L(m_strength);
	writeStream.WriteInt32L(m_coins);
	m_field->ExternalizeL(writeStream);
	writeStream.CommitL();
	CleanupStack::PopAndDestroy(); // writeStream
	iniFile->CommitL();
	CleanupStack::PopAndDestroy(); // iniFile			

}

void Icebloxx::updateSpeed(int speed)
{
    m_speed = speed;
    writeConfig();
}

void Icebloxx::updateStrength(int strength)
{
    m_strength = strength;
    writeConfig();
}

void Icebloxx::updateCoins(int coins)
{
    m_coins = coins;
    writeConfig();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?