diff --git a/src/main/java/chapter11/bystander/Bystander.java b/src/main/java/chapter11/bystander/Bystander.java index 732f8e2..132ba43 100644 --- a/src/main/java/chapter11/bystander/Bystander.java +++ b/src/main/java/chapter11/bystander/Bystander.java @@ -1,9 +1,8 @@ package chapter11.bystander; -public class Bystander extends RightShoe -{ - public void learn(Dance dance) - { +public class Bystander extends RightShoe { + @Override + public void learn(Dance dance) { setSteps("-1 -7 "); } } diff --git a/src/main/java/chapter11/bystander/BystanderRunner.java b/src/main/java/chapter11/bystander/BystanderRunner.java index ece46ba..8f56340 100644 --- a/src/main/java/chapter11/bystander/BystanderRunner.java +++ b/src/main/java/chapter11/bystander/BystanderRunner.java @@ -3,16 +3,14 @@ import info.gridworld.actor.ActorWorld; import info.gridworld.grid.Location; -public class BystanderRunner extends CongaNumber -{ +public class BystanderRunner extends CongaNumber { @Override - public void setUpDancers(ActorWorld world) - { + public void setUpDancers(ActorWorld world) { super.setUpDancers(world); world.add(new Location(0, 9), new Bystander()); } - public static void main(String[] args) - { + + public static void main(String[] args) { DanceNumber number = new BystanderRunner(); number.run(new ActorWorld(), new Conga()); } diff --git a/src/main/java/chapter11/bystander/Conga.java b/src/main/java/chapter11/bystander/Conga.java index 0e36fdd..0fb331b 100644 --- a/src/main/java/chapter11/bystander/Conga.java +++ b/src/main/java/chapter11/bystander/Conga.java @@ -1,24 +1,30 @@ package chapter11.bystander; -public class Conga implements Dance -{ - private static String[] steps = - { - "00 -- 00 -- -- 77 -- 02 37 -- 40 -- -- 37 -- 41 ", - "-- 00 -- 07 00 -- 01 -- -- 40 -- 47 40 -- 41 -- ", - "00 -- 00 -- -- 77 -- 02 37 -- 40 -- -- 37 -- 41 ", - "-- 00 -- 07 00 -- 01 -- -- 40 -- 47 40 -- 41 -- ", - "00 -- 01 -- -- 37 -- 40 00 -- 07 -- -- 51 -- 40 ", - "60 -- 60 -- -- 60 -- 64 60 -- 60 -- -- 60 -- 64 ", - }; +public class Conga implements Dance { + private static String[] steps = + { + "00 -- 00 -- -- 77 -- 02 37 -- 40 -- -- 37 -- 41 ", + "-- 00 -- 07 00 -- 01 -- -- 40 -- 47 40 -- 41 -- ", + "00 -- 00 -- -- 77 -- 02 37 -- 40 -- -- 37 -- 41 ", + "-- 00 -- 07 00 -- 01 -- -- 40 -- 47 40 -- 41 -- ", + "00 -- 01 -- -- 37 -- 40 00 -- 07 -- -- 51 -- 40 ", + "60 -- 60 -- -- 60 -- 64 60 -- 60 -- -- 60 -- 64 ", + }; - private static int[] beat = {2, 2, 1, 1}; + private static int[] beat = {2, 2, 1, 1}; - public String getName() - { - return "Conga"; - } + @Override + public String getName() { + return "Conga"; + } - public String getSteps(int m) { return steps[m-1]; } - public int[] getBeat() { return beat; } -} + @Override + public String getSteps(int m) { + return steps[m - 1]; + } + + @Override + public int[] getBeat() { + return beat; + } +} \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/CongaNumber.java b/src/main/java/chapter11/bystander/CongaNumber.java index bcdb7e9..891ebb5 100644 --- a/src/main/java/chapter11/bystander/CongaNumber.java +++ b/src/main/java/chapter11/bystander/CongaNumber.java @@ -2,28 +2,27 @@ import info.gridworld.actor.ActorWorld; import info.gridworld.grid.Location; + import java.awt.Color; -public class CongaNumber extends DanceNumber -{ - public void setUpDancers(ActorWorld world) - { - super.setUpDancers(world); +public class CongaNumber extends DanceNumber { + @Override + public void setUpDancers(ActorWorld world) { + super.setUpDancers(world); - world.add(new Location(5, 3), new LeftSandal()); - world.add(new Location(5, 4), new RightSandal()); - world.add(new Location(5, 6), new LeftShoe()); - world.add(new Location(5, 7), new RightShoe()); - world.add(new Location(7, 2), new DancingBug(Color.YELLOW)); - world.add(new Location(7, 4), new DancingBug(Color.GREEN)); - world.add(new Location(7, 6), new DancingBug(Color.YELLOW)); - world.add(new Location(7, 8), new DancingBug()); - world.add(new Location(8, 6), new DancingCrab()); - } + world.add(new Location(5, 3), new LeftSandal()); + world.add(new Location(5, 4), new RightSandal()); + world.add(new Location(5, 6), new LeftShoe()); + world.add(new Location(5, 7), new RightShoe()); + world.add(new Location(7, 2), new DancingBug(Color.YELLOW)); + world.add(new Location(7, 4), new DancingBug(Color.GREEN)); + world.add(new Location(7, 6), new DancingBug(Color.YELLOW)); + world.add(new Location(7, 8), new DancingBug()); + world.add(new Location(8, 6), new DancingCrab()); + } - public static void main(String[] args) - { - DanceNumber number = new CongaNumber(); - number.run(new ActorWorld(), new Conga()); - } + public static void main(String[] args) { + DanceNumber number = new CongaNumber(); + number.run(new ActorWorld(), new Conga()); + } } diff --git a/src/main/java/chapter11/bystander/Dance.java b/src/main/java/chapter11/bystander/Dance.java index 9e80806..cfa2d1c 100644 --- a/src/main/java/chapter11/bystander/Dance.java +++ b/src/main/java/chapter11/bystander/Dance.java @@ -1,8 +1,9 @@ package chapter11.bystander; -public interface Dance -{ - String getName(); - String getSteps(int m); - int[] getBeat(); +public interface Dance { + String getName(); + + String getSteps(int m); + + int[] getBeat(); } diff --git a/src/main/java/chapter11/bystander/DanceNumber.java b/src/main/java/chapter11/bystander/DanceNumber.java index 944d889..f27891f 100644 --- a/src/main/java/chapter11/bystander/DanceNumber.java +++ b/src/main/java/chapter11/bystander/DanceNumber.java @@ -5,36 +5,31 @@ import info.gridworld.grid.Grid; import info.gridworld.grid.Location; -public class DanceNumber -{ - public void setUpDancers(ActorWorld world) - { - world.add(new Location(0, 0), new Maracas()); - } +public class DanceNumber { + public void setUpDancers(ActorWorld world) { + world.add(new Location(0, 0), new Maracas()); + } - public void teach(ActorWorld world, Dance dance) - { - world.setMessage(dance.getName()); + public void teach(ActorWorld world, Dance dance) { + world.setMessage(dance.getName()); - Grid gr = world.getGrid(); - for (Location loc : gr.getOccupiedLocations()) - { - Actor a = gr.get(loc); - if (a instanceof Dancer) - ((Dancer)a).learn(dance); + Grid gr = world.getGrid(); + for (Location loc : gr.getOccupiedLocations()) { + Actor a = gr.get(loc); + if (a instanceof Dancer) { + ((Dancer) a).learn(dance); + } + } } - } - public void run(ActorWorld world, Dance dance) - { - setUpDancers(world); - teach(world, dance); - world.show(); - } + public void run(ActorWorld world, Dance dance) { + setUpDancers(world); + teach(world, dance); + world.show(); + } - public static void main(String[] args) - { - DanceNumber number = new DanceNumber(); - number.run(new ActorWorld(), new MusicOnly()); - } -} + public static void main(String[] args) { + DanceNumber number = new DanceNumber(); + number.run(new ActorWorld(), new MusicOnly()); + } +} \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/DanceRunner.java b/src/main/java/chapter11/bystander/DanceRunner.java index 9eb52c3..6139746 100644 --- a/src/main/java/chapter11/bystander/DanceRunner.java +++ b/src/main/java/chapter11/bystander/DanceRunner.java @@ -1,18 +1,12 @@ package chapter11.bystander; -public class DanceRunner -{ - public static void main(String[] args) - { - int k = (int)(3 * Math.random()); - switch (k) - { - case 0: - WaltzNumber.main(args); break; - case 1: - YMCANumber.main(args); break; - case 2: - CongaNumber.main(args); break; +public class DanceRunner { + public static void main(String[] args) { + int k = (int) (3 * Math.random()); + switch (k) { + case 0 -> WaltzNumber.main(args); + case 1 -> YMCANumber.main(args); + case 2 -> CongaNumber.main(args); + } } - } } \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/Dancer.java b/src/main/java/chapter11/bystander/Dancer.java index f635193..d06e341 100644 --- a/src/main/java/chapter11/bystander/Dancer.java +++ b/src/main/java/chapter11/bystander/Dancer.java @@ -2,61 +2,55 @@ import info.gridworld.actor.Actor; import info.gridworld.grid.Location; + import java.awt.Color; -public abstract class Dancer extends Actor -{ - private String steps; - private int stepsCount; - - public Dancer() - { - setColor(null); - } - - public Dancer(Color color) - { - setColor(color); - } - - public void setSteps(String steps) - { - this.steps = steps; - stepsCount = 0; - } - - public void act() - { - if (getGrid() != null && steps != null) - { - takeStep(steps.substring(stepsCount, stepsCount + 3)); - stepsCount += 3; - if (stepsCount >= steps.length() - 2) +public abstract class Dancer extends Actor { + private String steps; + private int stepsCount; + + public Dancer() { + setColor(null); + } + + public Dancer(Color color) { + setColor(color); + } + + public void setSteps(String steps) { + this.steps = steps; stepsCount = 0; } - } - - private void takeStep(String step) - { - char d = step.charAt(0); - if (Character.isDigit(d)) - { - int dir = Character.digit(d, 10) * 45; - Location loc = getLocation(); - Location next = loc.getAdjacentLocation(getDirection() + dir); - if (getGrid().isValid(next)) - moveTo(next); - else - removeSelfFromGrid(); + + public void act() { + if (getGrid() != null && steps != null) { + takeStep(steps.substring(stepsCount, stepsCount + 3)); + stepsCount += 3; + if (stepsCount >= steps.length() - 2) { + stepsCount = 0; + } + } } - d = step.charAt(1); - if (Character.isDigit(d)) - { - int dir = Character.digit(d, 10) * 45; - setDirection(getDirection() + dir); + private void takeStep(String step) { + char d = step.charAt(0); + if (Character.isDigit(d)) { + int dir = Character.digit(d, 10) * 45; + Location loc = getLocation(); + Location next = loc.getAdjacentLocation(getDirection() + dir); + if (getGrid().isValid(next)) { + moveTo(next); + } else { + removeSelfFromGrid(); + } + } + + d = step.charAt(1); + if (Character.isDigit(d)) { + int dir = Character.digit(d, 10) * 45; + setDirection(getDirection() + dir); + } } - } - public abstract void learn(Dance dance); + public abstract void learn(Dance dance); } diff --git a/src/main/java/chapter11/bystander/DancingBug.java b/src/main/java/chapter11/bystander/DancingBug.java index 007016a..9703b3e 100644 --- a/src/main/java/chapter11/bystander/DancingBug.java +++ b/src/main/java/chapter11/bystander/DancingBug.java @@ -2,19 +2,15 @@ import java.awt.Color; -public class DancingBug extends Dancer -{ - public DancingBug() - { - } +public class DancingBug extends Dancer { + public DancingBug() {} - public DancingBug(Color color) - { - super(color); - } + public DancingBug(Color color) { + super(color); + } - public void learn(Dance dance) - { - setSteps(dance.getSteps(5)); - } + @Override + public void learn(Dance dance) { + setSteps(dance.getSteps(5)); + } } \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/DancingCrab.java b/src/main/java/chapter11/bystander/DancingCrab.java index fa474cc..33de816 100644 --- a/src/main/java/chapter11/bystander/DancingCrab.java +++ b/src/main/java/chapter11/bystander/DancingCrab.java @@ -1,9 +1,8 @@ package chapter11.bystander; -public class DancingCrab extends Dancer -{ - public void learn(Dance dance) - { - setSteps(dance.getSteps(6)); - } +public class DancingCrab extends Dancer { + @Override + public void learn(Dance dance) { + setSteps(dance.getSteps(6)); + } } \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/EasySound.java b/src/main/java/chapter11/bystander/EasySound.java index 52a1e12..9c0bbab 100644 --- a/src/main/java/chapter11/bystander/EasySound.java +++ b/src/main/java/chapter11/bystander/EasySound.java @@ -9,57 +9,44 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; -public class EasySound -{ - private SourceDataLine line = null; - private byte[] audioBytes; - private int numBytes; - - public EasySound(String fileName) - { - File soundFile = new File(fileName); - AudioInputStream audioInputStream = null; - try - { - audioInputStream = AudioSystem.getAudioInputStream(soundFile); - } - catch (Exception ex) - { - System.out.println("*** Cannot find " + fileName + " ***"); - System.exit(1); +public class EasySound { + private SourceDataLine line = null; + private byte[] audioBytes; + private int numBytes; + + public EasySound(String fileName) { + File soundFile = new File(fileName); + AudioInputStream audioInputStream = null; + try { + audioInputStream = AudioSystem.getAudioInputStream(soundFile); + } catch (Exception e) { + System.out.println("*** Cannot find " + fileName + " ***"); + System.exit(1); + } + + AudioFormat audioFormat = audioInputStream.getFormat(); + DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); + try { + line = (SourceDataLine) AudioSystem.getLine(info); + line.open(audioFormat); + } catch (LineUnavailableException e) { + System.out.println("*** Audio line unavailable ***"); + System.exit(1); + } + + line.start(); + + audioBytes = new byte[(int) soundFile.length()]; + + try { + numBytes = audioInputStream.read(audioBytes, 0, audioBytes.length); + } catch (IOException ex) { + System.out.println("*** Cannot read " + fileName + " ***"); + System.exit(1); + } } - AudioFormat audioFormat = audioInputStream.getFormat(); - DataLine.Info info = new DataLine.Info(SourceDataLine.class, - audioFormat); - try - { - line = (SourceDataLine)AudioSystem.getLine(info); - line.open(audioFormat); - } - catch (LineUnavailableException ex) - { - System.out.println("*** Audio line unavailable ***"); - System.exit(1); + public void play() { + line.write(audioBytes, 0, numBytes); } - - line.start(); - - audioBytes = new byte[(int)soundFile.length()]; - - try - { - numBytes = audioInputStream.read(audioBytes, 0, audioBytes.length); - } - catch (IOException ex) - { - System.out.println("*** Cannot read " + fileName + " ***"); - System.exit(1); - } - } - - public void play() - { - line.write(audioBytes, 0, numBytes); - } -} +} \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/LeftSandal.java b/src/main/java/chapter11/bystander/LeftSandal.java index dc10c65..2a7d369 100644 --- a/src/main/java/chapter11/bystander/LeftSandal.java +++ b/src/main/java/chapter11/bystander/LeftSandal.java @@ -1,9 +1,8 @@ package chapter11.bystander; -public class LeftSandal extends Dancer -{ - public void learn(Dance dance) - { - setSteps(dance.getSteps(3)); - } +public class LeftSandal extends Dancer { + @Override + public void learn(Dance dance) { + setSteps(dance.getSteps(3)); + } } \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/LeftShoe.java b/src/main/java/chapter11/bystander/LeftShoe.java index 8a841af..0c9693f 100644 --- a/src/main/java/chapter11/bystander/LeftShoe.java +++ b/src/main/java/chapter11/bystander/LeftShoe.java @@ -1,9 +1,8 @@ package chapter11.bystander; -public class LeftShoe extends Dancer -{ - public void learn(Dance dance) - { - setSteps(dance.getSteps(1)); - } +public class LeftShoe extends Dancer { + @Override + public void learn(Dance dance) { + setSteps(dance.getSteps(1)); + } } diff --git a/src/main/java/chapter11/bystander/Maracas.java b/src/main/java/chapter11/bystander/Maracas.java index ea7d713..f8014a9 100644 --- a/src/main/java/chapter11/bystander/Maracas.java +++ b/src/main/java/chapter11/bystander/Maracas.java @@ -1,37 +1,35 @@ package chapter11.bystander; -public class Maracas extends Dancer -{ - private EasySound[] beatSound; - private int[] beat; - private int stepsCount; +public class Maracas extends Dancer { + private EasySound[] beatSound; + private int[] beat; + private int stepsCount; - public Maracas() - { - beatSound = new EasySound[3]; - beatSound[1] = new EasySound("beat1.wav"); - beatSound[2] = new EasySound("beat2.wav"); - } - - public void learn(Dance dance) - { - beat = dance.getBeat(); - stepsCount = 0; - setSteps("21 57 "); - } + public Maracas() { + beatSound = new EasySound[3]; + beatSound[1] = new EasySound("beat1.wav"); + beatSound[2] = new EasySound("beat2.wav"); + } - public void act() - { - if (beat != null) - { - int i = beat[stepsCount]; - if (i > 0) - beatSound[i].play(); - stepsCount++; - if (stepsCount >= beat.length) + @Override + public void learn(Dance dance) { + beat = dance.getBeat(); stepsCount = 0; + setSteps("21 57 "); } - super.act(); - } -} + @Override + public void act() { + if (beat != null) { + int i = beat[stepsCount]; + if (i > 0) { + beatSound[i].play(); + } + stepsCount++; + if (stepsCount >= beat.length) { + stepsCount = 0; + } + } + super.act(); + } +} \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/MusicOnly.java b/src/main/java/chapter11/bystander/MusicOnly.java index 5403449..f06ac1e 100644 --- a/src/main/java/chapter11/bystander/MusicOnly.java +++ b/src/main/java/chapter11/bystander/MusicOnly.java @@ -1,11 +1,18 @@ package chapter11.bystander; -public class MusicOnly implements Dance -{ - private static String[] steps = {"-- "}; - private static int[] beat = {2}; - - public String getName() { return "Music Only"; } - public String getSteps(int m) { return steps[m-1]; } - public int[] getBeat() { return beat; } +public class MusicOnly implements Dance { + private static String[] steps = {"-- "}; + private static int[] beat = {2}; + + public String getName() { + return "Music Only"; + } + + public String getSteps(int m) { + return steps[m - 1]; + } + + public int[] getBeat() { + return beat; + } } diff --git a/src/main/java/chapter11/bystander/RightSandal.java b/src/main/java/chapter11/bystander/RightSandal.java index 082c420..5c07d68 100644 --- a/src/main/java/chapter11/bystander/RightSandal.java +++ b/src/main/java/chapter11/bystander/RightSandal.java @@ -1,9 +1,8 @@ package chapter11.bystander; -public class RightSandal extends Dancer -{ - public void learn(Dance dance) - { - setSteps(dance.getSteps(4)); - } +public class RightSandal extends Dancer { + @Override + public void learn(Dance dance) { + setSteps(dance.getSteps(4)); + } } \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/RightShoe.java b/src/main/java/chapter11/bystander/RightShoe.java index e893f1e..414924f 100644 --- a/src/main/java/chapter11/bystander/RightShoe.java +++ b/src/main/java/chapter11/bystander/RightShoe.java @@ -1,9 +1,8 @@ package chapter11.bystander; -public class RightShoe extends Dancer -{ - public void learn(Dance dance) - { - setSteps(dance.getSteps(2)); - } +public class RightShoe extends Dancer { + @Override + public void learn(Dance dance) { + setSteps(dance.getSteps(2)); + } } \ No newline at end of file diff --git a/src/main/java/chapter11/bystander/Waltz.java b/src/main/java/chapter11/bystander/Waltz.java index 93d109c..7a53244 100644 --- a/src/main/java/chapter11/bystander/Waltz.java +++ b/src/main/java/chapter11/bystander/Waltz.java @@ -1,24 +1,30 @@ package chapter11.bystander; -public class Waltz implements Dance -{ - private static String[] steps = - { - "00 -- 20 -- 50 -- ", - "-- 10 -- 40 -- 60 ", - "-- 50 -- 00 -- 20 ", - "40 -- 60 -- 10 -- ", - "-7 -1 -1 ", - "60 60 -2 ", - }; +public class Waltz implements Dance { + private static String[] steps = + { + "00 -- 20 -- 50 -- ", + "-- 10 -- 40 -- 60 ", + "-- 50 -- 00 -- 20 ", + "40 -- 60 -- 10 -- ", + "-7 -1 -1 ", + "60 60 -2 ", + }; - private static int[] beat = {1, 2, 2}; + private static int[] beat = {1, 2, 2}; - public String getName() - { - return "chapter11.bystander.Waltz"; - } + @Override + public String getName() { + return "chapter11.bystander.Waltz"; + } - public String getSteps(int m) { return steps[m-1]; } - public int[] getBeat() { return beat; } + @Override + public String getSteps(int m) { + return steps[m - 1]; + } + + @Override + public int[] getBeat() { + return beat; + } } diff --git a/src/main/java/chapter11/bystander/WaltzNumber.java b/src/main/java/chapter11/bystander/WaltzNumber.java index 94743ec..e6d9fe6 100644 --- a/src/main/java/chapter11/bystander/WaltzNumber.java +++ b/src/main/java/chapter11/bystander/WaltzNumber.java @@ -4,27 +4,25 @@ import info.gridworld.actor.Actor; import info.gridworld.grid.Location; -public class WaltzNumber extends DanceNumber -{ - public void setUpDancers(ActorWorld world) - { - super.setUpDancers(world); +public class WaltzNumber extends DanceNumber { + @Override + public void setUpDancers(ActorWorld world) { + super.setUpDancers(world); - world.add(new Location(4, 5), new LeftShoe()); - world.add(new Location(4, 6), new RightShoe()); - Actor leftSandal = new LeftSandal(); - leftSandal.setDirection(180); - world.add(new Location(2, 6), leftSandal); - Actor rightSandal = new RightSandal(); - rightSandal.setDirection(180); - world.add(new Location(2, 5), rightSandal); - world.add(new Location(6, 3), new DancingBug()); - world.add(new Location(7, 4), new DancingCrab()); - } + world.add(new Location(4, 5), new LeftShoe()); + world.add(new Location(4, 6), new RightShoe()); + Actor leftSandal = new LeftSandal(); + leftSandal.setDirection(180); + world.add(new Location(2, 6), leftSandal); + Actor rightSandal = new RightSandal(); + rightSandal.setDirection(180); + world.add(new Location(2, 5), rightSandal); + world.add(new Location(6, 3), new DancingBug()); + world.add(new Location(7, 4), new DancingCrab()); + } - public static void main(String[] args) - { - DanceNumber number = new WaltzNumber(); - number.run(new ActorWorld(), new Waltz()); - } + public static void main(String[] args) { + DanceNumber number = new WaltzNumber(); + number.run(new ActorWorld(), new Waltz()); + } } diff --git a/src/main/java/chapter11/bystander/YMCA.java b/src/main/java/chapter11/bystander/YMCA.java index b54a651..68e94e6 100644 --- a/src/main/java/chapter11/bystander/YMCA.java +++ b/src/main/java/chapter11/bystander/YMCA.java @@ -1,24 +1,30 @@ package chapter11.bystander; -public class YMCA implements Dance -{ - private static String[] steps = - { - "67 31 ", - "21 57 ", - "67 31 ", - "21 57 ", - "67 31 21 57 ", - "60 60 20 20 20 20 60 60 ", - }; +public class YMCA implements Dance { + private static String[] steps = + { + "67 31 ", + "21 57 ", + "67 31 ", + "21 57 ", + "67 31 21 57 ", + "60 60 20 20 20 20 60 60 ", + }; - private static int[] beat = {1, 1, 1, 1, 2, 2, 2, 2}; + private static int[] beat = {1, 1, 1, 1, 2, 2, 2, 2}; - public String getName() - { - return "chapter11.bystander.YMCA"; - } + @Override + public String getName() { + return "chapter11.bystander.YMCA"; + } - public String getSteps(int m) { return steps[m-1]; } - public int[] getBeat() { return beat; } + @Override + public String getSteps(int m) { + return steps[m - 1]; + } + + @Override + public int[] getBeat() { + return beat; + } } diff --git a/src/main/java/chapter11/bystander/YMCANumber.java b/src/main/java/chapter11/bystander/YMCANumber.java index 3ac5e6c..4055bd2 100644 --- a/src/main/java/chapter11/bystander/YMCANumber.java +++ b/src/main/java/chapter11/bystander/YMCANumber.java @@ -3,31 +3,32 @@ import info.gridworld.actor.ActorWorld; import info.gridworld.actor.Actor; import info.gridworld.grid.Location; + import java.awt.Color; -public class YMCANumber extends DanceNumber -{ - public void setUpDancers(ActorWorld world) - { - super.setUpDancers(world); +public class YMCANumber extends DanceNumber { + @Override + public void setUpDancers(ActorWorld world) { + super.setUpDancers(world); - Actor leftSandal = new LeftSandal(); - leftSandal.setDirection(180); - world.add(new Location(1, 5), leftSandal); - Actor rightSandal = new RightSandal(); - rightSandal.setDirection(180); - world.add(new Location(1, 4), rightSandal); - world.add(new Location(5, 2), new LeftShoe()); - world.add(new Location(5, 3), new RightShoe()); - world.add(new Location(5, 7), new DancingBug()); - world.add(new Location(7, 2), new DancingBug(Color.YELLOW)); - world.add(new Location(7, 4), new DancingBug(Color.GREEN)); - world.add(new Location(8, 6), new DancingCrab()); - } + Actor leftSandal = new LeftSandal(); + leftSandal.setDirection(180); + world.add(new Location(1, 5), leftSandal); + Actor rightSandal = new RightSandal(); + rightSandal.setDirection(180); + world.add(new Location(1, 4), rightSandal); + world.add(new Location(5, 2), new LeftShoe()); + world.add(new Location(5, 3), new RightShoe()); + world.add(new Location(5, 7), new DancingBug()); + world.add(new Location(7, 2), new DancingBug(Color.YELLOW)); + world.add(new Location(7, 4), new DancingBug(Color.GREEN)); + world.add(new Location(8, 6), new DancingCrab()); + } - public static void main(String[] args) - { - DanceNumber number = new YMCANumber(); - number.run(new ActorWorld(), new YMCA()); - } + public static void main(String[] args) { + DanceNumber number = new YMCANumber(); + number.run(new ActorWorld(), new YMCA()); + } } + +public @interface \ No newline at end of file