Пример #1
0
int main( void )
{
    while( 1 )
    {
        if( state == TITLE )
            titleScreen();
        if( state == GAME_LOOP )
            gameLoop();
        if( state == GAME_OVER )
            gameOver();
        if( state == WIN )
            game_win();
    }

    return 0;
}
Пример #2
0
void game (void)
{
  int lives = MAX_LIVES;
  int score = 0;
  long int level_score;
  int level = START_LEVEL;
  int result;

  do {
    result = play_level (level, &level_score, lives, score);
    /* The level has been played, now we must check to see what happened, display an appropriate
       message to the terminal if necessary, add up points, etc */
    
    switch (result)
      {	
      case MSG_WINLEVEL:
	score+= level_score;
	level++;
	display_message (result, lives, level, score);
	break;
      case MSG_WINGAME:
	score+= level_score;
	level++; /* This is for the log_score function */
	game_win ();
	
	lives = 0; /* This lets us get out of this function */
	
	/* Display ending message, then go back to menu */
	ansi_PutString (1, 25, "Done.");
	wait_for_select ();
	break;
      case MSG_QUIT: return;
      default: /* We know the users aircraft has crashed in some way, so deduct one life and display a message */
	lives--;
	display_message (result, lives, level, score);
	break;
      }
  } while (lives > 0);

#ifndef __ANDROID__
  log_score (score, level); /* This records the score of anyone who finishes or runs out of lives */
#endif // __ANDROID__
}
Пример #3
0
int main(void)
{
    SCREEN screen;
    SDL_Rect src, food_place;
    SDL_Rect all_dst[32];
    int quit_screen = TRUE;
    int key_quit = KEY_NO;

    /*创建一个窗口*/
    creat_screen(&screen);
    /*初始化蛇的位置*/
    init_snake(&screen, &src, all_dst, snake_lenth);

    begin_time = SDL_GetTicks();

    food_place = rand_xy(&food_place);

    while (quit_screen)
    {
        /*移动*/
        quit_screen = move_snake(&screen, &src, all_dst, snake_lenth);
        /*判断是否吃到食物*/
        if (getfood(&all_dst[0], &food_place))
        {
            /*刷新一个食物*/
            food_place = rand_xy(&food_place);
            /*长度加1*/
            snake_lenth++;
            /*如果长度大于NEXT, 速度加快,进入下一关*/
            if (snake_lenth > NEXT)
            {
                /*清除蛇结点*/
                clean_snake(&screen, all_dst, snake_lenth);
                /*速度增加*/
                speed -= STEP;
                /*长度变为初始化长度*/
                snake_lenth = INIT_LENTH;
            }

            /*如果速度速度达到WIN, 胜利*/
            if (speed < WIN)
            {
                /*显示胜利*/
                game_win(screen.p_screen);
                while (quit_screen)
                {
                    quit_screen = key_snake(&key_quit);
                    sleep(10000);
                }
            }
        }

        /*意外判断, 撞到边界、撞到自己*/
        if (check(all_dst))
        {
            /*显示gameover*/
            game_over(screen.p_screen);
            while (quit_screen)
            {
                quit_screen = key_snake(&key_quit);
                usleep(10000);
            }
        }
        appa(&screen, &food_place);
        SDL_Flip(screen.p_screen);

        usleep(10000);
    }
    SDL_FreeSurface(screen.show_picture);
    SDL_FreeSurface(screen.food);

    return 0;
}
Пример #4
0
void on_give_up (int fd, struct message *msg)
{
	printf ("on_give_up\n");
	game_win ();
}