David Marec před 8 měsíci
rodič
revize
931b14b05f
1 změnil soubory, kde provedl 35 přidání a 15 odebrání
  1. 35 15
      dummy/pepper2.c

+ 35 - 15
dummy/pepper2.c

@@ -20,7 +20,7 @@ enum dirs {
 	D /* down */	
 };
 
-static size_t delay = 500;
+static size_t delay = 150;
 
 /* result window */
 static WINDOW * winR;
@@ -31,14 +31,19 @@ static void worm(WINDOW *win, int x, int y, char c0, char repl)
 	static int ax, ay;
 	static char ac = '*';
 
-	wattron(win, A_REVERSE | A_BOLD);
-	mvwprintw(win, y + 1, x + 1, "%c", c0);
-	wattroff(win, A_REVERSE | A_BOLD);
-	if (ac != '*')
-		mvwprintw(win, ay + 1, ax + 1, "%c", ac);
+	wattron(win, A_REVERSE);
+	mvwaddch(win, y + 1, x + 1, c0);
+	wattroff(win, A_REVERSE);
+	if (ac != '*') {
+		if (ac != '.')
+			wattron(win, COLOR_PAIR(1));
+		mvwaddch(win, ay, ax, ac);
+		if (ac != ' ')
+			wattroff(win, COLOR_PAIR(1));
+	}
 	wrefresh(win);
-	ax = x;
-	ay = y;
+	ax = x + 1;
+	ay = y + 1;
 	ac = repl;
 	usleep(delay * 1000);
 }
@@ -52,7 +57,7 @@ static __attribute((malloc)) __attribute__((nonnull)) char *get_it(truc_array co
 	int x = 0, y = 0;
 	char c0 = '<';
 
-	WINDOW * win = newwin(14, 18, 1, 40);
+	WINDOW * win = newwin(12, 17, 1, 49);
 
 	curs_set(0);
 	box(win, 0, 0);
@@ -64,9 +69,13 @@ static __attribute((malloc)) __attribute__((nonnull)) char *get_it(truc_array co
 		while((c = src->items[y][x]) != ' ') {
 			/* store */
 			if (c != '*') {
-				r[n++] = c;
 				worm(win, x, y, c0, c);
-				mvwprintw(winR, 1, 1, "%s", r);
+				if (n > 0)
+					mvwaddch(winR, 1, n , r[n - 1]);
+				r[n++] = c;
+				wattron (winR, COLOR_PAIR(2));
+				mvwaddch(winR, 1, n, c);
+				wattroff(winR, COLOR_PAIR(2));
 				wrefresh(winR);
 			} else
 				worm(win, x, y, c0, '.');
@@ -100,8 +109,12 @@ static __attribute((malloc)) __attribute__((nonnull)) char *get_it(truc_array co
 			/* ouch */
 			if (tx > 14 || tx < 0 || ty <0 || ty > 9)
 				break;
-			if ((c = src->items[ty][tx]) == ' ') 
+			if ((c = src->items[ty][tx]) == ' ') {
+				wattron(win,COLOR_PAIR(3));
+				mvwaddch(win, ty + 1, tx + 1, c);
+				wattroff(win, COLOR_PAIR(3));
 				break;
+			}
 			/* valid next */
 			x = tx;
 			y = ty;
@@ -161,6 +174,10 @@ static __attribute((malloc)) __attribute__((nonnull)) char *get_it(truc_array co
 
 end:
 	worm(win, x , y , ' ', ' ');
+	if (n > 1) {
+		mvwaddch(winR, 1, n, r[n -1]);
+		wrefresh(winR);
+	}
 	delwin(win);
 	return r;
 }
@@ -168,7 +185,7 @@ end:
 /* puzzle display */
 static void print_it(truc_array src)
 {
-	WINDOW * win = newwin(14, 18, 1, 1);
+	WINDOW * win = newwin(12, 17, 1, 1);
 	box(win, 0, 0);
 	for (size_t j= 0; j < 10; ++j) {
 		mvwprintw(win, j + 1, 1, "%s", src.items[j]);
@@ -214,12 +231,15 @@ int main(int argc, char *argv[])
 	initscr();
 	nonl();
 	noecho();
-	winR = newwin(3, 65, 20, 1);
+	winR = newwin(3, 65, 13, 1);
 	box(winR, 0, 0);
 	wrefresh(winR);
 
+	start_color();
+	init_pair(1, COLOR_RED, COLOR_BLACK);
+	init_pair(2, COLOR_BLACK, COLOR_MAGENTA);
+	init_pair(3, COLOR_BLUE, COLOR_BLUE);
 	print_it(a);
-
 	r = get_it(&a);
 	dallocx(r, 0);
 	delwin(winR);