delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/04/14:45:30

Message-ID: <016201be965e$3c8390a0$12d098cd@co.alachua.fl.us>
From: "Dean Limbaugh" <edl AT ns1 DOT co DOT alachua DOT fl DOT us>
To: <djgpp AT delorie DOT com>
References: <01be9641$b606eb60$LocalHost AT thendren>
Subject: Re: Adventure game
Date: Tue, 4 May 1999 14:45:09 -0400
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Reply-To: djgpp AT delorie DOT com

You can look at the source for the mainframe zork game, translated from
fortran into very bad non ansii C, which will give some ideas on how to
handle words, commands, data structures, etc

http://www.perplexed.com/GPMega/files/game/zorksrc.zip


----- Original Message -----
From: Christopher Nelson <paradox AT gye DOT satnet DOT net>
To: <djgpp AT delorie DOT com>
Sent: Tuesday, May 04, 1999 11:20 AM
Subject: Adventure game


>
>
> >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
>                              file://currently is
>
>                            cbuf[pointer]=0; file://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