00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef GAME_STATE_H
00010 #define GAME_STATE_H
00011
00012
00013 #include "IObservable.h"
00014 #include <iostream>
00015 #include <string>
00016
00017 using namespace std;
00018
00019 static string names[8]={"INIT","MAIN_MENU","NEW_GAME","HIT_BALL","ANIMATION","PAUSE","PAUSE","BALL_IN_HOLE"};
00020
00021 class GameState: public IObservable
00022 {
00023 public:
00024 enum State
00025 {
00026 BEFORE_GAME = -1,
00027 INIT = 0,
00028 MAIN_MENU = 1,
00029 NEW_GAME,
00030 HIT_BALL,
00031 ANIMATION,
00032 PAUSE_HIT,
00033 PAUSE_ANI,
00034 BALL_IN_HOLE
00035 };
00036
00037
00038
00039 static GameState *getInstance()
00040 {
00041 if (instance == NULL)
00042 {
00043 instance = new GameState();
00044 }
00045 return instance;
00046 }
00047
00048
00049 void setCurrentState(State state)
00050 {
00051 if (this->currentState!=state)
00052 {
00053 this->currentState = state;
00054 std::cout<<"STATE:: "<<names[currentState]<<'\n';
00055 this->notifySubscribers();
00056 }
00057
00058 }
00059
00060 State getCurrentState ()
00061 {
00062 return this->currentState;
00063 }
00064
00065
00066
00067 private:
00068 static GameState *instance;
00069 State currentState;
00070 GameState()
00071 {
00072 currentState = BEFORE_GAME ;
00073
00074 };
00075
00076 GameState(const GameState&);
00077
00078 };
00079
00080 #endif