Writing an Adventure Game 01

Introducing a series of posts about coding an adventure game in BB4W.  The aim here is to provide an introduction to programming.  Each post will build on the last and introduce new functionality to the game.

Let's start by creating our game world within the computer.  I'm going to create a 3x3 game world - so just 9 locations in total to keep things simple.

     dim World$(3,3) 

This command reserves 9 locations in memory that we can use for our 'world' arranged in a 3 by 3 grid or array.

Inside the computer's memory, the 'world' looks like a grid.  The game world is represented as a 3x3 grid of 9 locations.
The next step is to 'populate' the grid. The procedure 'populateWorld' is invoked which reads the names of the spaces into the array.

Adding the names of the spaces using the read command.  The names are stored as data commands in the program itself.
The next step is to record some data about the player character.  For example, it would be useful to record which space the player is currently exploring.  Let's start him/her at the 'Village', so his/her starting coordinates are (2,2).  We will use to variables to store this information.

Once you have the code loaded you can test the program works.

Run the program.  It won't do very much, but try typing: PRINT World$(2,1) after the prompt.  It should tell you the name of space (2,1).

Testing that the program reads the space names in correctly.  What happens if you type PRINT World$(4,5) ?

...and that's it for this post....

...next time... how to move the player around the 'world'.

Source code follows:

     REM an adventure game in BB4W
     REM by Mr Street

     REM version 1.0.0.1

     REM let's set up a 'world'
     
DIM World$(3,3) : REM creates a 3x3 grid
     REM now 'populate' the grid with some space names
     
PROC_populateWorld
     REM now some data about our player
     REM player's starting position
     
x% = 2
     y% = 2
     REM player's health
     
health% = 50

     REM next time... moving the player around the 'World'

     
PRINT "That's all folks"
     END


     
DEFPROC_populateWorld
     REM puts some names of the spaces into the World
     
LOCAL x%, y%
     REM start with the first row
     
FOR y% = 1 TO 3
       FOR x% = 1 TO 3
         READ World$(x%,y%)
       NEXT
     NEXT
     ENDPROC
     
:
     REM the data for our 3x3 grid
     
DATA "Hills",  "Mountains", "Forest"
     
DATA "Castle", "Village", "Fields"
     
DATA "Woods",  "Swamp",  "Lake"