⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 twogp2xplayersstate.cpp

📁 Source code (C++) of the Amoebax game for Symbian OS UIQ3.x。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//// Cross-platform free Puyo-Puyo clone.// Copyright (C) 2006, 2077 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 "Amoeba.h"#include "DrawAmoeba.h"#include "File.h"#include "IMatchObserver.h"#include "System.h"#include "TwoGP2XPlayersState.h"using namespace Amoebax;/// The size of the silhouettes' border in pixels.static const uint8_t k_SilhouetteBorder = 2;////// \brief Default constructor.///TwoGP2XPlayersState::TwoGP2XPlayersState (const std::string &backgroundFileName,                                          uint32_t leftPlayerScore,                                          uint32_t rightPlayerScore,                                          IMatchObserver *observer):    IState (),    m_AmoebasLeft (0),    m_AmoebasRight (0),    m_AmoebasSize (k_MaxAmoebasSize),    m_Background (0),    m_BackgroundFileName (backgroundFileName),    m_BackgroundMusic (0),    m_GameIsOver (false),    m_Generator (new PairGenerator ()),    m_Go (0),    m_GoTime (k_DefaultGoTime),    m_LeftGrid (new Grid (static_cast<uint16_t>(k_PositionXLeftGrid),                          static_cast<uint16_t>(k_PositionYLeftGrid),                          static_cast<uint16_t>(k_PositionXLeftQueue),                          static_cast<uint16_t>(k_PositionYLeftQueue),                          static_cast<uint16_t>(k_PositionXLeftWaiting),                          static_cast<uint16_t>(k_PositionYLeftWaiting),                          getAmoebaSize (), Grid::QueueSideLeft,                          leftPlayerScore, Grid::LayoutHorizontal)),    m_Observer (observer),    m_Ready (0),    m_ReadyTime (k_DefaultGoTime * 2),    m_RightGrid (new Grid (static_cast<uint16_t>(k_PositionXRightGrid),                           static_cast<uint16_t>(k_PositionYRightGrid),                           static_cast<uint16_t>(k_PositionXRightQueue),                           static_cast<uint16_t>(k_PositionYRightQueue),                           static_cast<uint16_t>(k_PositionXRightWaiting),                           static_cast<uint16_t>(k_PositionYRightWaiting),                           getAmoebaSize (), Grid::QueueSideRight,                           rightPlayerScore, Grid::LayoutHorizontal)),    m_ScoreFont (0),    m_SilhouetteBorder (k_SilhouetteBorder),    m_SilhouettesLeft (0),    m_SilhouettesRight (0),    m_StateAlreadyRemoved (false),    m_Winner (IPlayer::RightSide),    m_WinnerLoser (0){    assert ( 0 < getAmoebasSize () && "The amoeba's size is invalid." );    loadGraphicsResources ();    // Add the grids to the pair generator and then generate 4 pairs.    m_Generator->addGrid (getLeftGrid ());    m_Generator->addGrid (getRightGrid ());    m_Generator->generate (4);    // Load music.    std::string musicFileName (backgroundFileName);    musicFileName.replace (musicFileName.rfind (".png"), 4, ".ogg");    m_BackgroundMusic.reset (            Music::fromFile (File::getMusicFilePath (musicFileName)));}////// \brief Destructor.///TwoGP2XPlayersState::~TwoGP2XPlayersState (void){}voidTwoGP2XPlayersState::activate (void){    if ( Music::isPaused () )    {        Music::resume ();    }    else    {        m_BackgroundMusic->play ();    }}////// \brief Tells if the game is over.////// The game is over when one or both grids is filled up.////// \return \a true when at least one grid is filled up, \a false otherwise.///inline boolTwoGP2XPlayersState::gameIsOver (void) const{    return m_GameIsOver;}////// \brief Gets the size of the amoebas.////// \return The size of a single amoeba. All amoebas are squared, so///         their width and height are equal.///inline uint8_tTwoGP2XPlayersState::getAmoebaSize (void) const{    return m_AmoebasSize;}////// \brief Gets the time to display the "Go!" label.////// \return The time that the "Go!" label should be visible.///inline int32_tTwoGP2XPlayersState::getGoTime (void) const{    return m_GoTime;}////// \brief Gets the left grid.////// \return The pointer to the left grid.///inline Grid *TwoGP2XPlayersState::getLeftGrid (void){    return m_LeftGrid.get ();}////// \brief Gets the left player's score.////// \return The score of the left player.///inline uint32_tTwoGP2XPlayersState::getLeftPlayerScore (void){    return getLeftGrid ()->getScore ();}////// \brief Gets the time to display the "Ready?" label.////// \return The time that the "Ready?" label should be visible.///inline int32_tTwoGP2XPlayersState::getReadyTime (void) const{    return m_ReadyTime;}////// \brief Gets the right grid.////// \return The pointer to the right grid.///inline Grid *TwoGP2XPlayersState::getRightGrid (void){    return m_RightGrid.get ();}////// \brief Gets the right player's score.////// \return The score of the right player.///inline uint32_tTwoGP2XPlayersState::getRightPlayerScore (void){    return getRightGrid ()->getScore ();}////// \brief Gets the size of the silhouettes' border.////// \return The size of the silhouettes's border.///inline uint8_tTwoGP2XPlayersState::getSilhouetteBorder (void) const{    return m_SilhouetteBorder;}////// \brief Gets the winner's side.////// \return The side whose player is the winner.///inline IPlayer::PlayerSideTwoGP2XPlayersState::getWinnerSide (void) const{    return m_Winner;}voidTwoGP2XPlayersState::joyMotion (uint8_t joystick, uint8_t axis, int16_t value){}voidTwoGP2XPlayersState::joyDown (uint8_t joystick, uint8_t button){    if ( gameIsOver () )    {        if ( GP2X_BUTTON_START == button && !m_StateAlreadyRemoved )        {            System::getInstance ().removeActiveState ();            m_StateAlreadyRemoved = true;        }    }    else    {        switch (button)        {            case GP2X_BUTTON_A:                getRightGrid ()->rotateClockwise ();            break;            case GP2X_BUTTON_B:                getRightGrid ()->setMaxFallingSpeed ();            break;            case GP2X_BUTTON_X:                getRightGrid ()->moveLeft ();            break;            case GP2X_BUTTON_Y:                getRightGrid ()->moveRight ();            break;            case GP2X_BUTTON_START:                System::getInstance ().pause ();            break;            case GP2X_BUTTON_RIGHT:            case GP2X_BUTTON_CLICK:                getLeftGrid ()->rotateClockwise ();            break;            case GP2X_BUTTON_LEFT:                getLeftGrid ()->setMaxFallingSpeed ();            break;            case GP2X_BUTTON_UP:            case GP2X_BUTTON_UPRIGHT:                getLeftGrid ()->moveLeft ();            break;            case GP2X_BUTTON_DOWN:            case GP2X_BUTTON_DOWNRIGHT:                getLeftGrid ()->moveRight ();            break;        }    }}voidTwoGP2XPlayersState::joyUp (uint8_t joystick, uint8_t button){    switch (button)    {        case GP2X_BUTTON_B:            getRightGrid ()->setNormalFallingSpeed ();        break;        case GP2X_BUTTON_LEFT:            getLeftGrid ()->setNormalFallingSpeed ();        break;    }}////// \brief Loads all graphical resources.///voidTwoGP2XPlayersState::loadGraphicsResources (void){    m_AmoebasLeft.reset (            Surface::fromFile (File::getGraphicsFilePath ("leftgrid-gp2x.png")));    m_AmoebasRight.reset (            Surface::fromFile (File::getGraphicsFilePath ("rightgrid-gp2x.png")));    m_Background.reset (            Surface::fromFile (File::getGraphicsFilePath (m_BackgroundFileName)));    {        std::auto_ptr<Surface> grid (                Surface::fromFile (File::getGraphicsFilePath ("twoplayers-gp2x.png")));        grid->blit (m_Background->toSDLSurface ());    }    m_SilhouettesLeft.reset (Surface::fromFile (                File::getGraphicsFilePath ("leftsilhouettes-gp2x.png")));    m_SilhouettesRight.reset (Surface::fromFile (                File::getGraphicsFilePath ("rightsilhouettes-gp2x.png")));    setSilhouetteBorder (k_SilhouetteBorder);    m_WinnerLoser.reset (            Surface::fromFile (File::getGraphicsFilePath ("winnerloser-gp2x.png")));    m_ScoreFont.reset (Font::fromFile (File::getFontFilePath ("score")));    // Load the "Go!" and "Ready?" labels only if they are going to be shown.    if ( mustShowInitialLabels () )    {        m_Go.reset (                Surface::fromFile (File::getGraphicsFilePath ("go-gp2x.png")));        m_Ready.reset (                Surface::fromFile (File::getGraphicsFilePath ("ready-gp2x.png")));    }}////// \brief Tells if the "Go!!" label should be displayed.////// \return \a true If the "Go!!" label should be displayed,///         \a false otherwise.///inline boolTwoGP2XPlayersState::mustShowGoLabel (void) const{    return getGoTime () > 0;}////// \brief Tells if either the "Go!!" or the "Ready?" labels should be shown.////// \return \a true if either label must be displayed, \a false otherwise.///inline boolTwoGP2XPlayersState::mustShowInitialLabels (void) const{

⌨️ 快捷键说明

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