This repository was archived by the owner on Jan 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSWLaser.java
executable file
·66 lines (63 loc) · 1.63 KB
/
SWLaser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Laser here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SWLaser extends SmoothMover
{
private SWShip owner;
private double damage=1;
/** "Ro" rot
* "Bl" blau
* "Gr" gruen
*/
public SWLaser(int rot,SWShip owner,String farbe,double damage,int move)
{
this.owner=owner;
this.damage=damage;
setRotation(rot);
setImage("images/laser"+farbe+".png");
move(move);
}
public SWLaser(int rot,SWShip owner,String farbe,double damage)
{
this.owner=owner;
this.damage=damage;
setRotation(rot);
setImage("images/laser"+farbe+".png");
}
/**
* Act - do whatever the Laser wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
try
{
if(reachedTarget())
{
SWShip hitted=(SWShip)getOneIntersectingObject(SWShip.class);
hitted.hit(damage);
getWorld().removeObject(this);
}
if(isAtEdge())
{
getWorld().removeObject(this);
return;
}
move(10);
}
catch(NullPointerException ne)
{}
catch(IllegalStateException ie)
{}
catch(IllegalMonitorStateException ime)
{}
}
public boolean reachedTarget()
{
return getOneIntersectingObject(SWShip.class)!=this.owner&&getOneIntersectingObject(SWShip.class)!=null;
}
}