writing ludo

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.

Form

Board

Round

Screen


Warning: count(): Parameter must be an array or an object that implements Countable in /home/cselian/public_html/blog/wp-includes/class-wp-comment-query.php on line 405

Leave a Comment