int main(int argc, char** argv) { char result[MAX_LEN]; char add_a[MAX_LEN]; char add_b[MAX_LEN]; while(1) { get_number(add_a); get_number(add_b); add_big_int(add_a, add_b, result); printf("The result is: %s\n", result); } return 0; }
void merge_right(board *b) { int x, y; struct longint tmp; set_big_int(&merge_score, 0); for (y = 0; y < brd_h; y++) { for (x = 3; x > 0; x--) { if ((*b)[y][x] > 0 && (*b)[y][x] == (*b)[y][x - 1]) { (*b)[y][x] <<= 1; (*b)[y][x - 1] = 0; set_big_int(&tmp, (*b)[y][x]); add_big_int(&merge_score, &tmp); } } } }
void merge_left(board *b) { int x, y; struct longint tmp; set_big_int(&merge_score, 0); for (y = 0; y < brd_h; y++) { for (x = 0; x < brd_w - 1; x++) { if ((*b)[y][x] > 0 && (*b)[y][x] == (*b)[y][x + 1]) { (*b)[y][x] <<= 1; (*b)[y][x + 1] = 0; set_big_int(&tmp, (*b)[y][x]); add_big_int(&merge_score, &tmp); } } } }
void merge_down(board *b) { int x, y; struct longint tmp; set_big_int(&merge_score, 0); for (x = 0; x < brd_w; x++) { for (y = 3; y > 0; y--) { if ((*b)[y][x] > 0 && (*b)[y][x] == (*b)[y - 1][x]) { (*b)[y][x] <<= 1; (*b)[y - 1][x] = 0; set_big_int(&tmp, (*b)[x][y]); add_big_int(&merge_score, &tmp); } } } }
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()); }