Click here to Skip to main content
15,919,121 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Convert to UCS-2 .. Pin
Michael Dunn9-May-04 20:11
sitebuilderMichael Dunn9-May-04 20:11 
GeneralRe: Convert to UCS-2 .. Pin
rasha200310-May-04 5:09
rasha200310-May-04 5:09 
Generalabout allocator Pin
vividtang8-May-04 21:16
vividtang8-May-04 21:16 
GeneralRe: about allocator Pin
toxcct9-May-04 5:54
toxcct9-May-04 5:54 
GeneralNewbie string question Pin
MikeUofPhx8-May-04 17:00
MikeUofPhx8-May-04 17:00 
GeneralRe: Newbie string question Pin
Anonymous8-May-04 20:27
Anonymous8-May-04 20:27 
GeneralRe: Newbie string question Pin
John R. Shaw8-May-04 22:13
John R. Shaw8-May-04 22:13 
GeneralRe: Newbie string question Pin
MikeUofPhx9-May-04 13:41
MikeUofPhx9-May-04 13:41 
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 />
/* Text Adventure-Console.cpp : Defines the entry point for the console application.*/<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 />
/*Variables - global*/<br />
char user_command[250];<br />
char waitkey [10];<br />
char *pch;<br />
/*enum directions {/*<br />
<br />
/* Defenitions - global */<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 />
}; /*Define the Map structure*/<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 />
	}; /* Instantiate map structure with 19 "Rooms" as my map - 0 is a dummy*/<br />
<br />
/*Set current room*/<br />
int current_room = 1;<br />
<br />
int main(int argc, char* argv[])<br />
{	<br />
/*Displays current stuff*/<br />
	refresh();<br />
	process_command();<br />
<br />
<br />
	return 0;<br />
<br />
}<br />
<br />
void refresh(void)<br />
{<br />
/*Display current room*/<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 />
/*What exits are visible?*/<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 />
	/*Gets command*/<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 />
	/*Process Command*/<br />
	/*Split in to words*/<br />
	char *words[11];<br />
	int wordnumber = 0;<br />
	char *pch;<br />
	pch = strtok (user_command, " ");<br />
	/*Load the first word*/<br />
	words[wordnumber]=pch;<br />
	/*Load each additional word into words[]*/<br />
	while ((pch != NULL) && (wordnumber < 10))// and word # is acceptable - add later//<br />
	{<br />
	 wordnumber++;<br />
	 words[wordnumber]=pch;<br />
	 pch = strtok (NULL, " ,.");<br />
	}<br />
	/*loop through*/<br />
	/*int count;*/<br />
	/* for(count=1;count<=wordnumber;count++)*/<br />
	/*{*/<br />
	/*Get last character, strcomp with enter, chomp*/<br />
	/*	printf("**%s**\n",words[count]);*/<br />
	/*}*/<br />
	/* */<br />
<br />
	int result;<br />
	char go[] = "go";<br />
	result = _strnicmp(words[1], go, 2 );<br />
<br />
	if (result==0)<br />
	{<br />
	/*go - what direction?*/<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 />
		/*Legal move?*/<br />
			if (my_map[current_room].north >= 1)<br />
			{<br />
				current_room = my_map[current_room].north;<br />
				/*Update Display*/<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 />
		/*Legal move?*/<br />
			if (my_map[current_room].south>= 1)<br />
			{<br />
				current_room = my_map[current_room].south;<br />
				/*Update Display*/<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 />
		/*Legal move?*/<br />
			if (my_map[current_room].west >= 1)<br />
			{<br />
				current_room = my_map[current_room].west;<br />
				/*Update Display*/<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 />
		/*Legal move?*/<br />
			if (my_map[current_room].east >= 1)<br />
			{<br />
				current_room = my_map[current_room].east;<br />
				/*Update Display*/<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 />
		/*Legal move?*/<br />
			if (my_map[current_room].up >= 1)<br />
			{<br />
				current_room = my_map[current_room].up;<br />
				/*Update Display*/<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 />
		/*Legal move?*/<br />
			if (my_map[current_room].down >= 1)<br />
			{<br />
				current_room = my_map[current_room].down;<br />
				/*Update Display*/<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 />
		/*Legal move?*/<br />
			if (my_map[current_room].other>= 1)<br />
			{<br />
				current_room = my_map[current_room].north;<br />
				/*Update Display*/<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 />

GeneralOLE DB 'IColumnsInfo2' problem Pin
KalliMan8-May-04 13:06
KalliMan8-May-04 13:06 
QuestionWhich of these methods is more efficient? Pin
Joe Smith IX8-May-04 12:48
Joe Smith IX8-May-04 12:48 
AnswerRe: Which of these methods is more efficient? Pin
Gary R. Wheeler8-May-04 13:39
Gary R. Wheeler8-May-04 13:39 
AnswerRe: Which of these methods is more efficient? Pin
Prakash Nadar8-May-04 22:35
Prakash Nadar8-May-04 22:35 
AnswerRe: Which of these methods is more efficient? Pin
Paul Ranson9-May-04 1:15
Paul Ranson9-May-04 1:15 
AnswerRe: Which of these methods is more efficient? Pin
Ravi Bhavnani9-May-04 4:29
professionalRavi Bhavnani9-May-04 4:29 
AnswerRe: Which of these methods is more efficient? Pin
Joe Woodbury9-May-04 7:59
professionalJoe Woodbury9-May-04 7:59 
GeneralRe: Which of these methods is more efficient? Pin
Tim Smith9-May-04 9:23
Tim Smith9-May-04 9:23 
GeneralRe: Which of these methods is more efficient? Pin
Joe Woodbury9-May-04 9:42
professionalJoe Woodbury9-May-04 9:42 
GeneralRe: Which of these methods is more efficient? Pin
Tim Smith9-May-04 13:47
Tim Smith9-May-04 13:47 
AnswerRe: Which of these methods is more efficient? Pin
Tim Smith9-May-04 9:27
Tim Smith9-May-04 9:27 
GeneralUsing MFC Source Code Question Pin
nm_1148-May-04 8:26
nm_1148-May-04 8:26 
GeneralRe: Using MFC Source Code Question Pin
Joe Woodbury8-May-04 8:41
professionalJoe Woodbury8-May-04 8:41 
GeneralRPC: Problem in sending data Pin
ahsan_a8-May-04 8:17
ahsan_a8-May-04 8:17 
GeneralRe: RPC: Problem in sending data Pin
ahsan_a8-May-04 12:03
ahsan_a8-May-04 12:03 
GeneralRe: RPC: Problem in sending data Pin
Gary R. Wheeler8-May-04 13:42
Gary R. Wheeler8-May-04 13:42 
QuestionAccess WindowProc in MFC? Pin
Anonymous8-May-04 7:04
Anonymous8-May-04 7:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.