![]() |
Platforms, Frameworks & Libraries »
Game Development »
Games
Beginner
License: The Code Project Open License (CPOL)
Star Trek "Galactic Conquest" Game Contest Submission (Java)By Robert BettinelliStar Trek "Galactic Conquest" Game Contest Submission (Java) |
C++, C++/CLI, C, C#, Javascript, JScript .NET, Windows (Win2K, WinXP, Win2003, Vista, TabletPC), Dev, Design
|
||||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
THE DOWNLOAD : Download StarTrekGCExeJar-rb2008.zip - 1.39 MB
THE SOURCE CODE : Download StarTrekGCSourceRB-2008.zip - 1.5 MB
This application I based 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 spend 3 days typing in the code into the Vic-Basic O/S only to have the computer crash on running it and loosing all my work. That was a tad upsetting. But I learned alot. So now, I base this application on those designs with my own thinking on how they may have achived what they did to assemble their game into a cool application. I do the same but add my own touch.
Check out info that was really cool at the time : http://www3.sympatico.ca/maury/games/space/star_trek.html
1) Obviously get the StarTrekGCExeJar-rb2008.zip file and unzip it there will be one file contained within it. StarTrekGalacticConquestExeJar-rb2008.jar
2) 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)
3) Double Click the Jar file .. Associate it with javaw.exe that was installed in step 2.
4) Try out game (it should run).
This game was built from the ground up as shown on the above revision listing. This was 1st designed using the Java Terminal, although it had some draw backs. 1st thing is that when feeding output to the terminal you cant determine if the class that is accessing it is 1st generation or another instance of that class (which means you could acidently have 300 of the same object sending info to the terminal), when crossing over to the GUI i did in fact find that this was occuring (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.
The Construction of the app was broken up into sections.
1) Galaxy Design (Quadrant & Sectors) Which is laid out in a two dimensional Array.
2) Commands (To Handle commands to the Game and a master valid command list)
3) 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)
4) Movement handling
5) Utilites such as Graphics, sounds and external files.
To start the game..
We Have the following Setup
INITIALIZATION (Which includes all Variables and Galaxy Randomization)
private void init() // This is the Whole Kit and Ka-boodle. { // ======================================== util = new Util(5); // Initialize the Utilities Class util.initWindow(); // Initialize GUI Window sound = new Sound(); // Initialize the Sound Class util.setScroll(true); // Set No Scrolling sound.setAudio(true); // Set No Audio initWelcome(); // Welcome Notice LRS = new boolean[quadSizeX+1][quadSizeY+1]; // Set LRS Size initLRS(); // Clear LRS quad = new Quadrant[quadSizeX+1][quadSizeY+1]; // Set Galaxy Size commands = new ArrayList(); // Initiate Command Space. initCommands(); // Initiate Menu Commands & Dmaage Control player = new Player("New Player","Galactica",28,40); // Create Player Instance (Name, Ship, Baddies, # of Turns) createGalaxy(); // Create Galaxy (Empty) player.setPlayerName(util.inStr("Please Enter your Name : ")); // Set Player Name player.setShipName(util.inStr("Ship Name : ")); // Set Ship Name difficulty(); // Difficulty Set populateStuffUnEven((player.getBaddie()*750)/1000,"X",0); // Enemy Fighter (UnEven Distribute Test) populateStuffUnEven((player.getBaddie()*250)/1000,"V",(util.rNumber(350)+150)); // Enemy Battleship(UnEven Distribute Test) populateStuffEven((2*(quadSizeX+1)*(quadSizeY+1)),"*"); // Stars (Even Distribute) populateStuffUnEven(bases,"@",0); // Bases (UnEven Distribute) populateStuffUnEven(planets,"P",0); // Planets (UnEven Distribute) populateStuffUnEven(wormHoles,"W",0); // WormHoles (UnEven Dist.) populateStuffUnEven(sun,"S",0); // Sun (UnEven Dist.) populateStuffUnEven(1,"Y",0); // Ship (UnEven Distribute) }
GAME LOOP Until Game End or Quit ( Draw The Screen, Get Command, Re-act to Command )
public void play() { // Initialize Galaxy And Post Welcome. init(); // Play Loop. boolean finished = false; while (! finished) { // display Play Screen drawScreen(); // Get & Process New Command. String commandEntry = util.inStr("Command >> "); // finished = processCommand(commandEntry); } // Game Quit/Done. util.toScr(OUTMAIN,"\nMCP reports Simulation Terminated - End of Line. \n"); //Play Exit Sound sound.playSound("EOL.wav"); util.inStr("Hit [EXECUTE]"); //End. System.exit(0); }
What a simple loop.
But there is so much more... In this new version I even take into concideration 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.. also removes damage on return fire if your ship is docked.. Lets take a look..
/** * Enemy Turn. Included, Flight or Fight and Damage Evaluation. */ private void goEnemy() { // Enemy in Quad. Then (75%-Shoot or 25%-Move) (1 or the other not Both.) String shipType; for (int x=0; x<=sectSizeX; x++) { for(int y=0; y<=sectSizeY; y++) { // If Enemy Exists in Quadrant shipType = quad[player.getPlayerQX()][player.getPlayerQY()].getSpace(x,y); if ((shipType.equals("X"))||(shipType.equals("V"))) { int shuckJive = util.rNumber(100); // Flight! 75 - 100 Fear takes over and they move somewhere in quad. if (shuckJive >= 75) { // If Flight Then Plot New Location for ship. quad[player.getPlayerQX()][player.getPlayerQY()].plotEnemy(x,y); } else { // Fight! 0 - 74 - Then Hit with something. if (!jumpFlag) { int returnFire = 75+util.rNumber(100); if (shipType.equals("V")) { // Bigger Ship Bigger Shot. returnFire = 75+util.rNumber(300); } sound.playSound("L2.wav"); util.shot(x,y,player.getPlayerSX(),player.getPlayerSY()); util.toScr(OUTAUX,"Enemy @ ["+x+"]"+",["+y+"] yeilds ["+returnFire+"] pulse!\n"); if (player.getStatus() == "DOCKED") { util.sysNotice( "Damage Diverted while Docked."); } else { if (player.getSheildStauts().equals("UP")) { // If Sheild is UP then Hit Sheilds and take them down if possible. player.hitSheild(returnFire); if (player.getSheild() < 0) { player.sheildDown(); } } else { // Randomize Hull Hit. int hullDamage = util.rNumber(25); player.hitHull(hullDamage); if (player.getHull() > 0) util.toScr(OUTAUX,"HULL HIT!-Down to ["+player.getHull()+"]%\n"); } systemsDamage(10); // If Hit Ship then Maybe Systems Damage } } } } } } // Execute all Enemy Jumps at Once. & Display util.toScr(OUTAUX,quad[player.getPlayerQX()][player.getPlayerQY()].jumpEnemy()); jumpFlag = false; }And a small Rez Routine to put everything on screen..
/** * reZ Quadrant Based on Contents. */ public void reZ() { // Pull Quad Info to local String String evalQuad = quadStuff; // Only process if there is something there. if (evalQuad.length() > 0) { //Set Up offScreen Setup and Local Images. Image currentImg = null; Image offScreenImage = null; Graphics offscreenGraphics; offScreenImage = createImage(width, height); offscreenGraphics = offScreenImage.getGraphics(); String spaceString = ""; int counter = 0; int planetNo = 0; // Cycle through Quadrant Sectors. for (int x =0; x<= sectX;x++) { for (int y = 0; y<= sectY;y++) { // Look at Single Character from Quad. 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; } // Paint Sector Contents to Offscreen Image offscreenGraphics.drawImage(currentImg,y * 48,x * 48,this); counter +=1; } } // Send Complete offscreen to Custom JPanel. quadDisplay.drawImage(offScreenImage); } }
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Aug 2008 Editor: Sean Ewington |
Copyright 2008 by Robert Bettinelli Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |