Search This Blog

21 September 2017

Digital life

    Let’s code a little JavaScript project.
We have a world/ labyrinth / map and some creatures that roam in it. The world is described with walls and movable space. The creatures can use only the movable space to move and cannot move through the walls. The creatures have a field of vision of 1 square around them.

We will use some symbols to denote each one of the objects in our world:
    wall - *
    movable space - white space (space " ")
    creature - o

We will store the world in a two dimensional array. This way we can denote a location in the world with:
    world[x][y]

We could have used a one dimensional array. Then a location in the world would be:
    index = y * width + x
    world[index]



Here is the small repository of the project:

No comments:

Post a Comment