parent
8f015ee458
commit
33989e28ee
@ -0,0 +1,14 @@
|
||||
package com.example.tankbattle;
|
||||
|
||||
public class DefaultFireStrategy implements FireStrategy {
|
||||
|
||||
@Override
|
||||
public void fire(Tank t) {
|
||||
int bX = t.x + Tank.WIDTH/2 - Bullet.WIDTH/2;
|
||||
int bY = t.y + Tank.HEIGHT/2 - Bullet.HEIGHT/2;
|
||||
|
||||
new Bullet(bX, bY, t.dir, t.group, t.tf);
|
||||
|
||||
if(t.group == Group.GOOD) new Thread(()->new Audio("audio/tank_fire.wav").play()).start();
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.example.tankbattle;
|
||||
|
||||
public interface FireStrategy {
|
||||
void fire(Tank Tank);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.example.tankbattle;
|
||||
|
||||
public class FourDirFireStrategy implements FireStrategy {
|
||||
|
||||
@Override
|
||||
public void fire(Tank t) {
|
||||
int bX = t.x + Tank.WIDTH/2 - Bullet.WIDTH/2;
|
||||
int bY = t.y + Tank.HEIGHT/2 - Bullet.HEIGHT/2;
|
||||
|
||||
Dir[] dirs = Dir.values();
|
||||
for(Dir dir : dirs) {
|
||||
new Bullet(bX, bY, dir, t.group, t.tf);
|
||||
}
|
||||
|
||||
if(t.group == Group.GOOD) new Thread(()->new Audio("audio/tank_fire.wav").play()).start();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue