Logo Search packages:      
Sourcecode: mathwar version File versions  Download package

game_engine* create_game_engine ( GtkWidget *  parent  ) 

Create and intialize a game engine instance.

This function reads the user defined paramaters (if available), and initializes the games control structure accordingly.

Parameters:
parent The toplevel parent widget of the game's user interface.
Returns:
The newly created and intialized game engine.

Definition at line 625 of file game_engine.c.

References COMPUTER, and HUMAN.

{
   game_engine *game;
   GString     *name;

   srand ((unsigned int)time (NULL));
   game = g_malloc (sizeof (game_engine));

   /*
    * Player 1 is always human, and is the current OS user.  
    * Player 2 is always the computer.
    */
   if (getenv ("LOGNAME"))
      {
      name = g_string_new (getenv ("LOGNAME"));
      }
   else
      {
      name = g_string_new (_("Human Player"));
      }
   game->player1 = create_player (name->str, HUMAN);
   game->player2 = create_player (_("Computer Player"), COMPUTER);

   game->parent = parent;
   
   game->state = NOT_RUNNING;
   game->is_paused = FALSE;

   /*
    * Call begin_game to do all of the pre-game initialization.
    */
   begin_game (game);

   /*
    * Clean up...
    */
   g_string_free (name, TRUE);

#ifdef DEBUG_GAME_ENGINE 
   dump_game_engine (game);
#endif

   return game;
}


Generated by  Doxygen 1.6.0   Back to index