Turn Rules into Code

The rules of the game seem simple enough. A drag is valid if it’s within a row or a column, and if the two squares are the same color, and if there are no other squares between them. The drag can end on the second square, or it can continue onto empty squares beyond the second square. In this section you write the method, move(square1, square2), that makes these rules part of the game.

Make a Flowchart

To help you get from the rules to code, create a flowchart. A flowchart is a diagram that represents a set of rules in an organized way. Just making a flowchart like this can help you clarify what you really mean when you state the rules of a game. In a flowchart, conditionals are represented with diamonds, and calculations ...

Get Learn Game Programming with Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.