Blame view

ios/Runner/Wowgame/Classes/game_toy/ToySubGameScene.h 3.51 KB
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  //
  //  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<std::string> 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<int, Item*> items;
              int currentLevel;
              int currentItemTypeIndex;
              std::vector<ItemType> 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 */