add ghosts
authorLaurent Mazet <mazet@softndesign.org>
Wed, 16 Oct 2024 21:51:46 +0000 (23:51 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Wed, 16 Oct 2024 21:54:33 +0000 (23:54 +0200)
board-80x20.pac
board-80x22.pac
board-80x24.pac
color.c
color.h
display.c
function.c
function.h
pacman.c

index 75017da4099161a2593b082817480aa02dda5f5e..47f716261827c650839061b038006f52fd94344a 100644 (file)
@@ -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.| |.|"
index f85b511b98f94a95dc33e84c6ce3d57e0b748935..7a2b7ffa8bcbdd001729d0a7930947ad0f540494 100644 (file)
@@ -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|.....| |.....|"
index 0059ad99c383bea2674146642bb7d1c3f58915a5..9fc4dc26f43d0559b9cedc60140a7e89d0dc1fca 100644 (file)
@@ -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 05e28fb3561aa9fb005d158701480a0bf7e3a9d7..b990045cd02f8322715f9851962945721e15872d 100644 (file)
--- 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 0b2d25a9600d96698d99caeb72c5eab7791cc28b..b8eb68c7a4681479fb13902c48b883c9dea53ce7 100644 (file)
--- 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;
index f8c2f42118e45f815cf3235ec32b1181efcde2c4..4cef03a12232a6202c4b2d1886777c4bdc07ca2c 100644 (file)
--- 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;
     }
index de1c47ca467ecc0951e9f081559dfe721604e5cd..0d5ef3b9c5658b20a31128e6ad8bb7b5eb34cd3f 100644 (file)
@@ -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: */
index 81ed6e3e4d21166304f4fa91ebef72b7ac62711f..f666f4df3ca909d8f643fbfb4513c7fa31807bce 100644 (file)
@@ -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: */
index c0a4a54d17fcd7fcd0803c092bcb781f244af4d3..c37fd3026a05354ac0e16767861567a9b1f9a654 100644 (file)
--- 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 */