Beispiel #1
0
int game_is_lost()
{
	if (can_move_left(&grid) || can_move_right(&grid) || 
			can_move_up(&grid) || can_move_down(&grid)) {
		return 0;
	} else {
		return 1;
	}
}
Beispiel #2
0
int how_far_left(OBJp objp,int n)
{
   register int i;
   register int temp;

   temp = objp->x;       /* save the current position */

   /* increment the position until you can't move left any further */
   for (i = 0; i < n; i++)
   {
      objp->x--;
      if (!can_move_left(objp))
      {
         objp->x = temp;
         return(i);
      }
   }
   objp->x = temp;      /* restore the current position */
   return(n);           /* return how far left */
}
Beispiel #3
0
void play_game()
{
	board *b = &grid;

	do {

		switch (os_wait_for_key()) {
			case ESC_KEY:
				return;

			case UP_KEY:
				if (can_move_up(b)) {
					shift_up(b);
					merge_up(b);
					shift_up(b);
					add_big_int(&score, &merge_score);
					break;
				} else {
					continue;
				}

			case DOWN_KEY:
				if (can_move_down(b)) {
					shift_down(b);
					merge_down(b);
					shift_down(b);
					add_big_int(&score, &merge_score);
					break;
				} else {
					continue;
				}

			case LEFT_KEY:
				if (can_move_left(b)) {
					shift_left(b);
					merge_left(b);
					shift_left(b);
					add_big_int(&score, &merge_score);
					break;
				} else {
					continue;
				}

			case RIGHT_KEY:
				if (can_move_right(b)) {
					shift_right(b);
					merge_right(b);
					shift_right(b);
					add_big_int(&score, &merge_score);
					break;
				} else {
					continue;
				}

			default:
				continue;
		}

		add_tile(b);
		display_board(b);

	} while (!game_is_lost());
}