From: "Christopher Nelson" To: Subject: Adventure game Date: Tue, 4 May 1999 09:20:58 -0600 Message-ID: <01be9641$b606eb60$LocalHost@thendren> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.71.1712.3 X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3 Reply-To: djgpp AT delorie DOT com >Hey im a beginner but i sorta wanna jump ahead and instead of e-mailing for >everything i needed one at a time im doing them all at once!: I want to make >a little text-adventure game. I know how to output the text to the screen and >get the user input( i use cin and cout, i dont know any other way )but first >how would get input with spaces? Such as: Kill Enemy or Get Bottle? How would >i make those actions work? How do i use random things like...you go north, >random to pick enemies or some items? How do i save the game to a dat file as >it goes along ( remembers dead enemies or picked up items, also how do i add >items to a var. like if i wanted to add a Bottle and a Box to items and then >output it)and save and load at the end(quit)? this isn't too much at all, really. the easiest way to get input like that would be to use getc() verses cin, or just do cin characters, e.g. char c; cin >> c; then, you have a loop that gets each character in turn. when you read a newline (\n), you can go through the buffer that you've been saving in and see if the command is valid. alternatively, you can try to check each word as it is typed... meaning, when you detect a space, check the word against a list of commands. if the command is invalid, you might have a little status bar at the bottom that says so. (instead of just clearing the line and saying so where they're typing.) e.g: char cbuf[255]; // big command buffer int pointer=0; // start at beginning of buffer char cmnd_done=0, c; char cur_cmnd=0; do { if (kbhit()) c=getc(stdin); switch(c) { case 32: // if it's a space, check to see what the command in the buffer //currently is cbuf[pointer]=0; //terminates the string so that we can strcmp it. if (cur_cmnd ==0) cur_cmnd = is_command(cbuf); // etc. you can do lots of interesting stuff here... break; case '\n': cbuf[pointer]=0; cmnd_done=1; break; default: cbuf[pointer++] = c; break; } } } while(!cmnd_done); anyway, something of the sort... -={C}=-