options.cpp

来自「Source code (C++) of the Amoebax game fo」· C++ 代码 · 共 567 行 · 第 1/2 页

CPP
567
字号
/// If the current level is already at max. value, this/// function does nothing.///voidOptions::incrementVolume (void){    uint8_t currentVolumeLevel = getVolumeLevel ();    if ( currentVolumeLevel < getMaxVolumeLevel () )    {        setIntegerValue ("sound", "volume", currentVolumeLevel + 1);    }}////// \brief Tells if the screen is configured in full screen mode.////// \return \a true if the video should be set in full screen mode,///         \a false otherwise.///boolOptions::isFullScreen (void){#if defined (IS_GP2X_HOST)    return true;#else // IS_GP2X_HOST    return getBooleanValue ("screen", "fullscreen", false);#endif // !IS_GP2X_HOST}////// \brief Tells if the score is a high score.////// \param score The score to check if it is high score./// \return true if the score is a high score, otherwise false.///boolOptions::isHighScore (uint32_t score){    return findScorePosition (score) != m_HighScore.end();}////// \brief Tells if the sound is enabled.////// \return \a true if the sound should be enabled, \a false otherwise.///boolOptions::isSoundEnabled (void){    return getBooleanValue ("sound", "enabled", true);}////// \brief Tells if all video options are at they default value.////// \return \a true if all video options (width, height, and depth) are///         at their default values.  \a false otherwise.///boolOptions::isVideoOptionsAtDefault (void){    return !isFullScreen () &&           k_ScreenDepth == getScreenDepth () &&           k_ScreenHeight == getScreenHeight () &&           k_ScreenWidth == getScreenWidth ();}////// \brief Loads the list of high score.///voidOptions::loadHighScoreList (void){    {        HighScore highScore;        highScore.first = getIntegerValue ("highscore", "0.score", 500);        highScore.second = getStringValue ("highscore", "0.name", "JACK");        m_HighScore.push_back (highScore);    }    {        HighScore highScore;        highScore.first = getIntegerValue ("highscore", "1.score", 400);        highScore.second = getStringValue ("highscore", "1.name", "MICHAEL");        m_HighScore.push_back (highScore);    }    {        HighScore highScore;        highScore.first = getIntegerValue ("highscore", "2.score", 300);        highScore.second = getStringValue ("highscore", "2.name", "JANE");        m_HighScore.push_back (highScore);    }    {        HighScore highScore;        highScore.first = getIntegerValue ("highscore", "3.score", 200);        highScore.second = getStringValue ("highscore", "3.name", "JOHN");        m_HighScore.push_back (highScore);    }    {        HighScore highScore;        highScore.first = getIntegerValue ("highscore", "4.score", 100);        highScore.second = getStringValue ("highscore", "4.name", "MICHAELLE");        m_HighScore.push_back (highScore);    }}////// \brief Save the high score list.///voidOptions::saveHighScoreList (void){    std::list<HighScore>::iterator currentScore;    uint16_t currentScoreIndex;    for ( currentScoreIndex = 0, currentScore = m_HighScore.begin ();          currentScore != m_HighScore.end ();          ++currentScoreIndex, ++currentScore )    {        std::string scoreSection;     	char stringvalue[20];
		sprintf(stringvalue, "%d.score",   currentScoreIndex);
		scoreSection.append(stringvalue);
		//scoreSection << currentScoreIndex << ".score";        setIntegerValue ("highscore", scoreSection, currentScore->first);        std::string nameSection;        //nameSection << currentScoreIndex << ".name";
		sprintf(stringvalue, "%d.name",   currentScoreIndex);
		nameSection.append(stringvalue);        setStringValue ("highscore", nameSection, currentScore->second);    }}////// \brief Sets the video options to their default value.///voidOptions::setDefaultVideoOptions (void){    setFullScreen (false);    setScreenDepth (k_ScreenDepth);    setScreenHeight (k_ScreenHeight);    setScreenWidth (k_ScreenWidth);}////// \brief Sets the defaults controls for the players.///voidOptions::setDefaultPlayersControls (void){    PlayerControls controls;    controls.controlsType = KeyboardControls;    controls.joystick.index = 0;    controls.joystick.moveLeft = -1;    controls.joystick.moveRight = 1;    controls.joystick.pushDown = 2;    controls.joystick.rotateClockwise = 0;    controls.joystick.rotateCounterClockwise = 1;    controls.keyboard.moveLeft = k_PlayersControls[0][0];    controls.keyboard.moveRight = k_PlayersControls[0][1];    controls.keyboard.pushDown = k_PlayersControls[0][2];    controls.keyboard.rotateClockwise = k_PlayersControls[0][3];    controls.keyboard.rotateCounterClockwise = k_PlayersControls[0][4];    setPlayerControls (IPlayer::LeftSide, controls);    controls.keyboard.moveLeft = k_PlayersControls[1][0];    controls.keyboard.moveRight = k_PlayersControls[1][1];    controls.keyboard.pushDown = k_PlayersControls[1][2];    controls.keyboard.rotateClockwise = k_PlayersControls[1][3];    controls.keyboard.rotateCounterClockwise = k_PlayersControls[1][4];    setPlayerControls (IPlayer::RightSide, controls);}////// \brief Sets the full screen mode.////// \param fullScreen If \a true, the video should be set in full screen mode,///                   otherwise it should be set to windowed mode.///voidOptions::setFullScreen (bool fullScreen){    setBooleanValue ("screen", "fullscreen", fullScreen);}////// \brief Sets a new high score.////// \param score The score to set a new high score./// \param name The name to set a new name's high score.///voidOptions::setHighScore (uint32_t score, const std::string &name){    std::list<HighScore>::iterator currentScore = findScorePosition (score);    if (currentScore != m_HighScore.end ())    {        HighScore highScore;        highScore.first = score;        highScore.second = name;        m_HighScore.insert (currentScore, highScore);        currentScore = m_HighScore.end ();        --currentScore;        m_HighScore.erase (currentScore);        saveHighScoreList ();    }}////// \brief Sets the player's controls.////// \param player The player to set the controls to./// \param controls The player's controls to set.///voidOptions::setPlayerControls (IPlayer::PlayerSide player,                            const Options::PlayerControls &controls){    const int playerIndex = static_cast<int> (player);    std::string sectionName (k_PlayersName[playerIndex] + "-controls");    setIntegerValue (sectionName, "type", static_cast<int> (controls.controlsType));    setIntegerValue (sectionName, "KeyMoveLeft", controls.keyboard.moveLeft);    setIntegerValue (sectionName, "KeyMoveRight", controls.keyboard.moveRight);    setIntegerValue (sectionName, "KeyPushDown", controls.keyboard.pushDown);    setIntegerValue (sectionName, "KeyRotateCW", controls.keyboard.rotateClockwise);    setIntegerValue (sectionName, "KeyRotateCCW", controls.keyboard.rotateCounterClockwise);    setIntegerValue (sectionName, "JoyIndex", controls.joystick.index);    setIntegerValue (sectionName, "JoyMoveLeft", controls.joystick.moveLeft);    setIntegerValue (sectionName, "JoyMoveRight", controls.joystick.moveRight);    setIntegerValue (sectionName, "JoyPushDown", controls.joystick.pushDown);    setIntegerValue (sectionName, "JoyRotateCW", controls.joystick.rotateClockwise);    setIntegerValue (sectionName, "JoyRotateCCW", controls.joystick.rotateCounterClockwise);}////// \brief Sets the screen depth to use.////// \param depth The depth to use when setting the screen resolution.///voidOptions::setScreenDepth (unsigned int depth){    setIntegerValue ("screen", "depth", depth);}////// \brief Sets the screen height to use.////// \param height The height to use when setting the screen resolution.///voidOptions::setScreenHeight (unsigned int height){    setIntegerValue ("screen", "height", height);}////// \brief Sets the screen width to use.////// \param width The width to use when setting the screen resolution.///voidOptions::setScreenWidth (unsigned int width){    setIntegerValue ("screen", "width", width);}////// \brief Enables or disables the sound subsystem.////// \param enabled \a true if the sound subsystem should be enabled.///                \a false otherwise.///voidOptions::setSoundEnabled (bool enabled){    setBooleanValue ("sound", "enabled", enabled);}

⌨️ 快捷键说明

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