Untitled Document 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: The central panel represents a board with a declared number of rows and columns - 10 by 8 in this demonstration case. The image with a frilled-neck lizard in front of Uluru (formerly Ayers Rock in central Australia), is an example of placing a background graphic behind the board, as its primary art-work. There are five tiles placed on the board at this point in time, three are rectangular and are opaque, while two are partially transparent, demonstrating how game pieces can be regular or non-regular shapes. The last tile selected by the user (typically, with the mouse), is the current tile. The Left, Right, Up and Down buttons demonstrate movement of a tile in a given direction, one place at a time. The GoTo move, takes the current tile, to some other position on the board, identified by board coordinates starting at [1,1] in the top right hand corner rectangle in the grid (or removed from the board via a board coordinate of [0,0]). The Swap move exchanges the current tile, with the previous tile (the tile that was most recently the current tile, before the current one). E.g. Puzzle games which swap the last two tiles clicked, are an example of the use of this method. The Shuffle move randomly shuffles the positions of all the tiles currently on the board. The game programmer can declare areas of the board which are off-limits to play. In the demonstration code the 3 squares that have the Uluru rock beneath them, have been marked 'off-limits', meaning that no tile can be placed on any of those 3 positions - i.e. functions such as Left, Right, GoTo will refuse to do so, if the destination position is off-limits. 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, clickable from here JavaBoardGame.zip (354 KBytes). 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: Go to the sub-directory called classes. i.e. At the command line, from the SG_Board root directory, enter the command: cd classes To run the precompiled application do one of the following two things: run java -cp . MovingTilesApp Note 1: The run option simply uses the run.bat batch file (which encompasses/automates the second option). Note 2: The 2nd option tells the java interpreter, that the classpath begins at the current directory (via the -cp . ie. the 'fullstop' means, the current dir) Note 3: The minimal sample application doesn't close its window well. You may need to do a Ctrl-C at the command line, after closing the program's window. Compiling the sample application To compile the code at the CLI (command line interface): Change directory to the src sub-directory. i.e. If currently at the dir classes from the earlier instructions, enter: cd ..\src Enter the dir command which will display the presence of the file MovingTilesApp.java See if your PC has the java compiler on the default PATH by entering command: javac If the system doesn't find it, you'll need to precede the command with the location of your Java JDK bin directory. e.g. C:\j2sdk1.4.2\bin\javac or something similar. Now compile all the source files as follows: javac -verbose -d ../classes MovingTilesApp.java or C:\j2sdk1.4.2\bin\javac -verbose -d ../classes MovingTilesApp.java Now go and do the Run step as before (outlined above). i.e. Enter: cd ..\classes then run Modifying the code for your own game 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. 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.