add player
authorLaurent Mazet <mazet@softndesign.org>
Sun, 13 Oct 2024 21:34:25 +0000 (23:34 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 13 Oct 2024 21:34:25 +0000 (23:34 +0200)
a-orig.pac [deleted file]
a.pac
b-orig.pac [deleted file]
b.pac [deleted file]
display.c
pacman.c
time.c [new file with mode: 0644]
time.h [new file with mode: 0644]

diff --git a/a-orig.pac b/a-orig.pac
deleted file mode 100644 (file)
index ce4ee6b..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-width: 28
-height: 29
-tab: "F------------7F------------7"
-     "|            ||            |"
-     "| F--7 F---7 || F---7 F--7 |"
-     "| |  | |   | || |   | |  | |"
-     "| L--J L---J LJ L---J L--J |"
-     "|                          |"
-     "| F--7 F7 F------7 F7 F--7 |"
-     "| L--J || L--7F--J || L--J |"
-     "|      ||    ||    ||      |"
-     "L----7 |L--7 || F--J| F----J"
-     "     | |F--J LJ L--7| |     "
-     "     | ||          || |     "
-     "     | || F------7 || |     "
-     "-----J LJ |      | LJ L-----"
-     "          |      |          "
-     "-----7 F7 |      | F7 F-----"
-     "     | || L------J || |     "
-     "     | ||          || |     "
-     "     | |L--7 F7 F--J| |     "
-     "F----J |F--J || L--7| L----7"
-     "|      ||    ||    ||      |"
-     "| F--7 || F--JL--7 || F--7 |"
-     "| L--J LJ L------J LJ L--J |"
-     "|                          |"
-     "| F--7 F---7 F7 F---7 F--7 |"
-     "| |  | |   | || |   | |  | |"
-     "| L--J L---J || L---J L--J |"
-     "|            ||            |"
-     "L------------JL------------J"
diff --git a/a.pac b/a.pac
index 18e8b04f6b10bc9debc0d561bedd9a62680a1f0c..0059ad99c383bea2674146642bb7d1c3f58915a5 100644 (file)
--- a/a.pac
+++ b/a.pac
@@ -1,3 +1,26 @@
-width: 28
-height: 29
-tab: "F------------7F------------7|            ||            || F--7 F---7 || F---7 F--7 || |  | |   | || |   | |  | || L--J L---J LJ L---J L--J ||                          || F--7 F7 F------7 F7 F--7 || L--J || L--7F--J || L--J ||      ||    ||    ||      |L----7 |L--7 || F--J| F----J     | |F--J LJ L--7| |          | ||          || |          | || F------7 || |     -----J LJ |      | LJ L-----          |      |          -----7 F7 |      | F7 F-----     | || L------J || |          | ||          || |          | |L--7 F7 F--J| |     F----J |F--J || L--7| L----7|      ||    ||    ||      || F--7 || F--JL--7 || F--7 || L--J LJ L------J LJ L--J ||                          || F--7 F---7 F7 F---7 F--7 || |  | |   | || |   | |  | || L--J L---J || L---J L--J ||            ||            |L------------JL------------J"
+width: 39
+height: 24
+tab: "F----------7  |.L-----J.|  F----------7"
+     "|*.........|  |....c....|  |.........*|"
+     "|.F-7.F--7.|  |.F-----7.|  |.F--7.F-7.|"
+     "|.L-J.L--J.L--J.L-7 F-J.L--J.L--J.L-J.|"
+     "|................*| |*................|"
+     "|.F-7.F-----7.F---J L---7.F-----7.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"
+     "F---J.| F---J.|||L---J|||.L---7 |.L---7"
+     "|.....| |.....||L-----J||.....| |.....|"
+     "|.F-7.| |.F-7.|L-------J|.F-7.| |.F-7.|"
+     "|.| |.L-J.| |.L---------J.| |.L-J.| |.|"
+     "|.| |....*| |.............| |*....| |.|"
+     "|.| |.F---J |.F---------7.| L---7.| |.|"
+     "|.L-J.L-----J.L---7 F---J.L-----J L-J.|"
+     "|................*| |*................|"
+     "|.F-7.F--7.F--7.F-J L-7.F--7.F--7.F-7.|"
+     "|.L-J.L--J.|  |.L-----J.|  |.L--J.L-J.|"
+     "|*.........|  |.........|  |.........*|"
+     "L----------J  |.F-----7.|  L----------J"
diff --git a/b-orig.pac b/b-orig.pac
deleted file mode 100644 (file)
index 80a3335..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-width: 35
-height: 26
-tab: "F-----------7   | |   F-----------7"
-     "|           |   | |   |           |"
-     "| F--7 F--7 |   | |   | F--7 F--7 |"
-     "| |  | |  | |   | |   | |  | |  | |"
-     "| L--J L--J L---J L---J L--J L--J |"
-     "|                                 |"
-     "| F--7 F--------7 F--------7 F--7 |"
-     "| |  | L---7 F--J L--7 F---J |  | |"
-     "| |  |     | |       | |     |  | |"
-     "| |  | F-7 | | F---7 | | F-7 |  | |"
-     "| L--J | | L-J |   | L-J | | L--J |"
-     "|      | |     |   |     | |      |"
-     "L----7 | L---7 |   | F---J | F----J"
-     "F----J | F---J |   | L---7 | L----7"
-     "|      | |     |   |     | |      |"
-     "| F--7 | | F-7 |   | F-7 | | F--7 |"
-     "| |  | L-J | | L---J | | L-J |  | |"
-     "| |  |     | |       | |     |  | |"
-     "| |  | F---J L--7 F--J L---7 |  | |"
-     "| L--J L--------J L--------J L--J |"
-     "|                                 |"
-     "| F--7 F--7 F---7 F---7 F--7 F--7 |"
-     "| |  | |  | |   | |   | |  | |  | |"
-     "| L--J L--J |   | |   | L--J L--J |"
-     "|           |   | |   |           |"
-     "L-----------J   | |   L-----------J"
diff --git a/b.pac b/b.pac
deleted file mode 100644 (file)
index 1ece4a2..0000000
--- a/b.pac
+++ /dev/null
@@ -1,3 +0,0 @@
-width: 35
-height: 26
-tab: "F-----------7   | |   F-----------7|           |   | |   |           || F--7 F--7 |   | |   | F--7 F--7 || |  | |  | |   | |   | |  | |  | || L--J L--J L---J L---J L--J L--J ||                                 || F--7 F--------7 F--------7 F--7 || |  | L---7 F--J L--7 F---J |  | || |  |     | |       | |     |  | || |  | F-7 | | F---7 | | F-7 |  | || L--J | | L-J |   | L-J | | L--J ||      | |     |   |     | |      |L----7 | L---7 |   | F---J | F----JF----J | F---J |   | L---7 | L----7|      | |     |   |     | |      || F--7 | | F-7 |   | F-7 | | F--7 || |  | L-J | | L---J | | L-J |  | || |  |     | |       | |     |  | || |  | F---J L--7 F--J L---7 |  | || L--J L--------J L--------J L--J ||                                 || F--7 F--7 F---7 F---7 F--7 F--7 || |  | |  | |   | |   | |  | |  | || L--J L--J |   | |   | L--J L--J ||           |   | |   |           |L-----------J   | |   L-----------J"
index 59b23bccb1e321c324badbb6d1af4ece3ea41645..14e975a101dcf64b760b54fc8aaa8481e5fcc20a 100644 (file)
--- a/display.c
+++ b/display.c
@@ -103,14 +103,34 @@ void displayelement (board_t *board, int x, int y)
     case '+':
         element = ACS_PLUS;
         break;
-    case 'C':
+    case 'c':
         setcolor (yellow_black);
         element = 'C';
         break;
-    case 'O':
+    case 'C':
+        setcolor (red_black);
+        element = 'C';
+        break;
+    case 'o':
         setcolor (yellow_black);
         element = 'O';
         break;
+    case 'O':
+        setcolor (red_black);
+        element = 'O';
+        break;
+    case '.':
+        setcolor (brown_black);
+        element = ACS_BULLET;
+        break;
+    case '*':
+        setcolor (brown_black);
+        element = ACS_DIAMOND;
+        break;
+    case 'x':
+        setcolor (blue_black);
+        element = ACS_CKBOARD;
+        break;
     }
     mvaddch (board->yoffset + y, board->xoffset + x, element);
     setcolor (gray_black);
@@ -207,8 +227,8 @@ char *savewindow (int length, int xoffset, int yoffset)
 
 void msgwindow (char *msg, int xoffset, int yoffset, int length)
 {
-    setcolor (gray_black);
-    _dobound ((length > 0) ? length : (int)strlen (msg), 1, xoffset, yoffset);
+    setcolor (black_gray);
+    //_dobound ((length > 0) ? length : (int)strlen (msg), 1, xoffset, yoffset);
     if (length > 0) {
         int i;
         for (i = 0; i < length; i++) {
@@ -216,7 +236,7 @@ void msgwindow (char *msg, int xoffset, int yoffset, int length)
         }
     }
     mvaddstr (yoffset, xoffset + ((length > 0) ? (length - (int)strlen (msg)) / 2 : 0), msg);
-    setcolor (black_gray);
+    setcolor (gray_black);
 }
 
 /* vim: set ts=4 sw=4 et: */
index d642d007d78642a73f82e56fb340ae67d54306d0..eb1508680cb5738c3ea0e0b9dcfc4ba2655f5774 100644 (file)
--- a/pacman.c
+++ b/pacman.c
@@ -24,7 +24,8 @@ int savelen = 12;
 int height = 20;
 int width = 40;
 int xoffset = 1;
-int yoffset = 0;
+int yoffset = 1;
+int scorelen = 15;
 
 char *help =
     "<i> Move up cursor\n"
@@ -136,6 +137,8 @@ int main (int argc, char *argv[])
     start_color ();
 
     /* window positions (board) */
+    int xscore = (board->width - scorelen) / 2;
+    int yscore = 0;
     int xboard = board->xoffset = xoffset;
     int yboard = board->yoffset = yoffset;
     int xsave = max (xboard + (board->width - savelen) / 2, 1);
@@ -145,7 +148,7 @@ int main (int argc, char *argv[])
     /* pacman position */
     int x = 0;
     int y = 0;
-    if (findchar (board, 'C', &x, &y)) {
+    if (findchar (board, 'c', &x, &y)) {
         VERBOSE (WARNING, printf ("can't find Pacman\n"));
     }
     int nx = x;
@@ -154,6 +157,8 @@ int main (int argc, char *argv[])
     /* event loop */
     int stop = 0;
     int draw = 1;
+    int mode = 0;
+    int score = 0;
     while (!stop) {
 
         /* draw board */
@@ -162,20 +167,25 @@ int main (int argc, char *argv[])
             draw = 0;
         }
 
+        /* display score */
+        char msg[128] = {0};
+        sprintf (msg, "score: % 5d", score);
+        msgwindow (msg, xscore, yscore, scorelen);
+
         /* move pacman */
         if ((nx != x) || (ny != y)) {
-            *getcell (board, x, y) = 'O';
+            *getcell (board, x, y) = (mode == 0) ? 'o' : 'O';
             displayelement (board, x, y);
             refresh ();
-            msleep (250);
+            msleep (150);
             *getcell (board, x, y) = ' ';
             displayelement (board, x, y);
             x = nx;
             y = ny;
-            *getcell (board, x, y) = 'C';
+            *getcell (board, x, y) = (mode == 0) ? 'c' : 'C';
             displayelement (board, x, y);
             refresh ();
-            msleep (250);
+            msleep (150);
         }
 
         int ch = getch ();
@@ -233,7 +243,19 @@ int main (int argc, char *argv[])
             nx = ((x < board->width - 1) ? x : -1) + 1;
             break;
         }
-        if (*getcell (board, nx, ny) != ' ') {
+
+        /* check new position */
+        char *cell = getcell (board, nx, ny);
+        switch (*cell) {
+        case '*':
+            mode = 1;
+            /* fallthrough */
+        case '.':
+            score++;
+            /* fallthrough */
+        case ' ':
+            break;
+        default:
             nx = x;
             ny = y;
         }
diff --git a/time.c b/time.c
new file mode 100644 (file)
index 0000000..ba0084e
--- /dev/null
+++ b/time.c
@@ -0,0 +1,10 @@
+#include <unistd.h>
+
+#include "time.h"
+
+void msleep (int msec)
+{
+    usleep (msec * 1000);
+}
+
+/* vim: set ts=4 sw=4 et: */
diff --git a/time.h b/time.h
new file mode 100644 (file)
index 0000000..bc21d7f
--- /dev/null
+++ b/time.h
@@ -0,0 +1,8 @@
+#ifndef __TIME_H__
+#define __TIME_H__
+
+void msleep (int msec);
+
+#endif /* __TIME_H__ */
+
+/* vim: set ts=4 sw=4 et: */