diff options
| author | Franklin Wei <frankhwei536@gmail.com> | 2014-06-23 17:04:30 -0400 |
|---|---|---|
| committer | Franklin Wei <frankhwei536@gmail.com> | 2014-06-23 17:04:30 -0400 |
| commit | 7c3ee246fb626ab09b3b05055efdfaf3a00e60e7 (patch) | |
| tree | 231d914a2677fdf8e466c972b62b4d9632698aa9 | |
| parent | 35e1fd6820cd05c180e180d0ec61457a9f31e196 (diff) | |
| download | wargames-server-7c3ee246fb626ab09b3b05055efdfaf3a00e60e7.zip wargames-server-7c3ee246fb626ab09b3b05055efdfaf3a00e60e7.tar.gz wargames-server-7c3ee246fb626ab09b3b05055efdfaf3a00e60e7.tar.bz2 wargames-server-7c3ee246fb626ab09b3b05055efdfaf3a00e60e7.tar.xz | |
Fixed more bugs, added more features :)
| -rw-r--r-- | chatbot.c | 15 | ||||
| -rw-r--r-- | games.c | 59 | ||||
| -rw-r--r-- | joshua.c | 1 | ||||
| -rw-r--r-- | location.h | 28 | ||||
| -rw-r--r-- | main.cpp | 1 | ||||
| -rw-r--r-- | strings.c | 17 | ||||
| -rw-r--r-- | strings.h | 6 | ||||
| -rw-r--r-- | util.c | 9 |
8 files changed, 98 insertions, 38 deletions
@@ -4,6 +4,7 @@ #include <games.h> #include <string.h> #include <unistd.h> +#include <stdlib.h> void do_chatbot(void) { int stage=0; /* stage 0: i'm fine how are you... -> @@ -39,6 +40,7 @@ void do_chatbot(void) valid=true; } } + break; case 1: for(int i=0;i<sizeof(stage2_triggers)/sizeof(const char*);++i) { @@ -49,6 +51,7 @@ void do_chatbot(void) valid=true; } } + break; case 2: for(int i=0;i<sizeof(stage3_triggers)/sizeof(const char*);++i) { @@ -59,6 +62,7 @@ void do_chatbot(void) valid=true; } } + break; case 3: for(int i=0;i<sizeof(stage4_triggers)/sizeof(const char*);++i) { @@ -70,7 +74,18 @@ void do_chatbot(void) global_thermonuclear_war(); } } + break; } // switch + for(int i=0;i<sizeof(exit_triggers)/sizeof(const char*);++i) + { + if(strcmp(buf, exit_triggers[i])==0) + { + print_string("\n\n"); + print_string(exit_responses[rand()%sizeof(exit_responses)/sizeof(const char*)]); + print_string("\n--CONNECTION TERMINATED--"); + return; + } + } if(!valid) { print_string("\n\n"); @@ -31,6 +31,8 @@ void global_thermonuclear_war(void) char target_names[32][129]; good=true; int num_targets=0; + struct location_t targets[32]; + int num_targets_found=0; for(int i=0;i<32 && good;++i) { getnstr(target_names[i], 128); @@ -41,31 +43,42 @@ void global_thermonuclear_war(void) else { ++num_targets; + allLower(target_names[i]); + remove_punct(target_names[i]); + bool found=false; + for(int j=0;j<sizeof(world)/sizeof(struct location_t);++j) + { + if(strcmp(world[j].name, target_names[i])==0) + { + found=true; + if(world[j].owner!=side) + { + targets[num_targets_found]=world[j]; + ++num_targets_found; + } + else + { + print_string("\n\nATTEMPTING TO FIRE AT OWN CITY.\nPLEASE CONFIRM (YES OR NO): "); + char response[17]; + getnstr(response, 16); + allLower(response); + remove_punct(response); + if(strcmp(response, "yes")==0 || strcmp(response, "y")==0) + { + targets[num_targets_found]=world[j]; + ++num_targets_found; + } + } + } + } + if(!found) + { + print_string("TARGET NOT FOUND: "); + print_string(target_names[i]); + print_string("\n"); + } } } - struct location_t targets[32]; - int num_targets_found=0; - for(int i=0;i<num_targets;++i) - { - allLower(target_names[i]); - remove_punct(target_names[i]); - bool found=false; - for(int j=0;j<sizeof(world)/sizeof(struct location_t);++j) - { - if(strcmp(world[j].name, target_names[i])==0) - { - targets[num_targets_found]=world[j]; - ++num_targets_found; - found=true; - } - } - if(!found) - { - print_string("TARGET NOT FOUND: "); - print_string(target_names[i]); - print_string("\n"); - } - } for(int i=0;i<num_targets_found;++i) { map[targets[i].y][targets[i].x]='X'; @@ -31,6 +31,7 @@ void be_joshua() start_color(); init_pair(1, COLOR_BLUE, COLOR_BLACK); attron(COLOR_PAIR(1));*/ + scrollok(stdscr, true); bool gamesPhase=false; char buf[33]; int maxx, maxy; @@ -1,25 +1,27 @@ /* provide the GTNW with some geographical data to draw the missiles */ +enum player_t { USA=1, USSR }; struct location_t { const char* name; int x; int y; /* x,y-coords on the map */ + enum player_t owner; }; struct location_t world[]={ /* US cities */ - {"las vegas", 5, 7}, - {"seattle", 3, 2}, - {"new york", 34, 5}, - {"new orleans", 25, 10}, - {"washington", 33, 6}, - {"washington dc", 33, 6}, - {"winston-salem", 30, 7}, - {"san francisco", 1, 6}, - {"chicago", 24, 4}, - {"miami", 32, 11}, + {"las vegas", 5, 7, USA}, + {"seattle", 3, 2, USA}, + {"new york", 34, 5, USA}, + {"new orleans", 25, 10, USA}, + {"washington", 33, 6, USA}, + {"washington dc", 33, 6, USA}, + {"winston-salem", 30, 7, USA}, + {"san francisco", 1, 6, USA}, + {"chicago", 24, 4, USA}, + {"miami", 32, 11, USA}, /* Soviet cities */ /* NOTE: These are not neccessarily correct. I simply eyed them relative to Murmansk */ - {"murmansk", 74, 1}, - {"moscow", 70, 5}, - {"minsk", 66, 4}, + {"murmansk", 74, 1, USSR}, + {"moscow", 70, 5, USSR}, + {"minsk", 66, 4, USSR}, }; @@ -4,4 +4,5 @@ using namespace std; int main() { be_joshua(); + endwin(); } @@ -2,6 +2,8 @@ const char* stage1_triggers[] = { "im fine", "im fine how are you", + "i am fine", + "i am fine how are you", "how are you" }; const char* stage2_triggers[] = { @@ -23,9 +25,24 @@ const char* stage4_triggers[] = { "no lets play global thermonuclear war instead", "later lets play global thermonuclear war", "later lets play global thermonuclear war instead", + "later", "lets play global thermonuclear war", "global thermonuclear war is better" }; +const char* exit_triggers[] = { + "goodbye", + "good-bye", + "bye", + "bye-bye", + "see you later", + "logout" +}; +const char* exit_responses[] = { + "GOODBYE.", + "BYE!", + "BYE-BYE!", + "GOOD-BYE.", +}; const char punctuation_marks[] = { '\'', '?', '.', '/', '`', '~', ',', '+', '!' }; @@ -1,8 +1,10 @@ #ifndef WOPR_STRINGS #define WOPR_STRINGS -const char* stage1_triggers[3]; +const char* stage1_triggers[5]; const char* stage2_triggers[6]; const char* stage3_triggers[4]; -const char* stage4_triggers[6]; +const char* stage4_triggers[7]; const char punctuation_marks[9]; +const char* exit_triggers[6]; +const char* exit_responses[4]; #endif @@ -13,10 +13,19 @@ void allLower(char* str) } void print_string(const char* str) /* print string, slowly */ { + int window_height; + int junk; + getmaxyx(stdscr, window_height, junk); int i=0; while(str[i]) { addch(str[i]); + int cursx, cursy; + getyx(stdscr, cursy, cursx); + if(cursy==window_height) + { + scroll(stdscr); + } usleep(SLEEP_TIME); refresh(); ++i; |