1 // Brain Party 2 // Copyright (C) 2010 Paul Hudson (http://www.tuxradar.com/brainparty) 3 4 // Brain Party is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU General Public License 6 // as published by the Free Software Foundation; either version 3 7 // of the License, or (at your option) any later version. 8 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 18 #ifndef __MINIGAME_H__ 19 #define __MINIGAME_H__ 20 21 #include <vector> 22 #include <algorithm> 23 #include <map> 24 #include <string> 25 26 #include "BPGame.h" 27 #include "BPPoint.h" 28 #include "SpriteFont.h" 29 #include "BPList.h" 30 31 enum RankTypes { NONE, FAIL, BRONZE, SILVER, GOLD, PLATINUM }; // "NONE" is required, otherwise the default is "FAIL" 32 enum MiniGameStates { SHOWING, GUESSING, PAUSING, THINKING, WAITING, CHANGING, MOVES, MOVING, REMEMBER, CORRECT, WRONG, SUCCESS, FAILURE, FADE_IN, FADE_OUT }; 33 enum MiniGameTypes { PUZZLE, LIVELY, ACTION }; 34 enum ReturnTypes { RT_NORMAL, RT_SECRET, RT_BRAINBOOST }; 35 36 class BPGame; 37 class SpriteFont; 38 39 40 class BPMiniGame_BGStar { 41 public: 42 int Type; 43 float Speed; 44 BPPoint Pos; 45 }; 46 47 48 49 class BPMiniGame { 50 public: 51 ReturnTypes ReturnType; // controls which game screens return to y 52 int FinishedTime; // set to Environment.TickCount when game should no longer have Tick() called 53 const char* GameTitle; 54 const char* GameHelp; 55 const char* GameHelp2; 56 57 SpriteFont* sfcGameTitle; 58 SpriteFont* sfcGameHelp; 59 MiniGameTypes MiniGameType; 60 61 62 int FinalWeight; 63 RankTypes FinalRank; 64 const char* FinalGrade; 65 66 SpriteFont* sfcFinalWeight; 67 SpriteFont* sfcFinalGrade; 68 69 BPPoint TouchEvent; 70 71 BPGame* TheGame; 72 73 BPMiniGame(BPGame* game); 74 virtual ~BPMiniGame(); 75 void Init(); // called after the constructor so that any descendent constructors have finished 76 virtual void Start() = 0; 77 virtual int GetWeight() = 0; 78 virtual void SetMarathon(); 79 static RankTypes GetRank(int Weight); 80 const char* GetGrade(int Weight); 81 void TickMiniGame(); 82 void RenderMiniGame(); 83 void RenderScore(); 84 85 virtual void OnMouseDown() = 0; 86 virtual void OnMouseUp() = 0; 87 virtual void OnMouseMove() = 0; 88 89 void HandleMouseUp(BPPoint e); 90 void HandleMouseDown(BPPoint e); 91 void HandleMouseMove(BPPoint e); 92 93 void DrawProfessorText(); 94 void PlayMusic(); 95 96 protected: 97 static const int MiniGameWidth = 320; 98 static const int MiniGameHalfWidth = 160; 99 static const int MiniGameHeight = 480; // note: needs to be screen height minus the height of the info bar 100 static const int MiniGameHalfHeight = 240; 101 102 bool RedrawClock(); 103 104 virtual void Render() = 0; 105 virtual void Tick() = 0; 106 107 void Success(); 108 void Failure(); 109 void CalculateResult(); 110 void ContinueGame(); 111 void GoBack(); 112 void ShowHelp(); 113 int DivRem(int Num, int Div, int &Rem); 114 int Round(double num); 115 int MinMax(int num); 116 void RenderCorrect(); 117 void RenderWrong(); 118 void GenerateStarfield(BPPList<BPMiniGame_BGStar*> &list); 119 void UpdateStarfield(BPPList<BPMiniGame_BGStar*> &list); 120 void DrawStarfield(BPPList<BPMiniGame_BGStar*> &list); 121 122 bool MarathonMode; // used by some games to hide/stop the timer so players can play as long as they want to 123 124 private: 125 bool InTick; 126 bool BackDown; 127 bool HelpDown; 128 int WantToQuit; 129 }; 130 131 #endif 132