here full Alien.class Code
here Blizzard.class Code
the question is how to call Died method to AttackAlien Method in Blizzard Class?
public class Alien extends Enemy
{ private int Health=3;
int Speed = 20;
/**
* Act - do whatever the Fish wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{move();
if(BlizzardCheck())
{Health--;}
}
/**
* Momovement
*/
public void move()
{setLocation(getX()+Speed, getY());
if (isTouching(WallWest.class))
{Speed = -Speed;
}else
if (isTouching(WallEast.class))
{ Speed= -Speed;
}
}
/**
* BlizzardAttack
*/
public boolean BlizzardCheck()
{
Actor blizzard = getOneObjectAtOffset(0, 0, Blizzard.class );
return(blizzard!=null);
}
/**
* Monster Died
*/
public void Died()
{if (Health<=0)
{getWorld().removeObject(this);
}
}
}
import greenfoot.*;
/**
* Write a description of class Player here.
*
* Muhamad Ariq Rasyid
* 1.0, 30 Feb 3021
*/
public class Blizzard extends Actor
{ private int Level=1;
public int Health=25;
public int Exp=0;
GreenfootSound LvUp= new GreenfootSound("level_up (online-audio-converter.com).mp3");
public Blizzard(int Level)
{
this.Level = Level;
Health = 25+5*(Level-1);
}
public Blizzard()
{if (Exp >= 100 && Level == 1)
{Level = 2;
LvUp.play();}
if (Exp >= 2300 && Level == 2)
{ Level = 3;
LvUp.play();
}
if (Exp >= 400 && Level == 3)
{ Level = 4;
LvUp.play();
}
}
/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
KeyboardCheck();
Howling();
GameOver();
showstatistic();
}
public void showstatistic()
{if (getWorld() instanceof Dugeons)
{getWorld().showText("Health :" +Health, 50, 30);
getWorld().showText("EXP :" +Exp ,130, 30);
getWorld().showText("LV :" +Level, 180, 30);
}
}
public void GameOver()
{if (Health<=0)
{Greenfoot.setWorld(new Gameover());
}
}
public void Howling()
{if (getWorld() instanceof MoonlightClift) Howl();
}
public void Howl()
{ GreenfootSound WolfHowls= new GreenfootSound( "wolfhowl.wav" );
if(Greenfoot.isKeyDown("H")) WolfHowls.play();
}
public void moveUp()
{setLocation (getX(),getY()-30);
}
public void moveDown()
{setLocation (getX(),getY()+30);
}
public void moveLeft()
{setLocation (getX()-30,getY());
}
public void moveRight()
{setLocation (getX()+30,getY());
}
public void KeyboardCheck()
{if (Greenfoot.isKeyDown("s"))
{
if(StonesCheck(0,+30))
if(Wall1Check(0,+30))
if(Wall2Check(0,+30))
if(FunitureCheck(0,+30))
if(HillCheck(0,+30))
if(MapCorpsCheck(0,+30))
if(Treescheck(0,+30))
if(Parentscheck(0,+30))
if(Freaturecheck(0,+30))
if(WallEastCheck(0, +30))
if(WallNorthCheck(0, +30))
if(WallNorthEastCheck(0, +30))
if(WallNorthWesttCheck(0, +30))
if(WallSouthCheck(0, +30))
if(WallSouthEastCheck(0, +30))
if(WallSouthWestCheck(0, +30))
if(WallWestCheck(0, +30))
moveDown();
}
if (Greenfoot.isKeyDown("w"))
{
if(StonesCheck(0,-30))
if(Wall1Check(0,-30))
if(Wall2Check(0,-30))
if(FunitureCheck(0,-30))
if(HillCheck(0,-30))
if(MapCorpsCheck(0,-30))
if(Treescheck(0,-30))
if(Parentscheck(0,-30))
if(Freaturecheck(0,-30))
if(WallEastCheck(0, -30))
if(WallNorthCheck(0, -30))
if(WallNorthEastCheck(0, -30))
if(WallNorthWesttCheck(0, -30))
if(WallSouthCheck(0, -30))
if(WallSouthEastCheck(0, -30))
if(WallSouthWestCheck(0, -30))
if(WallWestCheck(0, -30))
moveUp();}
if (Greenfoot.isKeyDown("a"))
{
if(StonesCheck(-30,0))
if(Wall1Check(-30,0))
if(Wall2Check(-30,0))
if(FunitureCheck(-30,0))
if(HillCheck(-30,0))
if(MapCorpsCheck(-30,0))
if(Treescheck(-30,0))
if(Parentscheck(-30,0))
if(Freaturecheck(-30,0))
if(WallEastCheck(-30, 0))
if(WallNorthCheck(-30, 0))
if(WallNorthEastCheck(-30, 0))
if(WallNorthWesttCheck(-30, 0))
if(WallSouthCheck(-30, 0))
if(WallSouthEastCheck(-30, 0))
if(WallSouthWestCheck(-30, 0))
if(WallWestCheck(-30, 0))
moveLeft();
}
if (Greenfoot.isKeyDown("d"))
{if(StonesCheck(+30,0))
if(Wall1Check(+30,0))
if(Wall2Check(+30,0))
if(FunitureCheck(+30,0))
if(HillCheck(+30,0))
if(MapCorpsCheck(+30,0))
if(Treescheck(+30,0))
if(Parentscheck(+30,0))
if(Freaturecheck(+30,0))
if(WallEastCheck(+30, 0))
if(WallNorthCheck(+30, 0))
if(WallNorthEastCheck(+30, 0))
if(WallNorthWesttCheck(+30, 0))
if(WallSouthCheck(+30, 0))
if(WallSouthEastCheck(+30, 0))
if(WallSouthWestCheck(+30, 0))
if(WallWestCheck(+30, 0))
moveRight();}
}
public boolean StonesCheck(int x, int y)
{
Actor Stones = getOneObjectAtOffset(x, y, Stones.class );
return(Stones==null);
}
public boolean Wall1Check(int x, int y)
{
Actor Wall1 = getOneObjectAtOffset(x, y, Wall1.class );
return(Wall1==null);
}
public boolean Wall2Check(int x, int y)
{
Actor Wall2= getOneObjectAtOffset(x, y, Wall2.class );
return(Wall2==null);
}
public boolean FunitureCheck(int x, int y)
{
Actor Funiture= getOneObjectAtOffset(x, y, funiture.class );
return(Funiture==null);
}
public boolean HillCheck(int x, int y)
{
Actor Hill= getOneObjectAtOffset(x, y, Hill.class );
return(Hill==null);
}
public boolean MapCorpsCheck(int x, int y)
{
Actor MapCorps= getOneObjectAtOffset(x, y, MapCorps.class );
return(MapCorps==null);
}
public boolean Treescheck(int x, int y)
{Actor Tree= getOneObjectAtOffset(x, y, Tree.class );
return(Tree==null);
}
public boolean Parentscheck(int x, int y)
{Actor Parents= getOneObjectAtOffset(x, y, Parents.class );
return(Parents==null);
}
public boolean Freaturecheck(int x, int y)
{Actor Freature= getOneObjectAtOffset(x, y, Freature.class );
return(Freature==null);
}
public boolean Enemy(){
Actor Enemy = getOneObjectAtOffset(0, 0, Enemy.class );
return(Enemy!=null);
}
public boolean WallEastCheck(int x, int y)
{Actor WallEast = getOneObjectAtOffset(x, y, WallEast.class );
return(WallEast==null);
}
public boolean WallNorthCheck(int x, int y)
{Actor WallNorth = getOneObjectAtOffset(x, y, WallNorth.class );
return(WallNorth==null);
}
public boolean WallNorthEastCheck(int x, int y)
{Actor WallNorthEast = getOneObjectAtOffset(x, y, WallNorthEast.class );
return(WallNorthEast==null);
}
public boolean WallNorthWesttCheck(int x, int y)
{Actor WallNorthWest = getOneObjectAtOffset(x, y, WallNorthWest.class );
return(WallNorthWest==null);
}
public boolean WallSouthCheck(int x, int y)
{Actor WallSouth = getOneObjectAtOffset(x, y, WallSouth.class );
return(WallSouth==null);
}
public boolean WallSouthEastCheck(int x, int y)
{Actor WallSouthEast = getOneObjectAtOffset(x, y, WallSouthEast.class );
return(WallSouthEast==null);
}
public boolean WallWestCheck(int x, int y)
{Actor WallWest = getOneObjectAtOffset(x, y, WallWest.class );
return(WallWest==null);
}
public boolean WallSouthWestCheck(int x, int y)
{Actor WallWest = getOneObjectAtOffset(x, y, WallWest.class );
return(WallWest==null);
}
public void AttackAlien()
{Actor Alien = getOneObjectAtOffset(0, 0, Alien.class);
if(Alien!=null)
{
}
}}
