// // ToySubGameScene.h // SteveAndMaggieGame // // Created by Katarzyna Kalinowska-Górska on 07/05/2019. // #ifndef ToySubGameScene_h #define ToySubGameScene_h #include "ToyParentScene.h" #include "audio/include/AudioEngine.h" #include "ToyGameLifeIndicatorView.h" #include "ToySettingsLayer.h" class ToySubGameScene : public ToyParentScene { public: class GameCreator { public: virtual ToySubGameScene* createGameScene(int gameId,std::string layoutFilePath) = 0; }; struct CommonConfig { std::vector itemPicturePaths; int maxItemsAtATime; int screenPadding; float maxSecondsInactivity; int lives; }; virtual void onEnter() override; // virtual void onExit() override; // virtual void onEnterTransitionDidFinish() override; virtual bool initWithConfiguration(std::string layoutFilePath, CommonConfig commonConfig); virtual ~ToySubGameScene(); virtual void pauseGame() = 0; virtual void resumeGame() = 0; virtual void presentGameResumeLayer(); protected: enum class PlayState { INIT, PRE_PLAYING, PLAYING, CHANGING_LEVEL, LOST, WON }; enum class ItemType : int { NONE = 0, ONE = 1, TWO = 2, THREE = 3, FOUR = 4 }; class Item { public: cocos2d::Sprite* sprite; cocos2d::Rect rect; ItemType type; bool operator==(const Item& item2) { if(sprite == nullptr || item2.sprite == nullptr){ return false; } return sprite->getTag() == item2.sprite->getTag(); } virtual ~Item(){ if(sprite != nullptr){ sprite->removeFromParent(); } } }; // state variables class GameState { public: PlayState playState; bool settingsMenuShown; bool tosAcceptMenuShown; std::map items; int currentLevel; int currentItemTypeIndex; std::vector itemTypeOrder; //the order of the types to catch (shuffled randomly at the beginning of each level) bool itemVanishingMode; float timeCount; float lossTimeCount; bool lossHalfTime; int wrongItemCount; virtual ~GameState(){} }; GameState* gameState; CommonConfig commonConfig; // CocosDenshion::SimpleAudioEngine* soundEngine; ToyGameLifeIndicatorView* lifeIndicatorView; ToySettingsLayer* settingsMenu; virtual void addLivesIndicatorView(); virtual GameState* createGameState(); virtual void removeGameState(); virtual void clearGameState(); virtual void clearAllItems(); virtual bool generateItemTypeAndId(ItemType& itemType, int& itemId, std::string& itemPicturePath, ItemType preferredType = ItemType::NONE); virtual std::string generateItemPicPathForType(ItemType itemType); virtual bool touchHandlerForWidget(std::string objectName, cocos2d::ui::Widget::TouchEventType touchEventType) override; virtual bool onPrevLevelButtonClicked(); virtual bool onReplayButtonClicked(); virtual bool onNextLevelButtonClicked(); virtual bool onFastForwardButtonClicked(); virtual void startGame(bool playIntro = true) = 0; virtual void gameWon(); virtual void gameLost(); virtual void resetGame(); }; #endif /* ToySubGameScene_h */