aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chatbot.c15
-rw-r--r--games.c59
-rw-r--r--joshua.c1
-rw-r--r--location.h28
-rw-r--r--main.cpp1
-rw-r--r--strings.c17
-rw-r--r--strings.h6
-rw-r--r--util.c9
8 files changed, 98 insertions, 38 deletions
diff --git a/chatbot.c b/chatbot.c
index ddc0eff..6217696 100644
--- a/chatbot.c
+++ b/chatbot.c
@@ -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");
diff --git a/games.c b/games.c
index 21c982f..a4234ce 100644
--- a/games.c
+++ b/games.c
@@ -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';
diff --git a/joshua.c b/joshua.c
index fc9d1f6..fb7190c 100644
--- a/joshua.c
+++ b/joshua.c
@@ -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;
diff --git a/location.h b/location.h
index 57c9b0d..974da64 100644
--- a/location.h
+++ b/location.h
@@ -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},
};
diff --git a/main.cpp b/main.cpp
index 1180f8f..6b2dbb3 100644
--- a/main.cpp
+++ b/main.cpp
@@ -4,4 +4,5 @@ using namespace std;
int main()
{
be_joshua();
+ endwin();
}
diff --git a/strings.c b/strings.c
index 69cff57..a2be3d9 100644
--- a/strings.c
+++ b/strings.c
@@ -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[] = {
'\'', '?', '.', '/', '`', '~', ',', '+', '!'
};
diff --git a/strings.h b/strings.h
index 0a06689..da14086 100644
--- a/strings.h
+++ b/strings.h
@@ -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
diff --git a/util.c b/util.c
index 6ca83fe..a3c336b 100644
--- a/util.c
+++ b/util.c
@@ -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;