| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#include <curses.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include <time.h> |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
static int next_j(int j) |
| 38 |
{ |
| 39 |
if (j == 0) |
| 40 |
j = 4; |
| 41 |
else |
| 42 |
--j; |
| 43 |
|
| 44 |
if (has_colors()) |
| 45 |
{ |
| 46 |
int z = rand() % 3; |
| 47 |
chtype color = COLOR_PAIR(z); |
| 48 |
|
| 49 |
if (z) |
| 50 |
color |= A_BOLD; |
| 51 |
|
| 52 |
attrset(color); |
| 53 |
} |
| 54 |
|
| 55 |
return j; |
| 56 |
} |
| 57 |
|
| 58 |
int main(int argc, char *argv[]) |
| 59 |
{ |
| 60 |
int x, y, j, r, c, seed; |
| 61 |
static int xpos[5], ypos[5]; |
| 62 |
|
| 63 |
#ifdef XCURSES |
| 64 |
Xinitscr(argc, argv); |
| 65 |
#else |
| 66 |
initscr(); |
| 67 |
#endif |
| 68 |
seed = time((time_t *)0); |
| 69 |
srand(seed); |
| 70 |
|
| 71 |
if (has_colors()) |
| 72 |
{ |
| 73 |
int bg = COLOR_BLACK; |
| 74 |
|
| 75 |
start_color(); |
| 76 |
|
| 77 |
#if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000) |
| 78 |
if (use_default_colors() == OK) |
| 79 |
bg = -1; |
| 80 |
#endif |
| 81 |
init_pair(1, COLOR_BLUE, bg); |
| 82 |
init_pair(2, COLOR_CYAN, bg); |
| 83 |
} |
| 84 |
|
| 85 |
nl(); |
| 86 |
noecho(); |
| 87 |
curs_set(0); |
| 88 |
timeout(0); |
| 89 |
keypad(stdscr, TRUE); |
| 90 |
|
| 91 |
r = LINES - 4; |
| 92 |
c = COLS - 4; |
| 93 |
|
| 94 |
for (j = 5; --j >= 0;) |
| 95 |
{ |
| 96 |
xpos[j] = rand() % c + 2; |
| 97 |
ypos[j] = rand() % r + 2; |
| 98 |
} |
| 99 |
|
| 100 |
for (j = 0;;) |
| 101 |
{ |
| 102 |
x = rand() % c + 2; |
| 103 |
y = rand() % r + 2; |
| 104 |
|
| 105 |
mvaddch(y, x, '.'); |
| 106 |
|
| 107 |
mvaddch(ypos[j], xpos[j], 'o'); |
| 108 |
|
| 109 |
j = next_j(j); |
| 110 |
mvaddch(ypos[j], xpos[j], 'O'); |
| 111 |
|
| 112 |
j = next_j(j); |
| 113 |
mvaddch(ypos[j] - 1, xpos[j], '-'); |
| 114 |
mvaddstr(ypos[j], xpos[j] - 1, "|.|"); |
| 115 |
mvaddch(ypos[j] + 1, xpos[j], '-'); |
| 116 |
|
| 117 |
j = next_j(j); |
| 118 |
mvaddch(ypos[j] - 2, xpos[j], '-'); |
| 119 |
mvaddstr(ypos[j] - 1, xpos[j] - 1, "/ \\"); |
| 120 |
mvaddstr(ypos[j], xpos[j] - 2, "| O |"); |
| 121 |
mvaddstr(ypos[j] + 1, xpos[j] - 1, "\\ /"); |
| 122 |
mvaddch(ypos[j] + 2, xpos[j], '-'); |
| 123 |
|
| 124 |
j = next_j(j); |
| 125 |
mvaddch(ypos[j] - 2, xpos[j], ' '); |
| 126 |
mvaddstr(ypos[j] - 1, xpos[j] - 1, " "); |
| 127 |
mvaddstr(ypos[j], xpos[j] - 2, " "); |
| 128 |
mvaddstr(ypos[j] + 1, xpos[j] - 1, " "); |
| 129 |
mvaddch(ypos[j] + 2, xpos[j], ' '); |
| 130 |
|
| 131 |
xpos[j] = x; |
| 132 |
ypos[j] = y; |
| 133 |
|
| 134 |
switch (getch()) |
| 135 |
{ |
| 136 |
case 'q': |
| 137 |
case 'Q': |
| 138 |
curs_set(1); |
| 139 |
endwin(); |
| 140 |
return EXIT_SUCCESS; |
| 141 |
case 's': |
| 142 |
nodelay(stdscr, FALSE); |
| 143 |
break; |
| 144 |
case ' ': |
| 145 |
nodelay(stdscr, TRUE); |
| 146 |
#ifdef KEY_RESIZE |
| 147 |
break; |
| 148 |
case KEY_RESIZE: |
| 149 |
# ifdef PDCURSES |
| 150 |
resize_term(0, 0); |
| 151 |
erase(); |
| 152 |
# endif |
| 153 |
r = LINES - 4; |
| 154 |
c = COLS - 4; |
| 155 |
#endif |
| 156 |
} |
| 157 |
napms(50); |
| 158 |
} |
| 159 |
} |