So I'm creating a new scenario similar to one of my other scenarios, Crash Course, and I'm running into a problem. When I test it, I move object Naruto into object Sasuke, and it a terminal error window pops up for some reason that I can't figure out. I neet help...
Class MyWorld:
Class Naruto:
Class Sasuke:
The Naruto class is the only one with code in the method punch for testing purposes.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author Edwin
* @version 1.0
*/
public class MyWorld extends World
{
private Naruto naruto;
private OtherNaruto otherNaruto;
private ShadowClone shadowClone;
private Sasuke sasuke;
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
prepare();
}
public void Naruto()
{
if (naruto.getWorld() == this)
{ naruto.subtractHealth();
}
}
public void Sasuke()
{
if (sasuke.getWorld() == this)
{sasuke.subtractHealth();
}
}
public void OtherNaruto()
{
if (otherNaruto.getWorld() == this)
{otherNaruto.subtractHealth();
}
}
public void ShadowClone()
{
if (shadowClone.getWorld() == this) {
shadowClone.subtractHealth();
}
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Naruto naruto = new Naruto();
addObject(naruto,94,110);
ShadowClone shadowclone = new ShadowClone();
addObject(shadowclone,457,110);
OtherNaruto othernaruto = new OtherNaruto();
addObject(othernaruto,306,270);
othernaruto.setLocation(85,272);
Sasuke sasuke = new Sasuke();
addObject(sasuke,454,285);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Naruto here.
*
* @author Edwin
* @version 1.0
*/
public class Naruto extends Actor
{
private int health = 100;
/**
* Act - do whatever the Naruto wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
run();
punch();
}
public void run()
{
if(Greenfoot.isKeyDown("w"))
{
move(4);
}
if(Greenfoot.isKeyDown("s"))
{
move(-4);
}
if(Greenfoot.isKeyDown("a"))
{
turn(4);
}
if(Greenfoot.isKeyDown("d"))
{
turn(-4);
}
}
public void punch()
{
MyWorld world = (MyWorld) getWorld();
Actor shadowClone;
shadowClone = getOneObjectAtOffset(0,0, ShadowClone.class);
if (shadowClone != null)
{
world.OtherNaruto();
world.Sasuke();
}
Actor otherNaruto;
otherNaruto = getOneObjectAtOffset(0,0, OtherNaruto.class);
if (otherNaruto != null)
{
world.ShadowClone();
world.Sasuke();
}
Actor sasuke;
sasuke = getOneObjectAtOffset(0,0, Sasuke.class);
if (sasuke != null)
{
world.OtherNaruto();
world.ShadowClone();
}
}
public void subtractHealth()
{
health = health - 25;
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Sasuke here.
*
* @author Edwin
* @version 1.0
*/
public class Sasuke extends Actor
{
private int health = 100;
/**
* Act - do whatever the Sasuke wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
run();
punch();
}
public void run()
{
if(Greenfoot.isKeyDown("5"))
{
move(4);
}
if(Greenfoot.isKeyDown("2"))
{
move(-4);
}
if(Greenfoot.isKeyDown("1"))
{
turn(4);
}
if(Greenfoot.isKeyDown("3"))
{
turn(-4);
}
}
public void punch()
{
}
public void subtractHealth()
{
health = health - 25;
}
}



