Formatted all files to the same standard
This commit is contained in:
@ -1,22 +1,22 @@
|
||||
package com.iluwatar;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Strategy (DragonSlayingStrategy) encapsulates the algorithm to use. The
|
||||
* object (DragonSlayer) can alter its behavior by changing its strategy.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Green dragon spotted ahead!");
|
||||
DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
System.out.println("Red dragon emerges.");
|
||||
dragonSlayer.changeStrategy(new ProjectileStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
System.out.println("Black dragon lands before you.");
|
||||
dragonSlayer.changeStrategy(new SpellStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Green dragon spotted ahead!");
|
||||
DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
System.out.println("Red dragon emerges.");
|
||||
dragonSlayer.changeStrategy(new ProjectileStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
System.out.println("Black dragon lands before you.");
|
||||
dragonSlayer.changeStrategy(new SpellStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* DragonSlayer uses different strategies to slay the dragon.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DragonSlayer {
|
||||
|
||||
@ -16,7 +16,7 @@ public class DragonSlayer {
|
||||
public void changeStrategy(DragonSlayingStrategy strategy) {
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
|
||||
public void goToBattle() {
|
||||
strategy.execute();
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* Strategy interface.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface DragonSlayingStrategy {
|
||||
|
||||
void execute();
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ public class ProjectileStrategy implements DragonSlayingStrategy {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
System.out.println("You shoot the dragon with the magical crossbow and it falls dead on the ground!");
|
||||
System.out
|
||||
.println("You shoot the dragon with the magical crossbow and it falls dead on the ground!");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ public class SpellStrategy implements DragonSlayingStrategy {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
System.out.println("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");
|
||||
System.out
|
||||
.println("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user