SG_Board - A General Purpose 2D Board Game Engine

Many games are based on moving tiles or game pieces around a two dimensional (2D) grid. Such games include traditional board-games including Checkers (aka Draughts), Chess, Snakes-and-Ladders, Ludo and many others. There are also newer games, often computer-based only, also based on 2D grids, such as BeJeweled and Alchemy. The SG_Board board-game class presented and made available here, provides the basic on-screen moves for manipulating tiles and game pieces around a 2D board. It provides a versatile set of classes and methods in Java, upon which you can program the rules of some existing board-game, such as Ludo (see Figure 2), Snakes-and-Ladders (see Figure3) and Checkers (see Figure 4), or some entirely new 2D game of your own invention.

SG_Board was originally written in C++ by the author in 1990, but was converted to Java more recently. It was initially used by Solid Software Pty Ltd on inhouse projects, but has now been released as an open source program under the GNU GPL license (General Public License), to make it widely available particularly to both students and teachers of Java and OOP (Object Oriented Programming) concepts, and to board-game and puzzle-game enthusiasts.

Figure 1. Sample use of generic SG_Board 2D game engine, called MovingTilesApp

The SG_Board 2D board-game engine or package in Java parlance, includes two main classes: the SG_Board class and the Tile class, together with several auxiliary classes. Figure 1 above represents a small demonstration application of SG_Board, supplied with the package, but which is not a complete game. It simply shows the basic functionality, or the atomic moves available in the class, using a minimal amount of code to do so - in order to get you up and coding with it, as soon as possible. Here is a description of what you see in Figure1, and how you interact with the example program, which is simply called MovingTilesApp:

Figure 2. Student example Ludo game using the SG_Board 2D game engine.

Some Recent Example Games based on SG_Board

Second year undergraduate students at the Department of Information Systems within the University of melbourne, recently used the SG_Board package within an introductory subject to the Java language. They were given three choices of game to develop, as the main assignment of the subject, all of which could be based on an underlying grid pattern, and hence capable of implementation using the SG_Board class. They were: Ludo, Snakes-and-Ladders and Draughts (also known as Checkers). They were given the set of playing rules for each game, to side-step the variation in rules that exist for several of these traditional games.

Figure 3. Student example Snakes-and-Ladders game using the SG_Board 2D game engine.

Each student team consisted of three team-members. There were over 80 teams. Over 90 percent of the teams submitted a working game, many of them of commercial quality - at least partially attributed to the high productivity of using the SG-Board class to develop 2D-based board-games, even for novices of the Java language.

Figure 4. Student example Draughts/Checkers game using the SG_Board 2D game engine.

Downloading, Running and Compiling SG_Board

The SG_Board package is downloadable as a single .zip file.

The directory file structure of the unzipped file is as follows:

Figure 5. Code/File tree in the .zip download.

If you use Borland's JBuilder then there is a project file for running and compiling the project, in the sub-directory: SG_Board\MovingTilesApp

Note: The following instructions on running and compiling the code from the command-line, assume an MS Windows installation of Java. The necessary commands on other platforms such as Mac OSX and Linux, will be similar, usually easier (e.g. OS X comes with Java pre-installed). I've tested the code on: Windows NT, Windows 2000, Windows XP, Mac OS X, and SUSE Linux - and have encountered no problems.

Running the sample application

If you are simply going to use the Java command-line tools then you can run the sample application as follows:

Compiling the sample application

To compile the code at the CLI (command line interface):


Modifying the code for your own game

The two files and provide the proto-typical example of how you should begin to use the SG_Board classes. i.e. Rather than modifying the file directly, you should add your event-handling code and other game-specific code to - which inherits the basic functionality from SG_Board. Your main application file will be very much like - for example, if you decided to write a 2D chess game, instead of, your main file might be called, say. Given that a chessboard is made of a 16x16 grid, within the file file, you would have a line of code something like this:

MyEnhancedBoard myBoard = new MyEnhancedBoard("chessboard.jpg",0,0,16,16,60,60);

instead of the line at line-no 78 in

Don't modify the files:,, and, until absolutely necessary, which should be on your second or third game, not on your first. I.e. Stick with the good advice above, to keep your modifications to and other new source files which extend what is in SG_Board. Remember, there is no support offered with the download.

... That's it - so go forth and produce the next classic Board Game.

Motivation still a problem?

Does 2D seem a little low-tech for you with all those 3D blockbusters on the shelves? Remember, while board games have a long tradition going back into ancient times in some instances, new board games are invented regularly - often with technology no more sophisticated than cardboard. E.g. When the game Trivial Pursuit (which earned hundreds of millions of dollars for its creators) was invented and delivered using cardboard and paper, 3D computer games were already in existence. While SG_Board is certainly not a 3D game engine, as a 2D game engine, it gives you far more technological assistance with your invention than does cardboard!

Enjoy, Steve Goschnick, 2005 (author and copyright holder of SG_Board)

This web-page: Copyright 2005 (c), Steve Goschnick, Australia. Worldwide rights reserved.