Results 1 to 2 of 2
  1. #1
    gcap's Avatar
    gcap is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default "turtle game" 4 different classes - trouble moving the turltes -__-

    For a class I have to make a program will generate a turtle "tag game" with 5 chaser and evader turtles, they only have 100 moves to make it to their safe zones. If a turtle gets "tagged" then that turtle will be done. Whichever team (chaser or evader) has the most amount of turtles in the safe zone wins.
    So we had to have four different classes, TagGame, ChaserTurtle, EvaderTurtle and GameTurtle
    ChaserTurtle and EvaderTurtle are extended from GameTurtle
    But in my TagGame class I'm having trouble with a method called play() that makes the turtles move. I have the world set up (the background and window) but the turtles don't move.. I'm trying to add in the move() methods from the EvaderTurtle and ChaserTurtle classes but I'm having a hard time doing that.. here's the code for the TagGame class: anything anyone can do to help will be much appreciated! Thank you!
    Java Code:
    import java.util.*;
    import java.awt.*;
    public class CaposTagGame {
      public CaposTagGame ctg;
      public static final int NGAMETURTLE = 10;
      public GameTurtle [] players = new GameTurtle[NGAMETURTLE];
      public int turtlesAlive = NGAMETURTLE;
      public Random aRandom;
      public int delayInterval = 200; 
      public boolean end = false;
      public int tagDistance = 10;      
      public int turtleBaseStep = 4;    
      public int turtleStepOffset = 6;  
      public float chaserPercentLook = 0.25f;   
      public float evaderPercentLook = 0.45f;
      final int lookDistance = 100;
      public static void main(String[ ]args) {
        CaposTagGame program = new CaposTagGame();;
      public CaposTagGame() {
        World world = new World(); 
        aRandom = new Random();
        int x, y;
        Picture backGround = new Picture("tagGameBackground.png");
        for(int i = 0; i < NGAMETURTLE/2; i++) {
          x = aRandom.nextInt(160);
          y = aRandom.nextInt(120) + 360;
          players[i]= new ChaserTurtle(x,y,world,i,backGround,new Color(255, 110, 0),new Point(639,0), true); 
        for(int g = 5; g < NGAMETURTLE; g++) {
          x = aRandom.nextInt(160) + 430;
          y = aRandom.nextInt(120);
          players[g] = new EvaderTurtle(x,y,world,g,backGround,new Color(0, 255, 255),new Point(0, 479),false);
      public void play() {
        int moves = 0;
        int currentPlayer=5, enemy=5;
        while (true) { 
      public void delay() {
        try { Thread.sleep(delayInterval); }
        catch (InterruptedException ie) { 
          System.out.println("Error in delay " + ie.toString());
      public void makeDead(int index) {
        //when turtle is dead, it gets moved to end of array
        GameTurtle temp = players[index];
        if(index < turtlesAlive){
          players[index] = players[turtlesAlive];

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: "turtle game" 4 different classes - trouble moving the turltes -__-

    but the turtles don't move.. I
    How do you show the turtles moving? Are they located at x,y positions and those positions never change?
    Have you tried debugging your code by adding printlns that print out the values of x and y every time a move is made? What prints out? Is the code that changes the x,y values not being called? Add more printlns to show why not.

Similar Threads

  1. Replies: 1
    Last Post: 01-23-2011, 01:12 AM
  2. trouble with Scanner(new File("input"));
    By ronyosi in forum New To Java
    Replies: 9
    Last Post: 10-27-2010, 11:34 PM
  3. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  4. need help with "turtle" problem
    By cbear315 in forum New To Java
    Replies: 4
    Last Post: 09-18-2009, 01:23 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts