Writing Ludo

post_id: 23 / post_date: 2009-05-27



[tab: Ludo]

Tonight I set about trying to write Ludo. Full source code can be had here.

These parts described below can be seen here (or overleaf). It has things like Board, Coin, AdvanceCoin, BlockBuilder and it stores move history. See screenshots.

BlockType (enum): Normal / Home / Red / Green / Yellow / Blue

Block (structure): X / Y / Type / Color

Coin (class): Type / Color / Index / Block - where index is the position in an array of block the coin can be placed in from start to home. and Block is the current place it occupies.

Board (class): Holds array of blocks to be drawn on screen, array of paths a coin can take (depends on type). These are stored in local variables calculated in the constructor. It uses an inner class BlockBuilder to generate this list.

Board has the methods CreateCoin and AdvanceCoin. Create automatically places the coin at the start position. Advance returns false if the die value would cause the coin to move past home (> HomeIndex).

The windows Form where this is places hooks the paint method to draw blocks and coins. to invalidate (repaint). Form.Refresh() is called.

The Play button simply checks if the coin is home. If not, it tries to advance it. If that fails, it reports a message. Else it redraws the form to show the advanced coin.

[tab: Form]

[iframe src="http://cselian.com/d/code/serve.php?file=./ludo/LudoScreen.vb"]

[tab: Board]

[iframe src="http://cselian.com/d/code/serve.php?file=./ludo/Board.vb"]

[tab: Round]

[iframe src="http://cselian.com/d/code/serve.php?file=./ludo/Round.vb"]

[tab: Screen]