Snakes and ladders
|Top Previous Next|
This month's Plug and Play project implements one of your suggestions: a Snakes and Ladders game. It's a board game in which you have to reach the finish line; you move forward using a dice and you are helped or hindered by the ladders and snakes.
I am using a network of nodes (invisible entities) placed on each game square. I have set skill1 to the the number of the node (1... 60) and skill2 to a special value. As an example, skill2 = 3 will move the player 3 squares forward, skill2 = -5 will move the player 5 squares backward, etc. A skill2 = 999 value will roll the dice again and skill2 = 0 means that the square doesn't do anything special.
Why did I use nodes? I could have used an array to store the x and y coordinates of the squares for this rectangular board, but the nodes will offer you a much greater flexibility, allowing you to create irregular shaped boards as well.
Click the "click to roll" button to roll the dice; the player model will move to the proper destination, making use of all the special squares it encounters along its way: roll again, move back, snakes, ladders, etc.
Fortunately, the finish is quite close, so you should reach it within minutes even if you aren't spending your time in a casino all day long. A fabulous "congratulations" message awaits you at the end.
Since player's only job is to roll the dice by clicking the red button (that's all he does in this game, really) you can easily duplicate its code for as many players as needed, in case that you are interested in creating a multiplayer and / or AI based version of this game.
Don't forget that the code is nicely commented, as always.