Search:

Type: Posts; User: Norm

Page 1 of 2 1 2

Search: Search took 0.11 seconds.

  1. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    That does not make any sense.
    Change the code to print out the message when a car has completed a lap.

    BTW How much of the code you posted for this program did you write? You don't seem to...
  2. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Where are the messages for the other two cars?

    When does your code print out the "completed" message?
  3. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    It looks like it could work. What happens when you compile and execute the program?
  4. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Yes, that is how I would do it.


    No, do the increment outside of the println in its own statement.

    A sample of printing:
    int laps = 3; // for testing only
    System.out.println("Car laps=" +...
  5. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Your last post looks just like the broken code you posted earlier.
    Lets start with a simple problem and change it as you go along.

    Take the code that has the three cars running the race. Change...
  6. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    What test do you make with the if statement to determine if the counter should be incremented?


    Where is this counter's value incremented?
  7. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Yes you will use a counter.
    Will there be a counter for each car?
    Where will you increment the counter?


    How will you know that all the cards are stopped?

    You need lots more details on how...
  8. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Ok, how are you going to keep track of each car's number of laps?
    And how are you going to know when all three cars have finished their three laps?
  9. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    What do you want to do as they each restart the next lap?
    Should there be a counter for each car?
    Should the race stop when ONE car has completed the number of laps?
  10. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    I suggest that you remove the code that is now using the count variable and get the three cars to move.
    Then think about what you want to do when they each restart the next lap.
  11. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Why do you only start the thread when the count is > 3?
    Where is the value of count changed relative to the calls to the run method?
    Is run() called more than once?
  12. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Does your code do that? What are the steps you need to do to do that?
    Here is your code, slightly modified:


    if(count <= 3) {
    t1 = new Timer((int)s1, new ActionListener() {...
  13. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    I've just looked more closely at your code.
    I have no idea what the code is trying to do. There are no comments describing what you want it to do.
    For example, what are these statements supposed to...
  14. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    If you can make it go for 2 laps, it should be easy to continue going for the third lap.
    What happens after it goes for the first two laps?
  15. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Go to the API doc for javax.swing.Timer.
    There are links there to the tutorial which has examples of how to use the Timer class.
  16. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    You need to concentrate on the animation part only. The rest of your code would be in the way.
    Start with using a Swing Timer to change the x,y positions of the images and then call repaint() to...
  17. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Search on this forum or google for example codes
  18. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    I think it might be useful for you in learning how to animate your program to look at one of the many bouncing ball programs that exist. Search on this forum or google for example codes that will...
  19. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    How are you changing the x,y positions of the cars as they move?
    How are you defining the x,y positions of the curves
  20. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    You'll some things for the cars to move.
    The first would be a timer that will change their x,y position every small unit of time.
    The second would be a definition of where the track is. This will...
  21. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Your program must have the path to where the image files are located on your computer.
    You can use relative paths such as: images/<theImage>

    Either move the images or change the name of the...
  22. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    Your code has: " images/Track.gif"

    the image file location: C:\Users\Daniel\Pictures>

    These are not the same!!! They must be the same.
  23. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    In the command prompt window use the cd command to change directories.
    Here is a sample of its usage:



    D:\JavaDevelopment\Testing>cd ..

    D:\JavaDevelopment>cd Testing
    ...
  24. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    That's part one. Where is this part?

    Open a command prompt window, change to the folder with the images and enter the command: dir
    Copy and paste the contents here:
    To copy the contents of the...
  25. Thread: Car racing

    by Norm
    Replies
    105
    Views
    9,990

    Re: Car racing

    To show me, Copy the few lines of code from your program that load the images and that show the file names and paste them here
    Open a command prompt window, change to the folder with the images and...
Results 1 to 25 of 46
Page 1 of 2 1 2