Game Development Reference
In-Depth Information
We check that via a specialSquare function, which takes a parameter of square and returns the
corresponding square for a snake's tail or the top of the ladder; otherwise, it simply returns the same
square. This way we can simply set the value without a lot of code.
function specialSquare(theSquare)
local theSquare=theSquare
local i
for i=1,#tableSquares do
local currSquare=tableSquares[i]
if currSquare.startPos == theSquare then
-- We have reached a special square
return currSquare.endPos
end
end
-- There was no special square, so simply return the same square value back
return theSquare
end
With these functions, we have covered the major logical bulk of the game. The rest of the functions
are mostly cosmetic and deal with UI interactions and updating the display.
We also need an init function that sets or resets the game defaults before we start:
function init()
-- Blank out the players table
players={}
playersInGame=0
end
First, to test, we shall try the game with two players. The easiest way to do so is as follows:
function reset()
init()
addPlayer("Jayant")
addPlayer ("Douglas")
end
We have almost everything in place for it to conceptually work, but we need to stitch it all together
to make it work. When we start the game, what we need is a function that shall roll the die, move the
player to a new square, change to the next player, and repeat, till there is one player left. Therefore,
the game cannot start unless there are at least two players.
Because we are going to run this game in the Lua terminal rather than with a graphical framework,
we shall not be able to avail ourselves of the various graphical and touch functionalities. This shall
limit the interactivity of our sample for now. Though many games give the players a great deal of
interactivity, this particular game doesn't need that much. In this game, the die is simply thrown
(a random number is generated) and the player token is moved (by the program), so the only
interactivity we would need is to have the players tap the screen at every stage to proceed to the
next, and tap to roll dice. While we are in text mode, we are not able to get any touch events, hence
the game might look more like a self-running simulation, which announces to the terminal whose
turn it is and then what they rolled and where the player is currently, till one player is left.
Search WWH ::




Custom Search