options.cpp

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

CPP
567
字号
//// Cross-platform free Puyo-Puyo clone.// Copyright (C) 2006, 2007 Emma's Software//// This program 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.//// This program 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 this program; if not, write to the Free Software// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.//#if defined (HAVE_CONFIG_H)#include <config.h>#endif // HAVE_CONFIG_H#include <SDL.h>#include <sstream>#include "Options.h"#if defined (IS_OSX_HOST)#include "OSXOptions.h"#elif defined (IS_WIN32_HOST)#include "Win32Options.h"#else // IS_OSX_HOST#include "UnixOptions.h"#endif // !IS_OSX_PATHusing namespace Amoebax;// Default player's controlsstatic const uint32_t k_PlayersControls[2][5] ={    // Left player    {        SDLK_a,                 // Move left.        SDLK_d,                 // Move right.        SDLK_s,                 // Push down.        SDLK_w,                 // Rotate clockwise.        SDLK_LCTRL              // Rotate counter-clockwise    },    // Right player.    {        SDLK_LEFT,              // Move left.        SDLK_RIGHT,             // Move right.        SDLK_DOWN,              // Push down.        SDLK_UP,                // Rotate clockwise.
#ifdef UIQ3
        SDLK_F5              // Rotate counter-clockwise.
#else        SDLK_RCTRL              // Rotate counter-clockwise.
#endif    }};// Player's names.static std::string k_PlayersName[2] ={    std::string ("leftPlayer"),    std::string ("rightPlayer")};// Default screen's bits per pixel.static const unsigned int k_ScreenDepth = 0;// Default screen's height.static const unsigned int k_ScreenHeight = 600;// Default screen's width.static const unsigned int k_ScreenWidth = 800;// Default volume level.static const int k_VolumeLevel = 5;// Maximum volume level.static const int k_VolumeLevelMax = 10;////// \brief Default Options constructor.///Options::Options (void){}////// \brief Options destructor.///Options::~Options (void){}////// \brief Decrement the current volume level.////// If the current volume level is already 0, this function does nothing.///voidOptions::decrementVolume (void){    uint8_t currentVolumeLevel = getVolumeLevel ();    if ( currentVolumeLevel > 0 )    {        setIntegerValue ("sound", "volume", currentVolumeLevel - 1);    }}////// \brief Finds the position of an score in the list of high scores.////// \param score The score to find its position in the list./// \return The position that the score should be in the list.///std::list<HighScore>::iteratorOptions::findScorePosition (uint32_t score){    std::list<HighScore>::iterator currentScore;    for (currentScore = m_HighScore.begin();         currentScore != m_HighScore.end();         ++currentScore)    {        if ( score > currentScore->first )        {            break;        }    }    return currentScore;}////// \brief Gets the high score list.////// \return The list of high score.///std::list<HighScore> &Options::getHighScoreList (void){    return m_HighScore;}////// \brief Gets the only available instace of Options.////// \return The only instance of options.///Options &Options::getInstance (void){#if defined (IS_OSX_HOST)    static OSXOptions options;#elif defined (IS_WIN32_HOST)    static Win32Options options;#else // IS_OSX_HOST    static UnixOptions options;#endif // !IS_OSX_HOST    static bool firstCall = true;    if ( firstCall )    {        options.loadHighScoreList ();        firstCall = false;    }    return options;}////// \brief Gets the maximum volume level.////// \return The value of the maximum sound volume level.///unsigned intOptions::getMaxVolumeLevel (void){    return k_VolumeLevelMax;}////// \brief Gets the player's controls.////// \param player The player to get the controls from./// \return The player's controls.///Options::PlayerControlsOptions::getPlayerControls (IPlayer::PlayerSide player){    const int playerIndex = static_cast<int> (player);    Options::PlayerControls playerControls;    std::string sectionName (k_PlayersName[playerIndex] + "-controls");    playerControls.controlsType = static_cast<ControlsType> (        getIntegerValue (sectionName, "type",                         static_cast<int> (KeyboardControls)));    playerControls.keyboard.moveLeft =        getIntegerValue (sectionName, "KeyMoveLeft",                         k_PlayersControls[playerIndex][0]);    playerControls.keyboard.moveRight =        getIntegerValue (sectionName, "KeyMoveRight",                         k_PlayersControls[playerIndex][1]);    playerControls.keyboard.pushDown =        getIntegerValue (sectionName, "KeyPushDown",                         k_PlayersControls[playerIndex][2]);    playerControls.keyboard.rotateClockwise =        getIntegerValue (sectionName, "KeyRotateCW",                         k_PlayersControls[playerIndex][3]);    playerControls.keyboard.rotateCounterClockwise =        getIntegerValue (sectionName, "KeyRotateCCW",                         k_PlayersControls[playerIndex][4]);    playerControls.joystick.index =        getIntegerValue (sectionName, "JoyIndex", 0);    playerControls.joystick.moveLeft =        getIntegerValue (sectionName, "JoyMoveLeft", -1);    playerControls.joystick.moveRight =        getIntegerValue (sectionName, "JoyMoveRight", 1);    playerControls.joystick.pushDown =        getIntegerValue (sectionName, "JoyPushDown", 2);    playerControls.joystick.rotateClockwise =        getIntegerValue (sectionName, "JoyRotateCW", 0);    playerControls.joystick.rotateCounterClockwise =        getIntegerValue (sectionName, "JoyRotateCCW", 1);    return playerControls;}////// \brief Gets the screen depth to use.////// \return The depth to use when setting the screen resolution.///unsigned intOptions::getScreenDepth (void){#if defined (IS_GP2X_HOST)    return 16;#else   // IS_GP2X_HOST    return getIntegerValue ("screen", "depth", k_ScreenDepth);#endif  // !IS_GP2X_HOST}////// \brief Gets the screen height to use.////// \return The height to use when setting the screen resolution.///unsigned intOptions::getScreenHeight (void){#if defined (IS_GP2X_HOST)    return 240;#else // IS_GP2X_HOST    return getIntegerValue ("screen", "height", k_ScreenHeight);#endif // !IS_GP2X_HOST}////// \brief Gets the screen width to use.////// \return The width to use when setting the screen resolution.///unsigned intOptions::getScreenWidth (void){#if defined (IS_GP2X_HOST)    return 320;#else // IS_GP2X_HOST    return getIntegerValue ("screen", "width", k_ScreenWidth);#endif // !IS_GP2X_HOST}////// \brief Gets the current volume level.////// \return The current level of the volume, from 0 to getMaxVolumeLevel().///unsigned intOptions::getVolumeLevel (void){    return getIntegerValue ("sound", "volume", k_VolumeLevel);}////// \brief Incrememts the current volume level.///

⌨️ 快捷键说明

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