1. 程式人生 > 遊戲攻略 >《幻塔》奈美西斯版本解讀

《幻塔》奈美西斯版本解讀

public class StrategyTest {
public static void main(String[] args) {
// Zombie zombie = new FlagZombie();
Zombie zombie = new BigHeadZombie();
zombie.display();
zombie.move();
zombie.attack();
zombie.setAttackable(new Peng());
zombie.attack();
     /**

        我是大頭殭屍..
        一步一步的移動..
       咬
       碰

      **/

    }
}

interface Moveable {
void move();
}

interface Attackable {
void attack();
}

@Data
abstract class Zombie {
private Moveable moveable;
private Attackable attackable;
abstract void display();
abstract void move();
abstract void attack();

public Zombie(Moveable moveable
, Attackable attackable) {
this.moveable = moveable;
this.attackable = attackable;
}
}

class StepByMoveable implements Moveable {
@Override
public void move() {
System.out.println("一步一步的移動..");
}
}

class Peng implements Attackable {
@Override
public void attack() {
System.out.println("碰");
}
}

class Yao implements Attackable {
@Override
public void attack() {
System.out.println("咬");
}
}

class FlagZombie extends Zombie {
public FlagZombie() {
super(new StepByMoveable(), new Peng());
}

public FlagZombie(Moveable moveable, Attackable attackable) {
super(moveable, attackable);
}

@Override
void display() {
System.out.println("我是騎手殭屍..");
}

@Override
void move() {
getMoveable().move();
}

@Override
void attack() {
getAttackable().attack();
}
}

class BigHeadZombie extends Zombie {
public BigHeadZombie() {
super(new StepByMoveable(), new Yao());
}

public BigHeadZombie(Moveable moveable, Attackable attackable) {
super(moveable, attackable);
}

@Override
void display() {
System.out.println("我是大頭殭屍..");
}

@Override
void move() {
getMoveable().move();
}

@Override
void attack() {
getAttackable().attack();
}
}