5,661,954 members and growing! (16,023 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Game Development » Games     Beginner License: The Code Project Open License (CPOL)

Star Trek "Galactic Conquest" Game Contest Submission (Java)

By Robert Bettinelli

Star Trek "Galactic Conquest" Game Contest Submission (Java)
C++, C++/CLI, C, C#, Javascript, JScript .NET, Windows (Windows, NT4, Win2K, WinXP, Win2003, Vista, TabletPC), Dev, Design

Posted: 21 Jul 2008
Updated: 6 Aug 2008
Views: 6,809
Bookmarked: 13 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
7 votes for this Article.
Popularity: 3.19 Rating: 3.77 out of 5
1 vote, 14.3%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
4 votes, 57.1%
4
2 votes, 28.6%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

THE DOWNLOAD : Download StarTrekGCExeJar-rb2008.zip - 1.39 MB

THE SOURCE CODE : Download StarTrekGCSourceRB-2008.zip - 1.5 MB

Introduction

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.

Background

Check out info that was really cool at the time : http://www3.sympatico.ca/maury/games/space/star_trek.html

Using the Code

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).

Points of Interest

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.

Java Design

Here is Design Info :

ST-ClassFiles.jpg 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.

Game Routines Breakdown

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);
        }
    }  

New Concepts

The old System replaced with the new graphic and sound. There is alot 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 or alter the graphics to cover a wide range of games Such as Battlestar Galactica or others easily.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Robert Bettinelli


I have background in programming(many languages), web design, hardware and software. Currently I hold a designer and purchaser position in a large corporation. Although I wear as many hats as Im asked to. Programming in vb.net and java comes 2nd nature to me so I do this for fun. I also used to design in cobol and pascal and run a BBS(anyone remember what this was?). Anyways, drop me a line maybe I can help you.
Occupation: Other
Company: Valmont West Coast Engineering Group
Location: Canada Canada

Other popular Game Development articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 11 of 11 (Total in Forum: 11) (Refresh)FirstPrevNext
GeneralTilesmemberJason McBurney14:07 15 Aug '08  
GeneralRe: TilesmemberRobert Bettinelli11:17 16 Aug '08  
GeneralSource Codememberc24235:52 6 Aug '08  
GeneralRe: Source CodememberrTron17:32 6 Aug '08  
GeneralRe: Source Codememberc242311:25 6 Aug '08  
GeneralRe: Source CodememberrTron111:51 6 Aug '08  
GeneralRe: Source Codememberc242323:19 6 Aug '08  
GeneralRe: Source CodememberrTron117:48 7 Aug '08  
GeneralRe: Source Codememberc242323:40 7 Aug '08  
GeneralTried...memberTomas Brennan6:56 31 Jul '08  
GeneralRe: Tried...memberrTron120:02 31 Jul '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 6 Aug 2008
Editor: Sean Ewington
Copyright 2008 by Robert Bettinelli
Everything else Copyright © CodeProject, 1999-2008
Web07 | Advertise on the Code Project