示例#1
0
int main (int argc, char* argv[]) {
  if (argc > 1) args_handle (argc, argv);

  if(tron.user_name[0] == 0) {
    char *tmp = getlogin();
    if(tmp == NULL) {
      ifitron_abort("No username provided and attempts to fetch it automatically, failed.\n");
    }
    strcpy(tron.user_name, tmp);
  }

  if(get_server_mode() == 2) {
    while(TRUE) {
      int result = play_multiplayer();
      if(result == -1)
        break;
    }
    engine_exit();
    ifitron_exit();
  }

  if(client_host_addr != NULL) { //Connect to the server
    int sd = connect_to_server();
    if(sd == -1) {
      ifitron_abort("Couldn't connect to the server.\n");
    }else{
      set_client_socket_descriptor(sd);
    }
  }

  engine_init ();
  engine_show_main_menu ();
  ifitron_init ();
	
  while (TRUE) {
    if (tron.is_alive == FALSE) 
      ifitron_game_over ();
    
    engine_get_game_input();
    player_update(get_tron());
    
    player_increase_size (get_tron(), 1);
    player_increase_score (get_tron(), game.level);
	  
    if (tron.score % 50 == 0 && game.level < 9) game.level++;

    if (player_hit_self(get_tron()) == TRUE  || player_hit_borders(get_tron()) == TRUE)
      tron.is_alive = FALSE;

    engine_show_screen ();
  }
  return 0;
}
示例#2
0
文件: main.c 项目: gsrr/Python
/**	The main function - contains the main loop of the game.
 *
 *
 *	@note I tried to make this function as clear as possible, so anyone
 *        could understaing the whole game logic starting by here. @n
 *        Have fun with the source code!
 */
 int main (int argc, char* argv[])
{
	if (argc > 1)
		args_handle (argc, argv);

	engine_init ();
	engine_show_main_menu ();
	nsnake_init ();

	while (TRUE == TRUE)
	{
		if (snake.is_alive == FALSE)
			nsnake_game_over ();

		engine_get_game_input ();

		player_update ();
		fruit_update_bonus ();

		if (player_hit_fruit () == TRUE)
		{
			// Is this score arbitrary?
			player_increase_score (game.level*3 + fruit.bonus);
			player_increase_size (2);
			fruit_init ();
		}

		if (player_hit_self () == TRUE)
			snake.is_alive = FALSE;

		if (player_collided_with_borders () == TRUE)
			snake.is_alive = FALSE;

		engine_show_screen ();
	}


	// Even though we have this here, the game always quits during
	// the main loop
	engine_exit ();
	nsnake_exit ();
	return 0;
}