Board index » delphi » help begginer with text game.

help begginer with text game.

i am a begginer at pascal but i think i have enough understanding of
it to start a simple text game. the one thing that i can't figure
out is how to be able to pick something up and use it later in the game
(like invitory)and look at what i have picked up earlier in the game.
if anybody can help please do. PLEASE RESPOND ON THIS NEWS GROUP ONLY
CAUSE MY E-MAIL HAS GIVING ME A FIT.

HOPELESS

 

Re:help begginer with text game.


i am a begginer at pascal but i think i have enough understanding of
it to start a simple text game. the one thing that i can't figure
out is how to be able to pick something up and use it later in the game
(like invitory)and look at what i have picked up earlier in the game.
if anybody can help please do. PLEASE RESPOND ON THIS NEWS GROUP ONLY
CAUSE MY E-MAIL HAS GIVING ME A FIT.

HOPELESS

Re:help begginer with text game.


On 26 Oct 1995, Jim Moore wrote:

Quote
> i am a begginer at pascal but i think i have enough understanding of
> it to start a simple text game. the one thing that i can't figure
> out is how to be able to pick something up and use it later in the game
> (like invitory)and look at what i have picked up earlier in the game.
> if anybody can help please do. PLEASE RESPOND ON THIS NEWS GROUP ONLY
> CAUSE MY E-MAIL HAS GIVING ME A FIT.

When you pick something up, just store it in an array.  Keep a
counter/pointer so you know which element of the array to put it into.  
The later you can just search the array.
Hope this help.  
***************************************************************************
* Matt Dew                  |        it's only fun            |            *
* ECEN                      |              if                 |            *
* d...@ucsu.colorado.edu     |     there's more to learn       |            *
*                                                                          *
*               With Assembly, the argument of which language              *
*                     is fastest and tightest is futile.                   *
*                        Assembly always and forever..                     *
***************************************************************************

Re:help begginer with text game.


Quote
Jim Moore <jmo...@magicnet.net> wrote:
>i am a begginer at pascal but i think i have enough understanding of
>it to start a simple text game. the one thing that i can't figure
>out is how to be able to pick something up and use it later in the game
>(like invitory)and look at what i have picked up earlier in the game.
>if anybody can help please do. PLEASE RESPOND ON THIS NEWS GROUP ONLY
>CAUSE MY E-MAIL HAS GIVING ME A FIT.
>HOPELESS

Use something like:

const
Total_number_of Objects = whatever

var
self : array [1..Total_number_of_Objects] of string;
Objects_in_hand : integer

Define function keys to pick stuff up or display the inventory.

The fucntion keys ID can be found by running the following or
looking in the book.

Program whichkey;
{ From Borland's Turbo on line Help }

uses Crt;
var
  Ch : Char;
begin
   WriteLn('Press a key');
   Ch := ReadKey;
   if Ch = #0 then
     begin
     Ch := ReadKey;
     WriteLn('You hit special key number ',
             Ord(Ch));
     end
   else
     WriteLn('You hit a key with ASCII ',
             'code ',Ord(Ch));
end.

Initiate Objects_in_hand := 0;    When you pick stuff up:

Inc(Objects_in_hand);
Self[Objects_in_hand] := 'key',  etc.

To display inventory:
FOR N :=1 TO Objects_in_hand DO
    Writeln(self[n]);

<clifp...@airmail.net>

Re:help begginer with text game.


Quote
>On 26 Oct 1995, Jim Moore wrote:

>> i am a begginer at pascal but i think i have enough understanding of
>> it to start a simple text game. the one thing that i can't figure
>> out is how to be able to pick something up and use it later in the game
>> (like invitory)and look at what i have picked up earlier in the game.
>> if anybody can help please do. PLEASE RESPOND ON THIS NEWS GROUP ONLY
>> CAUSE MY E-MAIL HAS GIVING ME A FIT.

If you're into Object Pascal (which doesn't seem too likely as you described
yourself as a beginner, anyway), make an object-type TThing, then make a linked
list of things (call it, for instance, TInventory), you can either use
TCollection or implement your own list-handling. some sample code:

type
  PThing = ^TThing;

  TThing = object
    NextThing: Pthing;
         ThingName: string;
         {...
         a lot of methods to handle the thing
         ...}
         constructor Init(ThingName: string);
         destructor Done;
  end;

  TInventory = object
    FirstThing: PThing;
         function GetThing(ThingName: string);
         procedure InsertThing(OThing: PThing);
         procedure RemoveThing(ThingName: string);
         constructor Init;
         destructor Done;
  end;

If all the above seemed like gibberish to you then try with an array instead,
store either pointers to things or, if you're not into objects and pointers at
all, store a record-type variable with data on your items. For instance:

type
  Item = record
    Name: string;
         {...
          A lot of fields with data on the thing
          ...}
  end;
  Inventory = Array [1..20] of Item;

This sample limits the number of items you can carry to 20, something the upper
sample doesn't, the lower one is however faster, smaller, easier and less error
prone. Oh, you'll have to declare some sort of counter to know where in the
array the next item should be added.

Now don't try to run these through a compiler, it was a while ago since I wrote
Pascal code (programming Simula right now, yuck!) and I might have gotten
the details and grammar wrong. Basically this should do it however.

--
Jens Alm
d95...@efd.lth.se

| DISCLAIMER: I do not represent the | URL: http://www.efd.lth.se/~d95jal   |
| alien civilization in which I was  |                                      |
| raised. They have far more         | Do not take anything I say seriously |
| efficient ways of communication    | as it springs from divine madness    |

Other Threads