Much appreciated. I changed the comments to C syntax. It's true that I'm not doing proper captue yet (the else statements) but I was hoping to find a better way. Rather than change the while statement I just adapted the bottom so subscripts match. I'm going to see if there is some way I could ste this up with a switch statement. Any suggestions (especially for a better way of processing commands) are much appreciated.
<br />
<br />
<br />
#include <stdio.h><br />
#include <stdlib.h><br />
#include <string.h><br />
#include <mbstring.h><br />
#include <dos.h><br />
<br />
#define CR 0x0d<br />
#define ESC 0x1b<br />
#define TAB 0x09<br />
#define LF 0x0a<br />
#define BACKSPACE 0x08<br />
#define NULL 0<br />
#define TRUE 1<br />
#define FALSE 0<br />
#define LENGTH 80<br />
#define COLS 80<br />
#define VIDEO 0x10<br />
#define ROWS 25<br />
#define DELAY 250<br />
#define MROW 12<br />
<br />
void refresh(void);<br />
void process_command(void);<br />
void main_thing(void);<br />
void cls(void);<br />
<br />
<br />
char user_command[250];<br />
char waitkey [10];<br />
char *pch;<br />
<br />
struct map {<br />
char *name;<br />
char *description;<br />
int north;<br />
int south;<br />
int west;<br />
int east;<br />
int up;<br />
int down;<br />
int other;<br />
}; <br />
struct map my_map[22] = {<br />
{"Location0", "Dummy Location", 0,0,0,0,0,0,0},<br />
{"Location1", "Admissions", 2,0,10,17,0,0,0},<br />
{"Location2", "Lovely Lounge", 3,1,5,4,0,0,0},<br />
{"Location3", "Main Hallway", 20,2,6,13,0,0,0},<br />
{"Location4", "TV Room", 0,0,2,19,0,0,0},<br />
{"Location5", "Mess Hall", 6,0,12,2,0,0,0},<br />
{"Location6", "Crafts Room", 0,5,11,3,0,0,0},<br />
{"Location7", "Therapy Room", 0,0,0,20,0,0,0},<br />
{"Location8", "Padded Cell", 0,0,20,0,0,0,0},<br />
{"Location9", "Mike's Room", 0,0,16,0,0,0,0},<br />
{"Location10", "Nurse's Station", 0,0,0,1,0,0,0},<br />
{"Location11", "Group Therapy Room", 0,0,0,6,0,0,0},<br />
{"Location12", "Fenced Patio", 0,0,0,5,0,0,0},<br />
{"Location13", "Showers", 0,0,3,0,0,0,0},<br />
{"Location14", "Violent Ward", 0,0,0,21,18,0,0},<br />
{"Location15", "Honest Politician's Ward", 0,21,0,0,0,0,0},<br />
{"Location16", "Depressed College Student's Ward", 0,0,21,9,0,0,0},<br />
{"Location17", "Phone Booth", 0,0,1,0,0,0,0},<br />
{"Location18", "Secret Ritual Room", 0,0,0,0,0,14,0},<br />
{"Location19", "Psychiatrist's Lounge", 0,0,4,0,0,0,0},<br />
{"Location20", "Hallway part 2", 21,3,7,8,0,0,0},<br />
{"Location21", "Hallway part 3", 15,20,14,16,0,0,0}<br />
}; <br />
<br />
<br />
int current_room = 1;<br />
<br />
int main(int argc, char* argv[])<br />
{ <br />
<br />
refresh();<br />
process_command();<br />
<br />
<br />
return 0;<br />
<br />
}<br />
<br />
void refresh(void)<br />
{<br />
<br />
cls();<br />
printf("*** Josh's fantastic escape from the C Sanitarium for burnt out Coderz ***\n");<br />
printf("\n\n");<br />
printf("LOCATION : %s\n", my_map[current_room].name);<br />
printf("DESCRIPTION : %s\n",my_map[current_room].description);<br />
printf("WHAT'S HERE :\n");<br />
printf("VISIBLE EXITS:");<br />
<br />
<br />
if (my_map[current_room].north >= 1)<br />
{<br />
printf("North ");<br />
}<br />
<br />
if (my_map[current_room].south >= 1)<br />
{<br />
printf(" South ");<br />
}<br />
if (my_map[current_room].west >= 1)<br />
{<br />
printf(" West ");<br />
}<br />
if (my_map[current_room].east >= 1)<br />
{<br />
printf(" East ");<br />
}<br />
if (my_map[current_room].up >= 1)<br />
{<br />
printf(" Up ");<br />
}<br />
if (my_map[current_room].down >= 1)<br />
{<br />
printf(" Down ");<br />
}<br />
if (my_map[current_room].other >= 1)<br />
{<br />
printf(" Other ");<br />
}<br />
<br />
printf("\n");<br />
printf("\nWhat would you like to do?\n");<br />
<br />
fgets(user_command, sizeof(user_command), stdin);<br />
fflush(stdin);<br />
printf("\n");<br />
}<br />
void process_command(void)<br />
{<br />
<br />
<br />
char *words[11];<br />
int wordnumber = 0;<br />
char *pch;<br />
pch = strtok (user_command, " ");<br />
<br />
words[wordnumber]=pch;<br />
<br />
while ((pch != NULL) && (wordnumber < 10))
{<br />
wordnumber++;<br />
words[wordnumber]=pch;<br />
pch = strtok (NULL, " ,.");<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
int result;<br />
char go[] = "go";<br />
result = _strnicmp(words[1], go, 2 );<br />
<br />
if (result==0)<br />
{<br />
<br />
char north[] = "north";<br />
char south[] = "south";<br />
char west[] = "West";<br />
char east[] = "east";<br />
char up[] = "up";<br />
char down[] = "down";<br />
char other[] = "other";<br />
<br />
int result;<br />
result = _strnicmp(words[2], north, 5 );<br />
<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].north >= 1)<br />
{<br />
current_room = my_map[current_room].north;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], south, 5 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].south>= 1)<br />
{<br />
current_room = my_map[current_room].south;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], west, 4 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].west >= 1)<br />
{<br />
current_room = my_map[current_room].west;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2],east, 4 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].east >= 1)<br />
{<br />
current_room = my_map[current_room].east;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], up, 2 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].up >= 1)<br />
{<br />
current_room = my_map[current_room].up;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], down, 4 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].down >= 1)<br />
{<br />
current_room = my_map[current_room].down;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], other, 5 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].other>= 1)<br />
{<br />
current_room = my_map[current_room].north;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
}<br />
char blow[]="blow";<br />
result = _strnicmp(words[1], blow, 4 );<br />
if (result==0)<br />
{<br />
printf("you typed blow");<br />
}<br />
}<br />
void main_thing(void)<br />
{<br />
refresh();<br />
process_command();<br />
}<br />
void cls( void )<br />
{<br />
system("cls");<br />
}<br />
|