"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!
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();
program.play();
}
public CaposTagGame() {
World world = new World();
aRandom = new Random();
int x, y;
Picture backGround = new Picture("tagGameBackground.png");
world.setPicture(backGround);
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);
players[i].turnToFace(639,0);
}
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);
players[g].turnToFace(0,479);
}
world.repaint();
}
public void play() {
int moves = 0;
int currentPlayer=5, enemy=5;
while (true) {
players[currentPlayer].move(players[enemy]);
moves++;
}
}
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];
turtlesAlive--;
if(index < turtlesAlive){
players[index] = players[turtlesAlive];
players[turtlesAlive]=temp;
}
}
}
Re: "turtle game" 4 different classes - trouble moving the turltes -__-
Quote:
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.