File tree Expand file tree Collapse file tree 6 files changed +18
-19
lines changed Open diff view settings
Expand file tree Collapse file tree 6 files changed +18
-19
lines changed Open diff view settings
Original file line number Diff line number Diff line change @@ -34,8 +34,8 @@ public void step() {
3434 // toggle visibility every 10 steps
3535 count ++;
3636 if (count == 10 ) {
37- count = 0 ;
3837 visible = !visible ;
38+ count = 0 ;
3939 }
4040 }
4141
Original file line number Diff line number Diff line change 55/**
66 * Specialization of Polygon that has a color and the ability to draw itself.
77 */
8- public class ColorPolygon extends Polygon implements Actor {
8+ public class DrawablePolygon extends Polygon implements Actor {
99
10- protected Color color ;
10+ public Color color ;
1111
1212 /**
1313 * Creates an empty polygon.
1414 */
15- public ColorPolygon () {
15+ public DrawablePolygon () {
1616 super ();
1717 color = Color .GRAY ;
1818 }
@@ -38,7 +38,7 @@ public void step() {
3838 * @param args command-line arguments
3939 */
4040 public static void main (String [] args ) {
41- ColorPolygon p = new ColorPolygon ();
41+ DrawablePolygon p = new DrawablePolygon ();
4242 p .addPoint (57 , 110 );
4343 p .addPoint (100 , 35 );
4444 p .addPoint (143 , 110 );
Original file line number Diff line number Diff line change @@ -25,10 +25,10 @@ public class Drawing extends Canvas {
2525 /**
2626 * Adds a new actor to the drawing.
2727 *
28- * @param cp the object to add
28+ * @param dp the object to add
2929 */
30- public void add(ColorPolygon cp ) {
31- list.add(cp );
30+ public void add(ColorPolygon dp ) {
31+ list.add(dp );
3232 }
3333
3434 /**
@@ -47,17 +47,17 @@ public class Drawing extends Canvas {
4747 */
4848 @Override
4949 public void paint(Graphics g) {
50- for (ColorPolygon cp : list) {
51- cp .draw(g);
50+ for (ColorPolygon dp : list) {
51+ dp .draw(g);
5252 }
5353 }
5454
5555 /**
5656 * Calls the step method of each actor and updates the drawing.
5757 */
5858 public void step() {
59- for (ColorPolygon cp : list) {
60- cp .step();
59+ for (ColorPolygon dp : list) {
60+ dp .step();
6161 }
6262 repaint();
6363 }
Original file line number Diff line number Diff line change 44 * A polygon that is equiangular (all angles are equal in measure) and
55 * equilateral (all sides have the same length). It also has a color.
66 */
7- public class RegularPolygon extends ColorPolygon {
7+ public class RegularPolygon extends DrawablePolygon {
88
99 public static final String [] NAMES = {null , null , null ,
1010 "Triangle" , "Square" , "Pentagon" , "Hexagon" ,
Original file line number Diff line number Diff line change @@ -14,9 +14,9 @@ public class Sim1 {
1414 public static void main (String [] args ) {
1515
1616 // create some regular polygons
17- ColorPolygon p1 = new RegularPolygon (3 , 50 , Color .GREEN );
18- ColorPolygon p2 = new RegularPolygon (6 , 50 , Color .ORANGE );
19- ColorPolygon p3 = new RegularPolygon (360 , 50 , Color .BLUE );
17+ DrawablePolygon p1 = new RegularPolygon (3 , 50 , Color .GREEN );
18+ DrawablePolygon p2 = new RegularPolygon (6 , 50 , Color .ORANGE );
19+ DrawablePolygon p3 = new RegularPolygon (360 , 50 , Color .BLUE );
2020
2121 // move them out of the corner
2222 p1 .translate (100 , 80 );
Original file line number Diff line number Diff line change 1212public class Sprite implements Actor , KeyListener {
1313
1414 private Image image ;
15-
1615 private int xpos ;
1716 private int ypos ;
1817 private int dx ;
@@ -26,10 +25,10 @@ public class Sprite implements Actor, KeyListener {
2625 * @param ypos initial Y coordinate
2726 */
2827 public Sprite (String path , int xpos , int ypos ) {
28+ this .xpos = xpos ;
29+ this .ypos = ypos ;
2930 try {
3031 this .image = ImageIO .read (new File (path ));
31- this .xpos = xpos ;
32- this .ypos = ypos ;
3332 } catch (IOException e ) {
3433 e .printStackTrace ();
3534 }
You can’t perform that action at this time.
0 commit comments