Go Back   Java Programming Forums > Java Standard Edition Programming Help > Java Theory & Questions


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-04-2009, 09:21 AM
Junior Member
 

Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rojroj is on a distinguished road
Default Yo! Stuck making a simple game

Been lurking here for a while.

I've just been assigned to Java A, and this is actually one of our first "major" exercises... Problem is that I'm dead-stuck and I'm wondering if you could help me out?

I'm supposed to make a game that consists of a car moving on a road (the road consisting of whatever signs I want) so it looks like this ->

| o |
| |

"o" being the player. You're supposed to earn points for every "wall segment "(| |) you pass (easy part) and the walls are supposed to move in a random manner, keyboard control is optional (and WAY over my head).

The idea I had was to save the walls as separate strings consisting of a 5 blank spaces, a small L, and 5 more blanks -> "_____l_____", and making a big for loop with thread sleep to keep it pumping out one "wall" at a time, so print segment1, print player, print segment2, add +1 to score, repeat. The idea is to have a 50% chance to move (Math.random()?) with every loop, and then have the walls move either left or right one step. The idea I had was to accomplish this by removing one blank from one side and adding it to the other, to make the walls closer or further away from the player, and do the opposite on the other segment, so the walls move in unison without forcing the player to move, and then have some simple "if" thing that checks if the player is next to a "l", and then ending the program by printing out the score so far.

Gah wall of text.

I have no idea how to do this though - any tips or help on the way is mucho appreciated. . I've been looking around but don't know any way of changing the variables without making some huuuge chunky code.

Thanks in advance



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 01-04-2009, 09:27 AM
Freaky Chris's Avatar
Senile Half-Wit
 

Join Date: Mar 2009
Location: UK
Posts: 621
Thanks: 2
Thanked 64 Times in 60 Posts
Freaky Chris will become famous soon enoughFreaky Chris will become famous soon enoughFreaky Chris will become famous soon enough

I'm feeling Cheerful
Default Re: Yo! Stuck making a simple game

I'm still a bit confused sorry. Do you think you could post like a 10 line perfect match of how the output would look, this might help me get an idea of what we are looking at. Then I can suggest some ideas as to how to do it. I'm sure it's not as hard as it looks

Chris
Reply With Quote
  #3 (permalink)  
Old 01-04-2009, 08:17 PM
Junior Member
 

Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rojroj is on a distinguished road
Default Re: Yo! Stuck making a simple game

EDIT: It kills my spaces. There's supposed to be five blankspace between the " and the l, and then five more before the second ".

Re-reading what I said it does come of as being awfully confusing. Here's my idea in pseudo code:

For (however long I want the game to continue)

print " l ", print player ("o"), print " l "
If Math.random(); > 0.5
Check if math.random is over 0.75, if so then remove one blank space from before the l, and add on to the other side, if not then do the opposite (remove one). Thereby moving one of the walls closer to the player, randomized which one for each loop.
Check if there are no blank spaces to the right of the l in the first string, or left of the l in the second string (therby making it touch the "o"), if so then quit the loop.
Thread.sleep(some number)
print int that is = how many times the loop has been run


---------------------------
When run it should look something like this:

l o l
l o l
l o l
l o l
l o l
l o l
l o l
l o l
lo l

You cleared 9 obstacles!

Last edited by rojroj; 01-04-2009 at 08:23 PM.
Reply With Quote
  #4 (permalink)  
Old 02-04-2009, 03:24 PM
JavaPF's Avatar
mmm.. coffee
 
8 Highscores

Join Date: May 2008
Location: United Kingdom
Posts: 1,543
Thanks: 98
Thanked 92 Times in 85 Posts
JavaPF is someone you want to know!JavaPF is someone you want to know!JavaPF is someone you want to know!

I'm feeling Relaxed
Default Re: Yo! Stuck making a simple game

Hey rojroj,

I don't think this is anywhere near as complicated as you require but here is an example I wrote:

Java Code
import java.math.*;
import java.text.*;

public class Rojroj {

    public static String space1 = " ";
    public static String space2 = " ";
    public static String noSpace = "";
    
    public static String leftWall = "|";
    public static String rightWall = "|";
    
    public static String player = "o";
    
    public static int finalScore = 0;
    public static double randomDouble;

        
    public static void randomise(){
    
        DecimalFormat df = new DecimalFormat("#.##");
        double rd = Math.random();
        randomDouble = Double.parseDouble(df.format(rd));
        //System.out.println(randomDouble);
        
        if(randomDouble >= 0.75){
            move();
        }
        else{
            noMove();
        }
        
    }
    
    public static void move(){
        finalScore++;
        System.out.println(leftWall + space1 + player + space2 + rightWall);
        randomise();
    }
    
    public static void noMove(){
        
        System.out.println(leftWall + player + space2 + rightWall);
        System.out.println(" ");
        System.out.println("Game Over! - You cleared " + finalScore + " obsticle(s)");
    }
    
    
    public static void main(String[] args){
        
        System.out.println(leftWall + space1 + player + space2 + rightWall);
        randomise();
        
    }
    
}
Example output:

Java Code
| o |
| o |
| o |
| o |
|o |
 
Game Over! - You cleared 3 obsticle(s)
__________________
Don't forget to add syntax highlighted code tags around your code: [highlight=Java] code here [/highlight]

Forum Tip: Add to peoples reputation () by clicking the button on their useful posts.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Making a game for Mobile Phone Koâk Mobile Applications 15 30-07-2009 06:52 AM
[ASK]making a map donjuan AWT / Java Swing 3 15-05-2009 08:32 AM
stuck on this program can any one help me clive AWT / Java Swing 2 10-03-2009 09:54 PM
Looking for a programmer to make a simple program. GrosslyMisinformed Paid Java Projects 3 27-01-2009 07:33 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:57 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.