有什么比使用静态整数更好的信息存储方式? C ++
|
我通过将玩家的工作设置为数字来跟踪他的“工作”,如果改变工作将其递增一个,并通过数字是偶数还是奇数来确定他当前所从事的工作。 (现在只有两项工作)。但是,我知道这样做的更好方法,很快我将需要执行第三和第四项工作,因此我无法继续使用偶/奇检查。
这是我的代码供参考:(请注意,我只包含相关代码)
GameModeState.cpp
// If changeJob\'s parameter number is 1, it increments the job. If number is 2, it only returns the current job
int GameModeState::changeJob(int number)
{
// Default job is even (landman)
static int job = 1;
if (number == 1)
{
job = (job+1);
return job;
}
else
{
return job;
}
}
int GameModeState::getJob()
{
int currentJob = (changeJob(2));
return currentJob;
}
// If the player opens the \"stat sheet\", it changes their job
void GameModeState::_statSheet(const String& message, const Awesomium::JSValue& input, Awesomium::JSValue& output)
{
changeJob(1);
}
GameModeState.h
class GameModeState : public GameState::State
{
public:
/// Changes the player\'s job if number is 1, or returns current job if number is 2
static int changeJob(int number);
/// Returns the current job number by calling changeJob appropriately
static int getJob();
private:
// Opening the player sheet will change the player\'s job
void _statSheet(const String& message, const Awesomium::JSValue& input, Awesomium::JSValue& output);
};
ZoneMovementState.cpp(这是我检查当前作业的位置)
#include \"GameModeState.h\"
#include <EnergyGraphics/ZoneParser.h>
void ZoneMovementState::_changeZone(const String& message, const Awesomium::JSValue& input, Awesomium::JSValue& output)
{
// If the number from getJob is even, the player is currently a geologist
if (GameModeState::getJob()%2 == 0)
{
ZoneParser::getSingleton().load(\"../media/zones/geology_zone.xml\", false);
}
else //otherwise they are a landman
{
ZoneParser::getSingleton().load(\"../media/zones/landman_zone.xml\", false);
}
transitionHandler->go();
}
我认为作业的数组或枚举将是处理此问题的更好方法,但是我不确定如何将其实现到我的代码中。如果您知道更好的方法,请提供示例或至少指向正确方向的一点。我将不胜感激!
没有找到相关结果
已邀请:
3 个回复
柑恫祟
另外,我会考虑以某种方式将此类“与工作相关”的东西组织到某种数组或列表中,或将其更容易地称为“与工作相关的”东西:
惭法搽
艾食魄轻县