Dragon Adventure Game – Maze building

For my dragon adventure game, i need to build a ‘maze’. The NetLogo screen itself is an ok size, but if i want playable characters suitable for a video game, i need to use more space.

Firstly, i designed my simple maze on pen and paper.

the initial maze design – a 4×4 grid

As you can see I started with a 4×4 grid counting from 1, but the NetLogo array function counts from 0, so i redid the map starting from 0. This becomes significant when building the array.

array 1, counting from 1 and slightly unordered, array , more sequential and from 0

So having completed the array for the maze and the interconnecting rooms, I explored how to code this in NetLogo.

Firstly, I found some pseudo code, this time based on python as I have programming experience of it

;map = {'corridor':['room1','room2'],'room1':['corridor'],'room2':['corridor'] - python method

So in the python, it defines two rooms and corridor, with how they are connected. This is great for a text based adventure, i want to keep it simpler and not really name the rooms, just from my physical map know which rooms are, so reduced that to numbers.

I started with following the array example from the NetLogo dictionary, adjusting for the amount of rooms i needed (16).

let a array:from-list n-values 16 [0] ; init array a with 16 values of 0

So my room ‘0’ connects to room ‘1’, and room ‘1’ connects to ‘0, 5, 2’

  array:set a 0 "1"
  array:set a 1 "0,5,2"

As I am testing, i want to see the value of the array in the console as well.

print a

To make this work in NetLogo i need to create the ‘setup’ button and assign to a routine, so i create the ‘setup’ button from the ‘add’ item menu, and give it the routine ‘setup’

add the setup button

I then wrap the array creation in a the standard function, not forgetting to add the array extension.

extensions [array]

to setup
  let a array:from-list n-values 16 [0] ; init array a with 16 values of 0
  array:set a 0 "1"
  array:set a 1 "0,5,2"
  print a
end

I can then run the setup procedure, which will output the array

values in array represent connections between room

So I can see that my array is getting populated, i will be able to use the values in an index to draw the relevant rooms.

The completed array

extensions [array]

to setup
  let dungeon array:from-list n-values 16 [0] ; init array a with 16 values of 0
  ; use this line to copy and paste from 
  ; array:set dungeon n ""
  array:set dungeon 0 "1"
  array:set dungeon 1 "0,5,2"
  array:set dungeon 2 "1,3"
  array:set dungeon 3 "2"
  array:set dungeon 4 "8"
  array:set dungeon 5 "1,6"
  array:set dungeon 6 "5,10,7"
  array:set dungeon 7 "6,11"
  array:set dungeon 8 "4,9"
  array:set dungeon 9 "8"
  array:set dungeon 10 "6"
  array:set dungeon 11 "7,13"
  array:set dungeon 12 "13"
  array:set dungeon 13 "12,14"
  array:set dungeon 14 "13,15"
  array:set dungeon 15 "11,14"
  print dungeon
end

Confirmation output

this was helpful as i could spot the typo on 11.14

I spotted I had already made a typo on room 15, so I corrected that from 11.14 to 11,15 and my ‘dungeon’ map array was complete !

Leave a Reply

Your email address will not be published. Required fields are marked *