O'Reilly logo

Learn Game Programming with Ruby by Mark Sobkowicz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required