Programming modules

Now that we know what each module is going to do it is time to start programming it. Consider the store board module -

Store board - Will be stroring the board and where the snakes and ladders will be. It should initialise itself to ensure the board is empty

We will store the board as an array. The board will be 100 squares and model a snake or ladder as a either a positive number or a negative number. So -3 would be a snake of size 3. 6 would be a ladder of size 6. Intially the board will be empty (all 0) so the code for store board will be -

- VOID StoreBoard()
- FOR A = 0 to 99
- BOARD[A] = 0
- NEXT
- END

BOARD[] is the array and will be a global variable. So far so easy!

No start - makes sure that the square has no snake/ladder on it.

This one is more difficult. We need to decide what information will go into it and what will go out of it.

The square number will be the square we are testing. The true/false will be wether or not there is a ladder/snake on that square. Notice that I do not care how that square was decided because at this stage it is not important. All i am concerned about is how to do the No Start module.

- boolean checkStart(int squareNum)
- if BOARD[squareNum] = 0 THEN RETURN TRUE
- ELSE RETURN FALSE
- END

I renamed this so it makes a bit more sense. If the start is empty then we return true, else false. We can do the same of the end.

- boolean checkEnd(int squareNum, int size)
- if BOARD [squareNum + size] = 0 THEN RETURN TRUE
- ELSE RETURN FALSE
- END

In this case we need to know the size of the snake/ladder so we can check the end.

Note - This code DOES NOT check to see if a snake/ladder goes off the edge of the board. This should be added. I left it out to keep the code simple