Introduction
I based this application mostly on my own memories of a game that I played in days long gone by. I used to connect to something called "Compu-serve" on my Commodore-Vic 20 using a 300 baud modem and played online Star-Trek. Neat simple game. Round two with this is when I got a Commodore 64 and spent 3 days typing in the code into the Vic-Basic O/S only to have the computer crash on running it and losing all my work. That was a tad upsetting. But I learned a lot. So now, I base this application on those designs with my own thinking on how they may have achieved what they did to assemble their game into a cool application. I do the same but add my own touch.
Background
Check out information that was really cool at the time.
Using the Code
- Obviously get the StarTrekGCExeJar-rb2008.zip file and unzip it. There will be one file contained within it - StarTrekGalacticConquestExeJar-rb2008.jar.
- Make sure you have the latest Java installed http://www.java.com/en/download/installed.jsp (if you can run the sample, you should be ok).
- Double Click the Jar file. Associate it with javaw.exe that was installed in step 2.
- Try out the game (it should run).
Points of Interest
This game was built from the ground up as shown on the above revision listing. This was first designed using the Java Terminal, although it had some drawbacks. The first thing is that when feeding output to the terminal, you can't determine if the class that is accessing it is first generation or another instance of that class (which means you could accidentally have 300 of the same object sending information to the terminal), when crossing over to the GUI I did in fact find that this was occurring (part of the learning curve I guess). Anyway, once the basic foundation was created, I switched to a GUI display that was a bunch of text windows. From that, I switched the main display to Full Graphics. Once the Full Graphics display was working, I added and expanded on the graphics to allow a more favourful game play experience.
Java Design
Here is the Design Info
The construction of the app was broken up into sections.
- Galaxy Design (Quadrant & Sectors) which is laid out in a two dimensional Array
- Commands (to handle commands to the game and a master valid command list)
- Player Stats such as Available Energy, Score, nukes, etc. All the stuff that would effect command ability. It was also built this way so that if I wish I can have multiple players in a galaxy later on (Multiplayer)
- Movement handling
- Utilities such as Graphics, sounds and external files
Game Routines Breakdown
To start the game...
We have the following setup:
INITIALIZATION (which includes all Variables and Galaxy Randomization):
private void init()
{
util = new Util(5);
util.initWindow();
sound = new Sound();
util.setScroll(true);
sound.setAudio(true);
initWelcome();
LRS = new boolean[quadSizeX+1][quadSizeY+1];
initLRS();
quad = new Quadrant[quadSizeX+1][quadSizeY+1];
commands = new ArrayList<command>();
initCommands();
player = new Player("New Player","Galactica",28,40);
createGalaxy();
player.setPlayerName(util.inStr("Please Enter your Name : "));
player.setShipName(util.inStr("Ship Name : "));
difficulty();
populateStuffUnEven((player.getBaddie()*750)/1000,"X",0);
populateStuffUnEven((player.getBaddie()*250)/1000,
"V",(util.rNumber(350)+150));
populateStuffEven((2*(quadSizeX+1)*(quadSizeY+1)),"*");
populateStuffUnEven(bases,"@",0);
populateStuffUnEven(planets,"P",0);
populateStuffUnEven(wormHoles,"W",0);
populateStuffUnEven(sun,"S",0);
populateStuffUnEven(1,"Y",0);
}
GAME LOOP Until Game End or Quit (Draw The Screen, Get Command, React to Command):
public void play()
{
init();
boolean finished = false;
while (! finished)
{
drawScreen();
String commandEntry = util.inStr("Command >> ");
finished = processCommand(commandEntry);
}
util.toScr(OUTMAIN,"\nMCP reports Simulation Terminated - End of Line. \n");
sound.playSound("EOL.wav");
util.inStr("Hit [EXECUTE]");
System.exit(0);
}
What a simple loop!
But there is so much more... In this new version, I even take into consideration that the enemy has options, either shoot, or move and each ship has a damage tolerance. If you hit it, it may not mean it dies.. it also removes damage on return fire if your ship is docked. Let's take a look.
private void goEnemy()
{
String shipType;
for (int x=0; x<=sectSizeX; x++)
{
for(int y=0; y<=sectSizeY; y++)
{
shipType = quad[player.getPlayerQX()][player.getPlayerQY()].getSpace(x,y);
if ((shipType.equals("X"))||(shipType.equals("V")))
{
int shuckJive = util.rNumber(100);
if (shuckJive >= 75)
{
quad[player.getPlayerQX()][player.getPlayerQY()].plotEnemy(x,y);
}
else
{
if (!jumpFlag)
{
int returnFire = 75+util.rNumber(100);
if (shipType.equals("V"))
{
returnFire = 75+util.rNumber(300);
}
sound.playSound("L2.wav");
util.shot(x,y,player.getPlayerSX(),player.getPlayerSY());
util.toScr(OUTAUX,"Enemy @ ["+x+"]"+",["+y+"]
yields ["+returnFire+"] pulse!\n");
if (player.getStatus() == "DOCKED")
{
util.sysNotice( "Damage Diverted while Docked.");
}
else
{
if (player.getSheildStauts().equals("UP"))
{
player.hitSheild(returnFire);
if (player.getSheild() < 0)
{
player.sheildDown();
}
}
else
{
int hullDamage = util.rNumber(25);
player.hitHull(hullDamage);
if (player.getHull() > 0) util.toScr(OUTAUX,
"HULL HIT!-Down to ["+player.getHull()+"]%\n");
}
systemsDamage(10);
}
}
}
}
}
}
util.toScr(OUTAUX,quad[player.getPlayerQX()][player.getPlayerQY()].jumpEnemy());
jumpFlag = false;
}
And a small Rez
Routine to put everything on screen.
public void reZ()
{
String evalQuad = quadStuff;
if (evalQuad.length() > 0)
{
Image currentImg = null;
Image offScreenImage = null;
Graphics offscreenGraphics;
offScreenImage = createImage(width, height);
offscreenGraphics = offScreenImage.getGraphics();
String spaceString = "";
int counter = 0;
int planetNo = 0;
for (int x =0; x<= sectX;x++)
{
for (int y = 0; y<= sectY;y++)
{
spaceString = evalQuad.substring(counter, counter+1);
switch (spaceString.charAt(0))
{
case 'Y':
currentImg = gameGraphic[0][0];
break;
case 'X':
currentImg = gameGraphic[1][0];
break;
case 'Z':
currentImg = gameGraphic[1][1];
break;
case 'V':
currentImg = gameGraphic[2][0];
break;
case 'C':
currentImg = gameGraphic[2][1];
break;
case 'W':
currentImg = gameGraphic[6][0];
break;
case 'S':
currentImg = gameGraphic[7][0];
break;
case '*':
currentImg = gameGraphic[3][0];
break;
case '.':
currentImg = gameGraphic[4][0];
break;
case '@':
currentImg = gameGraphic[5][0];
break;
default:
planetNo = Integer.valueOf(spaceString).intValue();
currentImg = planets[planetNo];
break;
}
offscreenGraphics.drawImage(currentImg,y * 48,x * 48,this);
counter +=1;
}
}
quadDisplay.drawImage(offScreenImage);
}
}
New Concepts
The old system has been replaced with the new graphic and sound. There is a lot to look at in the source code above but there are no limits with this design as it can be reworked to become multiplay and alter the graphics to cover a wide range of games such as Battlestar Galactica or others easily.