Home Lawrence's Labyrinth Deconstructing B/X D&D Adventure Generator! B/X D&D Character Generator Other Contact
 

First PagePrevious PageBack to overviewNext PageLast Page

Getting Started

If you want to follow along and play with the code as we go, you'll need to set up a few things and possibly review some other things before we start.

This may all seem a little overwhelming at first, but don't get frustrated! Getting your development environment set up is a huge pain in the butt, but things get better once it is finally up and running!

Java

We'll be developing this game in Java. Java isn't a perfect language by any means (though none of them are!), but it runs on many, many different platforms without requiring much porting work. Since we're just kind of diving in and aren't sure where any of this is going, this is advantageous, since Java will run on…

  • Desktop Computers, running many many different operating systems.
  • Android Mobile Phones and Tablets
  • iOS Devices (via XMLVM or Oracle's yet-to-be-released iOS-compliant JVM)
  • Web Applications (via J2EE servlets, which can be had cheaply/free via Google AppEngine)

I'll be developing using the open-source OpenJDK 1.6 (aka JavaSE-6). You can get Linux packages from your distribution's package repositories, or from http://openjdk.java.net/.

If you're not using Unix, you can get Oracle's JDK6, which is essentially the same thing except closed-source, for many different platforms, at http://www.oracle.com/technetwork/java/javase/downloads/index.html.

Why are we using Java 6? Why aren't we using Java 7? Personally, I'd really like to use Java 7! Then we wouldn't have to use so many Apache Commons libraries to achieve true portability. But Java 7 isn't as widely supported yet. In particular, I am pretty sure that Android and AppEngine only go as high as Java 6 (though that may have changed after the time of this writing).

Eclipse

Eclipse is an “IDE” (aka Integrated Development Environment), a toolbox/environment to help you write code and manage your projects. It was originally geared towards Java, but it supports a number of languages, and has a pretty decent selection of plugins for about everything you can imagine.

Eclipse is rather Large and In Charge, but since it supports so many different languages through plugins, you can use it for pretty much any project in any reasonably popular programming language (except for the C# language; Eclipse's C# plugins are all pretty poor). This is especially useful when you have a large/complex project that uses modules written in many different languages. Switching between environments to edit bits of code in different languages is a huge pain!!

You don't have to use Eclipse. You can use something simpler with a smaller resource footprint, like NetBeans or any old text editor and the commandline if you want to, but Eclipse is what I'll be using, so it may be a little easier to follow along if you are using it, too.

You can get Eclipse at http://www.eclipse.org/downloads/. You want the “Eclipse IDE for Java Developers”.

(Optional) A Cat

Cats are cool. You should get one even if you're not writing a silly computer RPG! The best thing about a cat is, they will provide companionship and snuggles even after your boy/girlfriend dumps you because you are spending too many late nights hacking on silly RPGs!

A Little Bit of Programming Knowledge

You'll need to know some programming basics. You don't need to know much, but you'll need to have a basic working knowledge of functions/methods, variables, loops, and control structures.

You to not need to know much of anything about Object Oriented Programming. We'll be learning about that as we go.

These concepts are not hard to pick up. If you are new to Java, Eclipse, or programming in general, you might want to work through the video tutorials at:
http://eclipsetutorial.sourceforge.net/totalbeginner.html.

Don't get too frustrated if you don't grok it all the first time through. Understanding comes with experience, which we'll be getting as we implement this game!

If you're still feeling in the dark, google around for “Java Tutorials”. Many of them talk about compiling and running your code from the commandline (ick!), but armed with the knowledge of Eclipse from the above tutorials, you should be able to try things out in Eclipse instead with no trouble!

Come back here when you have an inkling of how variables/fields (they're the same thing!) work, how “if” and “case” statements work, and how looping constructs and functions/methods (they're the same thing!) work. It might be useful to know about objects and enumerations, too, but we'll touch on those here, too.

Don't worry if you don't completely grok polymorphism and inheritance. We'll go over that here, with concrete examples of how these concepts are useful in the context of building an RPG.

(Semi-Optional) Subversion Client Program

As we implement this game, I'll be keeping all of the source code in a Version Control Repository called Subversion. If you're curious as to what version control is all about, read this and then do some head-scratching.

The TL;DR here is that, if you use subversion, then you can keep your copy of the source code files in sync with mine fairly easily. You can always download the files by hand and copy them into your workspace, but that is a huge pain!

If you are going to be using Eclipse, there is a decent plugin called Subclipse that makes the whole process relatively painless. It is, however, a bit of a pain to get installed. Read the installation document carefully!

Here is a Subclipse installation tutorial: TUTORIAL: Installing Subclipse

More information on Subclipse can be found at http://subclipse.tigris.org/.

Once we've written a little code, I'll point you at a tutorial showing how to connect Subclipse to our source code repository and get all the files downloaded into Eclipse. The process is probably fairly similar for Subversive.

(NON-optional) GET PUMPED!

We're going to have an awesome time and do loads of groovy things!!! So Get Pumped and let's hack on some RPG!!!

(I don't have a tutorial available for Getting Pumped, but there is a young man named Robert Hamburger who is probably the world's foremost expert on the subject. His words of wisdom can be found at:
http://www.realultimatepower.net/)

Skeleton Source Code

The source code for this chapter can be found in the Subversion Repository. This would be a good time to check out a couple of projects into your workspace: TUTORIAL: Using Subclipse.

You'll first need to check out the “SimpleIO” project, then “002 - Getting Started”.

Abstract Startup and IO Libraries

The SimpleIO project that you just checked out contains some code to perform some startup initialization, and to provide generic ways to print to the screen and read from the keyboard for both locally running applications (what you'll be running as you play with the code) and Java Applets embedded in web pages (what you'll see at the beginning of each chapter of this book).

You don't need to worry about how the SimpleIO code works, or mess with it, if you don't want to. Just keep it up to date (as detailed in the Using Subclipse tutorial.

Your First Code!

Ok! Let's write a little Test App to demonstrate how we'll be using the SimpleIO library! It's not too complicated! It looks a little big because of all of the comments, but it's really not! Read over it and grok it! :3

/* 
 * Copyright (C) 2012 L. Adamson 
 *  
 * This software is provided 'as-is', without any express or implied warranty. 
 * In no event will the authors be held liable for any damages arising from the 
 * use of this software. 
 *  
 * Permission is granted to anyone to use this software for any purpose, 
 * including commercial applications, and to alter it and redistribute it 
 * freely, subject to the following restrictions: 
 *  
 * 1. The origin of this software must not be misrepresented; you must not claim 
 * that you wrote the original software. If you use this software in a product, 
 * an acknowledgment in the product documentation would be appreciated but is 
 * not required. 
 *  
 * 2. Altered source versions must be plainly marked as such, and must not be 
 * misrepresented as being the original software. 
 *  
 * 3. This notice may not be removed or altered from any source distribution. 
 *  
 * L. Adamson leaf@dizzydragon.net 
 */ 
 
// This "package" line must match the source directory that this file is in. 
package test; 
 
// These "imports" tell our code what other code we are going to use with it. 
import net.dizzydragon.retrocrawl.simpleio.SimpleIO; 
import net.dizzydragon.retrocrawl.simpleio.SimpleRunnable; 
 
// The class we create /must/ extend "SimpleRunnable" if we want to use the 
// automatic startup and applet code found in the SimpleRunnable class.  Think 
// of this as taking the SimpleRunnable class and "adding to it". 
public class Test extends SimpleRunnable 
{ 
	// "serialVersionUID" is only defined here to remove compiler warnings. 
	// at this stage of the game, you don't need to worry about what this 
	// field is for.  The code will work fine without it, but the compiler will 
	// throw a warning. 
	private static final long	serialVersionUID	= 1L; 
 
	// This static "main" method is the first thing that Java runs when you 
	// "Run as a Java Application".  We call it the "entry point". 
	// You don't need to worry about this stuff right now, just make sure that 
	// it is here. 
	public static void main( String[] args ) 
	{ 
		// "runLocal" is a magical method that sets up all of the GUI stuff 
		// and makes a call to this class' run() method, to execute your code. 
		// If you rename this class, make sure that you change this line to 
		// reflect it, ie "runLocal( new RenamedClassName() );". 
		runLocal( new Test() ); 
	} 
 
	// This method is where we start writing our code!  It gets called by the 
	// SimpleIO system once the GUI windows are set up, or the Applet is 
	// running. 
	@Override 
	public void run( SimpleIO io ) 
	{ 
		// We'll just print some text to the screen for now.  We'll write 
		// more interesting code later! 
		io.println( "Hello, Adventurer!" ); 
	} 
}

If you right click on your Test.java file and select Run As→Java Application, you should see something like this!

What's Next?

In the next chapter, we'll start actually building some game code! Woohoo!!!

Source Code

The source code for this chapter can be found in the Subversion Repository.

If you are interested in changing/modifying the code, you can download it into your Eclipse workspace using Subclipse as detailed here: TUTORIAL: Using Subclipse.

First PagePrevious PageBack to overviewNext PageLast Page

rustybox/book/002_getting_started.txt · Last modified: 2012/09/09 00:30 by leaf

Copyright © 2009, 2012-2014 by L. Adamson, unless otherwise stated.
If you see something here that you like, and find it useful or learn something, please consider making a quick, easy, and secure donation via PayPal.
Your support is what keeps this whole thing going!