Game Class Reference

#include <game.h>

Collaboration diagram for Game:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void Start ()
void UnloadDatas ()
bool IsGameFinished ()
bool IsGameLaunched () const
void MessageLoading ()
void MessageEndOfGame ()
int AskQuestion (Question &question, bool draw=true)
void Pause ()
bool GetEndOfGameStatus ()
void SetEndOfGameStatus (bool status)

Static Public Member Functions

static GameGetInstance ()

Private Member Functions

int NbrRemainingTeams ()
 Game ()

Private Attributes

bool isGameLaunched
bool endOfGameStatus

Static Private Attributes

static Gamesingleton = NULL

Detailed Description

Definition at line 29 of file game.h.


Constructor & Destructor Documentation

Game::Game (  )  [private]

Definition at line 60 of file game.cpp.

00061 {
00062   isGameLaunched = false;
00063   endOfGameStatus = false;
00064 }

Here is the caller graph for this function:


Member Function Documentation

int Game::AskQuestion ( Question question,
bool  draw = true 
)

Definition at line 117 of file game.cpp.

00118 {
00119   Time * global_time = Time::GetInstance();
00120   global_time->Pause();
00121 
00122   if (draw)
00123     GameLoop::GetInstance()->Draw ();
00124 
00125   int answer = question.Ask ();
00126 
00127   global_time->Continue();
00128   return answer;
00129 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Game::GetEndOfGameStatus (  ) 

Definition at line 235 of file game.cpp.

00235                              {
00236   return endOfGameStatus;
00237 }

Game * Game::GetInstance (  )  [static]

Definition at line 51 of file game.cpp.

00052 {
00053   if (singleton == NULL) {
00054     singleton = new Game();
00055   }
00056   return singleton;
00057 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Game::IsGameFinished (  ) 

Definition at line 66 of file game.cpp.

00067 {
00068   return (NbrRemainingTeams() <= 1);
00069 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Game::IsGameLaunched (  )  const

Definition at line 231 of file game.cpp.

00231                                {
00232   return isGameLaunched;
00233 }

void Game::MessageEndOfGame (  ) 

Definition at line 89 of file game.cpp.

00090 {
00091   std::vector<TeamResults*>* results_list = TeamResults::createAllResults();
00092   const char *winner_name = NULL;
00093 
00094   FOR_EACH_TEAM(team)
00095   {
00096     // Determine winner
00097     if (0 < (**team).NbAliveCharacter())
00098     {
00099       winner_name = (**team).GetName().c_str();
00100       break;
00101     }
00102   }
00103 
00104   // Print out results
00105   if (winner_name)
00106     jukebox.Play("share","victory");
00107 
00108   //question.Set (txt, true, 0);
00109   //AskQuestion();
00110   Mouse::GetInstance()->SetPointer(Mouse::POINTER_STANDARD);
00111   ResultsMenu menu(results_list, winner_name);
00112   menu.Run();
00113 
00114   TeamResults::deleteAllResults(results_list);
00115 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Game::MessageLoading (  ) 

Definition at line 83 of file game.cpp.

00084 {
00085   std::cout << std::endl;
00086   std::cout << "[ " << _("Starting a new game") << " ]" << std::endl;
00087 }

Here is the caller graph for this function:

int Game::NbrRemainingTeams (  )  [private]

Definition at line 71 of file game.cpp.

00072 {
00073   uint nbr = 0;
00074 
00075   FOR_EACH_TEAM(team){
00076     if( (**team).NbAliveCharacter() > 0 )
00077       nbr++;
00078   }
00079 
00080   return nbr;
00081 }

Here is the caller graph for this function:

void Game::Pause (  ) 

Definition at line 214 of file game.cpp.

00215 {
00216   Question question;
00217   if(!network.IsLocal())
00218     return;
00219 
00220   jukebox.Pause();
00221 
00222   //Pause screen
00223   question.Set ("", false, 0, "interface/pause_screen");
00224   question.add_choice(Config::GetInstance()->GetKeyboard()->GetKeyAssociatedToAction(Action::ACTION_PAUSE),
00225                       1
00226                       );
00227   AskQuestion(question, false);
00228   jukebox.Resume();
00229 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Game::SetEndOfGameStatus ( bool  status  ) 

Definition at line 239 of file game.cpp.

00239                                         {
00240   endOfGameStatus = status;
00241 }

Here is the caller graph for this function:

void Game::Start (  ) 

Definition at line 131 of file game.cpp.

00132 {
00133   bool err=true;
00134   bool end;
00135   std::string err_msg;
00136 
00137   try
00138   {
00139     GameLoop::GetInstance()->Init ();
00140 
00141     do
00142     {
00143       isGameLaunched = true;
00144       GameLoop::GetInstance()->fps.Reset();
00145 
00146       GameLoop::GetInstance()->Run();
00147 
00148       MSG_DEBUG( "game", "End of game_loop.Run()" );
00149       isGameLaunched = false;
00150 
00151       if (!IsGameFinished())
00152       {
00153         Question question;
00154         const char *msg = _("Do you really want to quit? (Y/N)");
00155         question.Set (msg, true, 0, "interface/quit_screen");
00156 
00157         {
00158           /* Tiny fix by Zygmunt Krynicki <zyga@zyga.dyndns.org> */
00159           /* Let's find out what the user would like to press ... */
00160           char *key_x_ptr = strchr (msg, '/');
00161           char key_x;
00162           if (key_x_ptr && key_x_ptr > msg) /* it's there and it's not the first char */
00163             key_x = tolower(key_x_ptr[-1]);
00164           else
00165             abort();
00166           if (!isalpha(key_x)) /* sanity check */
00167             abort();
00168 
00169           question.add_choice(SDLK_a + (int)key_x - 'a', 1);
00170         }
00171 
00172         jukebox.Pause();
00173         end = (AskQuestion(question) == 1);
00174         jukebox.Resume();
00175         if(!end)
00176           world.ToRedrawOnScreen(Rectanglei(Point2i(0,0),AppWormux::GetInstance()->video.window.GetSize()));
00177       } else {
00178         end = true;
00179       }
00180     } while (!end);
00181     err = false;
00182   }
00183   catch (const std::exception &e)
00184   {
00185     err_msg = e.what();
00186   }
00187 
00188   if (!err)
00189     if (IsGameFinished())
00190       MessageEndOfGame();
00191 
00192   UnloadDatas();
00193   Mouse::GetInstance()->SetPointer(Mouse::POINTER_STANDARD);
00194 
00195   if (err)
00196   {
00197     Question question;
00198     std::string txt = Format(_("Error:\n%s"), err_msg.c_str());
00199     std::cout << std::endl << txt << std::endl;
00200     question.Set (txt, true, 0);
00201     AskQuestion (question, false);
00202   }
00203 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Game::UnloadDatas (  ) 

Definition at line 205 of file game.cpp.

00206 {
00207   world.FreeMem();
00208   lst_objects.FreeMem();
00209   ParticleEngine::Stop();
00210   teams_list.UnloadGamingData();
00211   jukebox.StopAll();
00212 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

bool Game::endOfGameStatus [private]

Definition at line 33 of file game.h.

bool Game::isGameLaunched [private]

Definition at line 32 of file game.h.

Game * Game::singleton = NULL [static, private]

Definition at line 38 of file game.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:47:10 2007 for Wormux by  doxygen 1.4.7