]> git.sur5r.net Git - c128-kasse/commitdiff
guthaben kann nun auch genutzt werden..
authorsECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Sat, 28 Jul 2007 20:48:31 +0000 (20:48 +0000)
committersECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Sat, 28 Jul 2007 20:48:31 +0000 (20:48 +0000)
git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@25 af93e077-1a23-4f1e-9cbe-9382a9d578f5

credit_manager.c
kasse.c

index 12128a9cf9cac36c1e364001a04f88a625900c60..65a5293cc21c91498a7c083305a8f3ebd4146b0d 100644 (file)
@@ -64,7 +64,7 @@ void credit_manager() {
                                free(filter);
                                filter = NULL;
                        } else filter_len = strlen(filter);
-               } else if (c == 'z')
+               } else if (c == 'z' || c == 'q')
                        break;
        }
 }
diff --git a/kasse.c b/kasse.c
index 327aa88feec08367640cf25ed54353c03909e5c8..684af7294f3959b7fa02425ee7253a206efbd00c 100644 (file)
--- a/kasse.c
+++ b/kasse.c
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <conio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "general.h"
 #include "config.h"
@@ -16,7 +17,7 @@ void print_screen() {
        uc i = 0;
        clrscr();
        printf("C128-Kassenprogramm\n\n");
-       printf("Eingenommen: %ld Euro, Verkauft: %ld Flaschen, Drucken: %s\n\n", money * 100, items_sold, (printing == 1 ? "ein" : "aus"));
+       printf("Eingenommen: %ld Cents, Verkauft: %ld Flaschen, Drucken: %s\n\n", money, items_sold, (printing == 1 ? "ein" : "aus"));
        for (; i < num_items; ++i)
                printf("Eintrag %x: %s (%d Cents, %d mal verkauft)\n", i, status[i].item_name, status[i].price, status[i].times_sold);
        printf("\nBefehle: s) Daten sichern d) Drucken umschalten g) Guthabenverwaltung\n");
@@ -39,9 +40,10 @@ void print_log(uc n, int einheiten, char *nickname) {
 void buy(uc n) {
        int negative = 1;
        char entered[5] = {'1', 0, 0, 0, 0};
-       uc i = 0;
-       uc c;
+       uc i = 0, matches = 0;
+       uc c, nickname_len, single_match;
        int einheiten;
+       char *nickname;
        if (status[n].item_name == NULL)
                printf("FEHLER: Diese Einheit existiert nicht.\n");
        else {
@@ -56,12 +58,44 @@ void buy(uc n) {
                                entered[i++] = c;
                }
                einheiten = atoi(entered) * negative;
+               printf("\nAuf ein Guthaben kaufen? Wenn ja, Nickname eingeben:\n");
+               nickname = get_input();
+               if (nickname[0] == '\0') {
+                       free(nickname);
+                       nickname = NULL;
+               } else {
+                       nickname_len = strlen(nickname);
+                       /* go through credits and remove the amount of money or set nickname
+                        * to NULL if no such credit could be found */
+                       for (c = 0; c < num_credit_items; ++c)
+                               if (strncmp(nickname, credits[c].nickname, nickname_len) == 0) {
+                                       if (++matches == 2)
+                                               break;
+                                       else single_match = c;
+                               }
+                       if (matches == 1) {
+                               if (credits[single_match].credit < (status[n].price * einheiten)) {
+                                       printf("Sorry, %s hat nicht genug Geld :-(\n", nickname);
+                                       free(nickname);
+                                       return;
+                               } else {
+                                       /* Geld abziehen */
+                                       credits[single_match].credit -= (status[n].price * einheiten);
+                                       printf("\nVerbleibendes Guthaben fuer %s: %d Cents. Druecke ANYKEY...\n", nickname, credits[single_match].credit);
+                                       getchar();
+                               }
+                       } else {
+                               free(nickname);
+                               nickname = NULL;
+                       }
+               }
                status[n].times_sold += einheiten;
                money += status[n].price * einheiten;
                items_sold += einheiten;
-               // TODO: NULL in nickname des guthabenden ändern
                if (printing == 1)
-                       print_log(n, einheiten, NULL);
+                       print_log(n, einheiten, nickname);
+               if (nickname != NULL)
+                       free(nickname);
        }
 }