www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/07/12:05:25

From: "Shaggs" <jud AT tminet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Adventure game
Date: Thu, 6 May 1999 21:20:18 -0700
Organization: Posted via RemarQ Communities, Inc.
Lines: 105
Message-ID: <926050585.729.92@news.remarQ.com>
References: <01be9641$b606eb60$LocalHost AT thendren>
NNTP-Posting-Host: 208.145.132.45
NNTP-Posting-Date: Fri, 07 May 1999 04:16:25 GMT
X-Trace: 926050585.729.92 K8TBLZBRT842DD091C usenet1.supernews.com
X-Complaints-To: newsabuse AT remarQ DOT com
X-Newsreader: Microsoft Outlook Express 4.72.3612.1700
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

one step at a time. dont rush yourself

enough searching on yahoo or other engines using very specific terms such as
"keyboard routine" and whatnot will help sift out trash like logitech
perhiprial sellers

Christopher Nelson wrote in message
<01be9641$b606eb60$LocalHost AT thendren>...
>
>
>>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}=-
>
>
>


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019