From: Laurent Mazet Date: Wed, 16 Oct 2024 21:51:46 +0000 (+0200) Subject: add ghosts X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=9f84813fd05da7c2e54c09cc8a80000623425306;p=pacman.git add ghosts --- diff --git a/board-80x20.pac b/board-80x20.pac index 75017da..47f7162 100644 --- a/board-80x20.pac +++ b/board-80x20.pac @@ -9,8 +9,8 @@ tab: "F----------7 |.L-----J.| F----------7" "|.| |.L---7 |.L---------J.| F---J.| |.|" "|.L-J....*L-J.............L-J*....L-J.|" "|.....F-7.....F---3xE---7.....F-7.....|" - "L---7.| L---7.| |.F---J |.F---J" - "F---J.| F---J.| |.L---7 |.L---7" + "L---7.| L---7.| P Q |.F---J |.F---J" + "F---J.| F---J.| R S |.L---7 |.L---7" "|.....L-J.....L---------J.....L-J.....|" "|.F-7....*F-7.............F-7*....F-7.|" "|.| |.F---J |.F---------7.| L---7.| |.|" diff --git a/board-80x22.pac b/board-80x22.pac index f85b511..7a2b7ff 100644 --- a/board-80x22.pac +++ b/board-80x22.pac @@ -9,7 +9,7 @@ tab: "F----------7 |.L-----J.| F----------7" "|.| |.L---7 |.L---------J.| F---J.| |.|" "|.| |....*| |.............| |*....| |.|" "|.L-J.F-7.L-J.F---3xE---7.L-J.F-7.L-J.|" - "|.....| |.....| |.....| |.....|" + "|.....| |.....| P Q R S |.....| |.....|" "L---7.| L---7.|F-7 F-7|.F---J |.F---J" "F---J.| F---J.|| L---J ||.L---7 |.L---7" "|.....| |.....|L-------J|.....| |.....|" diff --git a/board-80x24.pac b/board-80x24.pac index 0059ad9..9fc4dc2 100644 --- a/board-80x24.pac +++ b/board-80x24.pac @@ -9,9 +9,9 @@ tab: "F----------7 |.L-----J.| F----------7" "|.| |.L---7 |.L---------J.| F---J.| |.|" "|.| |....*| |.............| |*....| |.|" "|.| |.F-7.| |.F---7xF---7.| |.F-7.| |.|" - "|.L-J.| |.L-J.|F--JxL--7|.L-J.| |.L-J.|" - "|.....| |.....|| ||.....| |.....|" - "L---7.| L---7.||F7 F7||.F---J |.F---J" + "|.L-J.| |.L-J.|F--J L--7|.L-J.| |.L-J.|" + "|.....| |.....|| P Q R ||.....| |.....|" + "L---7.| L---7.||F7 S F7||.F---J |.F---J" "F---J.| F---J.|||L---J|||.L---7 |.L---7" "|.....| |.....||L-----J||.....| |.....|" "|.F-7.| |.F-7.|L-------J|.F-7.| |.F-7.|" diff --git a/color.c b/color.c index 05e28fb..b990045 100644 --- a/color.c +++ b/color.c @@ -53,7 +53,7 @@ void setcolor (ctext_t color) num = 5; break; case magenta_black: - case lightmagenta_black: + case pink_black: num = 6; break; case brown_black: @@ -80,7 +80,7 @@ void setcolor (ctext_t color) num = 12; break; case magenta_gray: - case lightmagenta_gray: + case pink_gray: num = 13; break; case brown_gray: @@ -99,14 +99,14 @@ void setcolor (ctext_t color) case lightgreen_black: case lightcyan_black: case lightred_black: - case lightmagenta_black: + case pink_black: case yellow_black: case white_gray: case lightblue_gray: case lightgreen_gray: case lightcyan_gray: case lightred_gray: - case lightmagenta_gray: + case pink_gray: case yellow_gray: state = A_BOLD; break; diff --git a/color.h b/color.h index 0b2d25a..b8eb68c 100644 --- a/color.h +++ b/color.h @@ -14,7 +14,7 @@ typedef enum { lightgreen_black, lightcyan_black, lightred_black, - lightmagenta_black, + pink_black, yellow_black, blue_gray, green_gray, @@ -27,7 +27,7 @@ typedef enum { lightgreen_gray, lightcyan_gray, lightred_gray, - lightmagenta_gray, + pink_gray, yellow_gray, black_gray } ctext_t; diff --git a/display.c b/display.c index f8c2f42..4cef03a 100644 --- a/display.c +++ b/display.c @@ -76,7 +76,8 @@ int helpwindow (char *msg, int xoffset, int yoffset) void displayelement (board_t *board, int x, int y) { int element = ' '; - switch (*getcell (board, x, y)) { + int symb = *getcell (board, x, y); + switch (symb) { case '-': element = ACS_HLINE; break; @@ -110,57 +111,62 @@ void displayelement (board_t *board, int x, int y) case '+': element = ACS_PLUS; break; + case 'A': case 'a': - setcolor (yellow_black); + setcolor ((symb < 'a') ? lightred_black : yellow_black); element = 'v'; break; + case 'B': case 'b': - setcolor (yellow_black); + setcolor ((symb < 'a') ? lightred_black : yellow_black); element = '>'; break; + case 'C': case 'c': - setcolor (yellow_black); + setcolor ((symb < 'a') ? lightred_black : yellow_black); element = '^'; break; + case 'D': case 'd': - setcolor (yellow_black); + setcolor ((symb < 'a') ? lightred_black : yellow_black); element = '<'; break; - case 'A': - setcolor (lightred_black); - element = 'v'; - break; - case 'B': - setcolor (lightred_black); - element = '>'; + case 'O': + case 'o': + setcolor ((symb < 'a') ? lightred_black : yellow_black); + element = 'O'; break; - case 'C': - setcolor (lightred_black); - element = '^'; + case 'P': + case 'p': + setcolor ((symb < 'a') ? red_black : gray_black); + element = 'M'; break; - case 'D': - setcolor (lightred_black); - element = '<'; + case 'Q': + case 'q': + setcolor ((symb < 'a') ? blue_black : gray_black); + element = 'M'; break; - case 'o': - setcolor (yellow_black); - element = 'O'; + case 'R': + case 'r': + setcolor ((symb < 'a') ? green_black : gray_black); + element = 'M'; break; - case 'O': - setcolor (lightred_black); - element = 'O'; + case 'S': + case 's': + setcolor ((symb < 'a') ? magenta_black : gray_black); + element = 'M'; break; case '.': - setcolor (brown_black); + setcolor (yellow_black); //element = ACS_BULLET; element = '.'; break; case '*': - setcolor (brown_black); + setcolor (yellow_black); element = ACS_DIAMOND; break; case 'x': - setcolor (blue_black); + setcolor (gray_black); element = ACS_CKBOARD; break; } diff --git a/function.c b/function.c index de1c47c..0d5ef3b 100644 --- a/function.c +++ b/function.c @@ -235,4 +235,26 @@ int endofgame (board_t *board) return ((strchr (board->tab, '.') == NULL) && (strchr (board->tab, '*') == NULL)); } +int commuteghost (board_t *board, int i, int *px, int *py) +{ + char *tab = board->tab; + char *ghost; + int rc = 0; + ghost = strchr (tab, 'P' + i); + if (ghost == NULL) { + ghost = strchr (tab, 'p' + i); + if (ghost != NULL) { + *ghost = 'P' + i; + } + } else { + *ghost = 'p' + i; + } + if (ghost) { + *px = (ghost - tab) % board->width; + *py = (ghost - tab) / board->width; + rc = 1; + } + return rc; +} + /* vim: set ts=4 sw=4 et: */ diff --git a/function.h b/function.h index 81ed6e3..f666f4d 100644 --- a/function.h +++ b/function.h @@ -45,6 +45,8 @@ int findchar (board_t *board, char c, int *px, int *py); int endofgame (board_t *board); +int commuteghost (board_t *board, int i, int *px, int *py); + #endif /* __FUNCTION_H__ */ /* vim: set ts=4 sw=4 et: */ diff --git a/pacman.c b/pacman.c index c0a4a54..c37fd30 100644 --- a/pacman.c +++ b/pacman.c @@ -281,6 +281,15 @@ int main (int argc, char *argv[]) displayelement (board, x, y); refresh (); spin = 1; + + /* commute ghost */ + int i; + for (i = 0; i < 4; i++) { + int x, y; + if (commuteghost (board, i, &x, &y)) { + displayelement (board, x, y); + } + } } /* test end of game */