int main_widget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWorkspace::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: resize_s(); break;
        case 1: push_right(); break;
        case 2: push_left(); break;
        case 3: mark_selection(); break;
        case 4: open_new_file(); break;
        case 5: set_font(); break;
        case 6: set_page((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 7: set_background(); break;
        case 8: save_label(); break;
        default: ;
        }
        _id -= 9;
    }
    return _id;
}
Exemple #2
0
int main(int argn, char** argv) {
	
	int xsize, ysize;
	char c, c2;
	int i, i2;
	int x, y;

	WINDOW* wnd;
	char buf[50];
	tile* temp_tile; 

	/* Inicjalizacja generatora liczb losowych */
	srand(time(0));

	wnd = initscr();
	start_color();
	
	if(has_colors()) {

		enable_tile_colors();
		use_default_colors();

		/* Przyporządkuj każdej płytce kolor */
		init_pair(1, COLOR_YELLOW, -1);
		init_pair(2, COLOR_GREEN, -1);
		init_pair(3, COLOR_RED, -1);
		init_pair(4, COLOR_YELLOW, -1);
		init_pair(5, COLOR_WHITE, -1);
		init_pair(6, COLOR_RED, -1);
		init_pair(7, COLOR_GREEN, -1);
		init_pair(8, COLOR_BLUE, -1);
		init_pair(9, COLOR_CYAN, -1);
		init_pair(10, COLOR_MAGENTA, -1);

	}
	else {

		disable_tile_colors();

	}

	cbreak();
	echo();
	nonl();
	intrflush(stdscr, FALSE);
	keypad(stdscr, TRUE);

	getmaxyx(wnd, ysize, xsize);

	/* Pobierz docelowy rozmiar */
	while(1) {

		werase(wnd);

		draw_frame(wnd);

		wmove(wnd, ysize/2-(MAX_SIZE-MIN_SIZE+2), 20);	

		wprintw(wnd, "Available pool size:");

		for(i=MIN_SIZE;i<=MAX_SIZE;i++) {

			wmove(wnd, ysize/2-(MAX_SIZE-MIN_SIZE+2)+(i-MIN_SIZE+1), 20);
			attron(COLOR_PAIR(5) | A_BOLD);
			wprintw(wnd, "%d", i);
			attroff(COLOR_PAIR(5) | A_BOLD);
			wprintw(wnd, " for %dx%d", i, i);
			
		}

		wmove(wnd, ysize-2, 2);
		wprintw(wnd, "Saephir (c), 2010");

		wmove(wnd, ysize/2+1, 20);
		wprintw(wnd, "Type the desired number: ");

		c = getch();

		buf[0] = c;
		buf[1] = 0;

		i2 = atoi(buf);

		if(i2 >= MIN_SIZE && i2 <= MAX_SIZE) {
			TILES_COUNT = i2;
			init();
			break;
		}

	}

	while(1) {

		werase(wnd);

		draw_frame(wnd);

		/* Wygrana gra */
		if(verify()) {

			print_game(wnd);

			wmove(wnd, ysize/2, 40);
			wprintw(wnd, "Well done!");
			wmove(wnd, ysize/2+1, 40);
			wprintw(wnd, "Press ENTER to exit...");
			getch();
			break;

		}

		print_game(wnd);
		print_pool(wnd);

		wmove(wnd, ysize-2, 1);

		wgetnstr(wnd, buf, 49);
		buf[49] = 0;

		if(strcmp(buf, "exit") == 0 || strcmp(buf, "quit") == 0 || strcmp(buf, "q") == 0) {

			break;

		}
		else if(strcmp(buf, "help") == 0 || strcmp(buf, "?") == 0) {

			wmove(wnd, ysize-2, 1);
			wclrtoeol(wnd);
			draw_frame(wnd);
			wmove(wnd, ysize-2, 1);
			wprintw(wnd, HELP_LINE);
			getch();
			wmove(wnd, ysize-2, 1);
			wclrtoeol(wnd);
			draw_frame(wnd);
			wmove(wnd, ysize-2, 1);
			wprintw(wnd, HELP_LINE2);
			getch();

		}

		else if(strcmp(buf, "<<") == 0) {

			push_left();

		}

		else if(strcmp(buf, ">>") == 0) {

			push_right();

		}

		else if(strcmp(buf, "^^") == 0) {

			push_top();

		}

		else if(strcmp(buf, "vv") == 0) {

			push_bottom();

		}
		else if(sscanf(buf, "%c%d<%c%d", &c, &i, &c2, &i2) == 4) {

			i--;
			i2--;

			if(c == c2 && i == i2)
				continue;

			if(c-'a' < 0 || c-'a' >= 2*TILES_COUNT)
				continue;

			if(c2-'a' < 0 || c2-'a' >= 2*TILES_COUNT)
				continue;

			if(i < 0 || i >= TILES_COUNT)
				continue;

			if(i2 < 0 || i2 >= TILES_COUNT)
				continue;

			/* Przesuwamy na pole gry */
			if(c-'a' < TILES_COUNT) {

				temp_tile = &game[i][c-'a'];

				/* Miejsce musi być puste */
				if(!is_empty(temp_tile))
					continue;

				/* przesuwamy z puli do gry */
				if(c2-'a' >= TILES_COUNT)
					temp_tile = &pool[i2][c2-'a'-TILES_COUNT];
				/* przesuwamy z gry do gry */
				else
					temp_tile = &game[i2][c2-'a'];

				/* Żródło nie może być puste */
				if(is_empty(temp_tile))
					continue;

				move_tile(&game[i][c-'a'], temp_tile);

			}
			/* Przesuwamy do puli */
			else {

				temp_tile = &pool[i][c-'a'-TILES_COUNT];

				/* Miejsce musi być puste */
				if(!is_empty(temp_tile))
					continue;

				/* Przesuwamy z pola gry do puli */
				if(c2-'a' < TILES_COUNT)
					temp_tile = &game[i2][c2-'a'];
				/* Przesuwamy z puli do puli */
				else
					temp_tile = &pool[i2][c2-'a'-TILES_COUNT];
				
				/* Żródło nie może być puste */
				if(is_empty(temp_tile))
					continue;

				move_tile(&pool[i][c-'a'-TILES_COUNT], temp_tile);

			}
			


		}
		else if(sscanf(buf, "%c%d>%c%d", &c, &i, &c2, &i2) == 4) {

			i--;
			i2--;

			if(c == c2 && i == i2)
				continue;

			if(c-'a' < 0 || c-'a' >= 2*TILES_COUNT)
				continue;

			if(c2-'a' < 0 || c2-'a' >= 2*TILES_COUNT)
				continue;

			if(i < 0 || i >= TILES_COUNT)
				continue;

			if(i2 < 0 || i2 >= TILES_COUNT)
				continue;

			/* Przesuwamy do puli */
			if(c2-'a' >= TILES_COUNT) {

				temp_tile = &pool[i2][c2-'a'-TILES_COUNT];

				/* Miejsce musi być puste */
				if(!is_empty(temp_tile))
					continue;

				/* Przesuwamy z pola gry */
				if(c-'a' < TILES_COUNT)
					temp_tile = &game[i][c-'a'];
				/* Przesuwamy z puli */
				else
					temp_tile = &pool[i][c-'a'-TILES_COUNT];
				
				/* Żródło nie może być puste */
				if(is_empty(temp_tile))
					continue;

				move_tile(&pool[i2][c2-'a'-TILES_COUNT], temp_tile);

			}
			/* Przesuwamy na pole gry */
			else {

				temp_tile = &game[i2][c2-'a'];

				/* Miejsce musi być puste */
				if(!is_empty(temp_tile))
					continue;

				/* Przesuwamy z puli na pole gry */
				if(c-'a' >= TILES_COUNT)
					temp_tile = &pool[i][c-'a'-TILES_COUNT];
				/* Przesuwamy z pola gry na pole gry */
				else
					temp_tile = &game[i][c-'a'];
				
				/* Żródło nie może być puste */
				if(is_empty(temp_tile))
					continue;

				move_tile(&game[i2][c2-'a'], temp_tile);

			}

		}
		else if(sscanf(buf, "%c%d>pool", &c, &i) == 2 || sscanf(buf, "pool<%c%d", &c, &i) == 2) {

			i--;

			if(strcmp(&buf[2], ">pool") != 0) {
				buf[5] = 0;
				if(strcmp(buf, "pool<") != 0)
					continue;
			}

			if(c-'a' < 0 || c-'a' >= TILES_COUNT)
				continue;

			if(i < 0 || i >= TILES_COUNT)
				continue;

			/* Żródło nie może być puste */
			if(is_empty(&game[i][c-'a']))
				continue;

			/* Jeżeli źródło nie jest puste, to istnieją wolne miejsca w puli */
			/* znajdujemy więc pierwsze wolne miejsce */
			for(y=0;y<TILES_COUNT;y++) {
				for(x=0;x<TILES_COUNT;x++) {
					
					if(is_empty(&pool[x][y])) {
						
						move_tile(&pool[x][y], &game[i][c-'a']);
						break;
					}

				}
			}
			

		}

	}

	endwin();

	return 0;
}