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.
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:
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.
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.
The SG_Board package is downloadable as a single .zip file, clickable from here JavaBoardGame.zip (354 KBytes).
The directory file structure of the unzipped file is as follows:
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.
If you are simply going to use the Java command-line tools then you can run the sample application as follows:
To compile the code at the CLI (command line interface):
The two files EnhancedBoard.java and MovingTilesApp.java provide the proto-typical example of how you should begin to use the SG_Board classes. i.e. Rather than modifying the file SG_Board.java directly, you should add your event-handling code and other game-specific code to EnhancedBoard.java - which inherits the basic functionality from SG_Board. Your main application file will be very much like MovingTilesApp.java - for example, if you decided to write a 2D chess game, instead of MovingTilesApp.java, your main file might be called Chess2D.java, say. Given that a chessboard is made of a 16x16 grid, within the file Chess2D.java 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 MovingTilesApp.java
Don't modify the files: SG_Board.java, Tile.java, Position.java and CommonInfo.java, 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 EnchancedBoard.java 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.
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.