From aedf71494b2011ceeb06b96e63da1c7a79a32e0e Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Fri, 27 Jun 2014 18:11:06 -0400 Subject: Restructure --- Makefile | 4 +- README.md | 6 +- chatbot.c | 9 +- games.c | 381 ------------------------------------------------------------- games.h | 3 - gtnw.c | 382 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gtnw.h | 3 + joshua.c | 13 ++- main.cpp | 3 +- map.h | 19 +++- strings.c | 1 + util.c | 10 +- 12 files changed, 426 insertions(+), 408 deletions(-) delete mode 100644 games.c delete mode 100644 games.h create mode 100644 gtnw.c create mode 100644 gtnw.h diff --git a/Makefile b/Makefile index 8382f75..7028920 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -SOURCES=joshua.o main.o util.o chatbot.o games.o strings.o -HEADERS=chatbot.h games.h joshua.h location.h strings.h map.h util.h +SOURCES=joshua.o main.o util.o chatbot.o gtnw.o strings.o +HEADERS=chatbot.h gtnw.h joshua.h location.h strings.h map.h util.h CXXFLAGS=-I. -lncurses -g -O3 CFLAGS=-I. -std=gnu99 -g -O3 wargames: $(SOURCES) $(HEADERS) diff --git a/README.md b/README.md index 89c9fa0..819053e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,4 @@ ==WarGames== Program to simulate the W.O.P.R. from WarGames, with WORKING Global Thermonuclear War! -For the uninitiated, the logon is "joshua" -Say hi, and that you are fine. -Then, say "love to" when Joshua asks to play a game -Then, type "later" -Then, enjoy the ASCII masterpiece! \ No newline at end of file +For the uninitiated, read the TRANSCRIPT file diff --git a/chatbot.c b/chatbot.c index 314ae78..ae3e2c6 100644 --- a/chatbot.c +++ b/chatbot.c @@ -1,10 +1,11 @@ -#include -#include +#include "gtnw.h" #include "strings.h" -#include +#include "util.h" + +#include +#include #include #include -#include void do_chatbot(void) { int stage=0; /* stage 0: i'm fine how are you... -> diff --git a/games.c b/games.c deleted file mode 100644 index 108d83f..0000000 --- a/games.c +++ /dev/null @@ -1,381 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -static bool surrender=false; -static int winner=0; /* on surrender */ -static unsigned int max(long long a, long long b) -{ - return a>b?a:b; -} -static void fire_missile(struct location_t* city) -{ - int random=rand()%100; - int x=city->x, y=city->y; - if(random>=90) /* crit */ - { - map[y][x]='!'; - city->population=0; - } - else if(random>=60) /* major */ - { - map[y][x]='X'; - city->population=max((double)city->population*(double).4-400, 0); - } - else if(random>=30) /* minor */ - { - map[y][x]='*'; - city->population=max((double)city->population*(double).6-200, 0); - } - else if(random>=10) /* marginal */ - { - map[y][x]='x'; - city->population=max((double)city->population*(double).8-100, 0); - } - else - { - map[y][x]='O'; - } -} -static void calc_pops(long long* us_pop, long long* ussr_pop) -{ - *us_pop=0; - *ussr_pop=0; - /* calculate populations */ - for(int i=0;iussr_back) - { - while(us_back!=ussr_back) - { - ussr_cities[ussr_back].print=false; - ++ussr_back; - } - } - us_cities[us_back].print=true; - us_cities[us_back].print_name="Total"; - us_cities[us_back].population=us_pop; - ussr_cities[ussr_back].print=true; - ussr_cities[ussr_back].print_name="Total"; - ussr_cities[ussr_back].population=ussr_pop; - ++us_back; - ++ussr_back; - print_string("\n\n"); - char buf[512]; - for(int i=0;i0 && move<5) - good=true; - } - switch(move) - { - case 1: - do_missile_launch(side); - break; - case 2: - do_peace_talks(side); - break; - case 3: - surrender=true; - winner=side==1?2:1; - break; - case 4: - break; - } -} - -void global_thermonuclear_war(void) -{ - srand(time(0)); - surrender=false; - clear(); - for(int i=0;i +#include +#include +#include +static bool surrender=false; +static int winner=0; /* on surrender */ +static unsigned int max(long long a, long long b) +{ + return a>b?a:b; +} +static void fire_missile(struct location_t* city) +{ + int random=rand()%100; + int x=city->x, y=city->y; + if(random>=90) /* crit */ + { + map[y][x]='!'; + city->population=0; + } + else if(random>=60) /* major */ + { + map[y][x]='X'; + city->population=max((double)city->population*(double).4-400, 0); + } + else if(random>=30) /* minor */ + { + map[y][x]='*'; + city->population=max((double)city->population*(double).6-200, 0); + } + else if(random>=10) /* marginal */ + { + map[y][x]='x'; + city->population=max((double)city->population*(double).8-100, 0); + } + else + { + map[y][x]='O'; + } +} +static void calc_pops(long long* us_pop, long long* ussr_pop) +{ + *us_pop=0; + *ussr_pop=0; + /* calculate populations */ + for(int i=0;iussr_back) + { + while(us_back!=ussr_back) + { + ussr_cities[ussr_back].print=false; + ++ussr_back; + } + } + us_cities[us_back].print=true; + us_cities[us_back].print_name="Total"; + us_cities[us_back].population=us_pop; + ussr_cities[ussr_back].print=true; + ussr_cities[ussr_back].print_name="Total"; + ussr_cities[ussr_back].population=ussr_pop; + ++us_back; + ++ussr_back; + print_string("\n\n"); + char buf[512]; + for(int i=0;i0 && move<5) + good=true; + } + switch(move) + { + case 1: + do_missile_launch(side); + break; + case 2: + do_peace_talks(side); + break; + case 3: + surrender=true; + winner=side==1?2:1; + break; + case 4: + break; + } +} + +void global_thermonuclear_war(void) +{ + srand(time(0)); + surrender=false; + clear(); + for(int i=0;i -#include +#include "chatbot.h" +#include "joshua.h" +#include "strings.h" /* predefined strings */ +#include "util.h" + #include -#include -#include #include -#include +#include #include -#include "strings.h" +#include void cleanup(int signum) { endwin(); diff --git a/main.cpp b/main.cpp index b2c31db..d21db5c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ -#include #include + #include +#include using namespace std; int main() { diff --git a/map.h b/map.h index dddaca6..4208788 100644 --- a/map.h +++ b/map.h @@ -1,4 +1,3 @@ -#define LITERAL(x) (char[]){x} char *map[] = { /* 0 */ (char[]){" ."}, /* 1 */ (char[]){" __________--^-^-\\. ____ __----/^\\."}, @@ -16,4 +15,20 @@ char *map[] = { /* 13 */ (char[]){""}, /* 14 */ (char[]){" UNITED STATES SOVIET UNION"} }; - +const char *const_map[] = { + /* 0 */ (char[]){" ."}, + /* 1 */ (char[]){" __________--^-^-\\. ____ __----/^\\."}, + /* 2 */ (char[]){"|\\/. \\__. ___/ || ___/ _/._-_ ."}, + /* 3 */ (char[]){"| \\. /. /. __ __/ /__/ \\/^^\\___-__."}, + /* 4 */ (char[]){"| L-^-/. /. \\.\\_-- \\."}, + /* 5 */ (char[]){"| / _/ _/\\/."}, + /* 6 */ (char[]){"|. | _/. __ __/"}, + /* 7 */ (char[]){" \\. /. / ___/.//"}, + /* 8 */ (char[]){" \\__ / | / \\/."}, + /* 9 */ (char[]){" \\________ __ _____.\\. \\_. ____--_ /\\_ \\"}, + /* 10 */ (char[]){" \\__. / V. \\ \\ \\__ _/. \\_/ //"}, + /* 11 */ (char[]){" \\ /. \\/. \\. _/. //"}, + /* 12 */ (char[]){" \\_/. \\_/"}, + /* 13 */ (char[]){""}, + /* 14 */ (char[]){" UNITED STATES SOVIET UNION"} +}; diff --git a/strings.c b/strings.c index e3459e0..1cc22ae 100644 --- a/strings.c +++ b/strings.c @@ -1,4 +1,5 @@ #include "strings.h" + const char* stage1_triggers[] = { "im fine", "im fine how are you", diff --git a/util.c b/util.c index a3c336b..2f319f9 100644 --- a/util.c +++ b/util.c @@ -1,9 +1,11 @@ -#include +#include "strings.h" +#include "util.h" + #include -#include -#include #include -#include "strings.h" +#include +#include + void allLower(char* str) { for(int i=0;str[i];++i) -- cgit v1.1