Drawing the Board
The game code is organized into three classes. The Twelve class is a subclass of Gosu::Window and has the Gosu run loop methods: initialize, update, and draw. It also has the user-interaction methods button_down and button_up. Roughly speaking, the Twelve class is responsible for creating and maintaining the window on the screen and handling user input.
You create a separate class, Game, to handle the game logic. There is only one instance of the Game class at a time, and it has methods that take user input in the form of mouse down and mouse up locations, figures out whether those represent legal moves in the game, and then resolves those moves.
A third class, Square, contains the state of a single square and also draws that ...
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.