Author Topic: The Phantom Temple Game  (Read 5467 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: The Phantom Temple Game
« Reply #15 on: September 22, 2020, 01:30:11 pm »
Just my 2% of a dollar here. 

You really want to look into working with arrays when you run into something like this. This is a limit to what the internal compiler can handle believe it or not. So when you get in a situation where you must do something over and over (1105 times, lets say) you really want to handle that with a looping system and array to keep your code smaller. And that is doubly true of anything with PRINT statements.

sometimes just having little tweaks can make big differences too, like for the directions use a single _BYTE instead of a string.
A super simplistic(can do it in an even smaller way)
Code: QB64: [Select]
  1. DIM SHARED Directions(3) AS STRING
  2. DATA "NORTH","EAST","WEST","SOUTH":' NEWS
  3. FOR I% = 0 TO 3
  4.  READ Directions(I%)
  5. NEXT I%
  6.  
  7. DIM SHARED ROOMPATHS(1105) AS _BYTE
  8. ROOMPATHS(0) = 14 'as example you can go EAST, WEST, or SOUTH from the very first ROOM
  9. 'Then store the possible directions for a room with a simple number, 1 for north, 2 for east, 4 for west, and 8 for south
  10. 'so a value of 9 gets you NORTH and SOUTH, a value of 15 get you NORTH, EAST, WEST, and SOUTH
  11. 'Then you run those numbers
  12.  
  13. PRINT "In this room you can see paths to the ";
  14. IF ROOMPATHS(0) AND 1 THEN PRINT "NORTH,"
  15. IF ROOMPATHS(0) AND 2 THEN PRINT "EAST,"
  16. IF ROOMPATHS(0) AND 4 THEN PRINT "WEST,"
  17. IF ROOMPATHS(0) AND 8 THEN PRINT "SOUTH"
  18.  
  19. 'Granted in the end you would want to replace the 0 with a variable containing which room the player is entering.
  20.  

and making that a routine would be the way to go.
Code: QB64: [Select]
  1. SUB ROOM_DIRECTIONS(ROOMID%)
  2.  IF ROOMPATHS(ROOMID%) AND 1 THEN PRINT "NORTH,"
  3.  IF ROOMPATHS(ROOMID%) AND 2 THEN PRINT "EAST,"
  4.  IF ROOMPATHS(ROOMID%) AND 4 THEN PRINT "WEST,"
  5.  IF ROOMPATHS(ROOMID%) AND 8 THEN PRINT "SOUTH"
  6.  

And format that however you want. print each direction on its own line or list them all on a single line, whatever.

okay that may have been 5% of a dollar but so be it.
Granted after becoming radioactive I only have a half-life!

Offline MidnightOwl

  • Newbie
  • Posts: 5
    • View Profile
Re: The Phantom Temple Game
« Reply #16 on: September 23, 2020, 01:56:40 am »
To add my 2 cents. Everything should be in arrays, room descriptions, object  descriptions, object locations,etc. Then when the data is read from a file the code gets very small. For a complete discussion of this read 'Creating Basic Adventure Programs by Frank Decosta.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: The Phantom Temple Game
« Reply #17 on: September 23, 2020, 11:35:35 am »
To add my 2 cents. Everything should be in arrays, room descriptions, object  descriptions, object locations,etc. Then when the data is read from a file the code gets very small. For a complete discussion of this read 'Creating Basic Adventure Programs by Frank Decosta.

IMHO a game with lot's and lot's of text should have the Text in separate file. It easier to write the text and manage it in a text editor and you can have a simple little sub to load the text file and mark the start and end points of the text ( a once and for all time running thing) in an array for speedy binary lookup of the text block. The bas program would be tiny and easy to manage too, specially if one insists on all GOSUBS.

Welcome to the forum! @MidnightOwl
« Last Edit: September 23, 2020, 12:21:59 pm by bplus »