diff --git a/Technology/Game-2/bin/resources/missile.png b/Technology/Game-2/bin/resources/missile.png index 0a6428a..ab620f8 100644 Binary files a/Technology/Game-2/bin/resources/missile.png and b/Technology/Game-2/bin/resources/missile.png differ diff --git a/Technology/Game-2/bin/resources/spaceship.png b/Technology/Game-2/bin/resources/spaceship.png index 2e387ae..b412667 100644 Binary files a/Technology/Game-2/bin/resources/spaceship.png and b/Technology/Game-2/bin/resources/spaceship.png differ diff --git a/Technology/Game-2/src/Game/Missile.java b/Technology/Game-2/src/Game/Missile.java index 7e66dc8..1efb6a5 100644 --- a/Technology/Game-2/src/Game/Missile.java +++ b/Technology/Game-2/src/Game/Missile.java @@ -2,6 +2,7 @@ package Game; +//Inherit some methods shared with class SpaceShip public class Missile extends Sprite { private final int BOARD_WIDTH = 800; diff --git a/Technology/Game-2/src/Game/SpaceShip.java b/Technology/Game-2/src/Game/SpaceShip.java index dbf7e6d..7995e0e 100644 --- a/Technology/Game-2/src/Game/SpaceShip.java +++ b/Technology/Game-2/src/Game/SpaceShip.java @@ -6,6 +6,7 @@ import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.List; +// Inherit some methods shared with class Missile public class SpaceShip extends Sprite { private int dx; @@ -19,7 +20,6 @@ public class SpaceShip extends Sprite { } private void initSpaceShip() { - missiles = new ArrayList<>(); loadImage("src/resources/spaceship.png"); @@ -36,7 +36,6 @@ public class SpaceShip extends Sprite { } public void keyPressed(KeyEvent e) { - int key = e.getKeyCode(); if (key == KeyEvent.VK_SPACE) { @@ -65,7 +64,6 @@ public class SpaceShip extends Sprite { } public void keyReleased(KeyEvent e) { - int key = e.getKeyCode(); if (key == KeyEvent.VK_LEFT) { diff --git a/Technology/Game-2/src/Game/Sprite.java b/Technology/Game-2/src/Game/Sprite.java index e075744..cdadcc0 100644 --- a/Technology/Game-2/src/Game/Sprite.java +++ b/Technology/Game-2/src/Game/Sprite.java @@ -1,5 +1,11 @@ // Origin: https://zetcode.com/javagames/movingsprites/ +// SpaceShip and Missile have some methods in common. +// We can just as well have them inherit those methods + +// The protected modifier specifies that the member can only be accessed within its own package +// The private modifier specifies that the member can only be accessed within its own class. + package Game; import java.awt.Image; @@ -14,21 +20,19 @@ public class Sprite { protected boolean visible; protected Image image; + // Set the initial position public Sprite(int x, int y) { - this.x = x; this.y = y; visible = true; } protected void loadImage(String imageName) { - ImageIcon ii = new ImageIcon(imageName); image = ii.getImage(); } protected void getImageDimensions() { - width = image.getWidth(null); height = image.getHeight(null); } diff --git a/Technology/Game-3/src/Game/Missile.java b/Technology/Game-3/src/Game/Missile.java index 2ac79a0..a4ef51d 100644 --- a/Technology/Game-3/src/Game/Missile.java +++ b/Technology/Game-3/src/Game/Missile.java @@ -2,6 +2,7 @@ package Game; +//Inherit some methods shared with class SpaceShip public class Missile extends Sprite { private final int BOARD_WIDTH = 800; diff --git a/Technology/Game-3/src/Game/SpaceShip.java b/Technology/Game-3/src/Game/SpaceShip.java index dbf7e6d..d8ce098 100644 --- a/Technology/Game-3/src/Game/SpaceShip.java +++ b/Technology/Game-3/src/Game/SpaceShip.java @@ -6,6 +6,7 @@ import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.List; +//Inherit some methods shared with class Missile public class SpaceShip extends Sprite { private int dx; @@ -19,7 +20,6 @@ public class SpaceShip extends Sprite { } private void initSpaceShip() { - missiles = new ArrayList<>(); loadImage("src/resources/spaceship.png"); @@ -36,7 +36,6 @@ public class SpaceShip extends Sprite { } public void keyPressed(KeyEvent e) { - int key = e.getKeyCode(); if (key == KeyEvent.VK_SPACE) { @@ -65,7 +64,6 @@ public class SpaceShip extends Sprite { } public void keyReleased(KeyEvent e) { - int key = e.getKeyCode(); if (key == KeyEvent.VK_LEFT) { diff --git a/Technology/Game-3/src/Game/Sprite.java b/Technology/Game-3/src/Game/Sprite.java index b266a5c..8891823 100644 --- a/Technology/Game-3/src/Game/Sprite.java +++ b/Technology/Game-3/src/Game/Sprite.java @@ -1,5 +1,11 @@ // Origin: https://zetcode.com/javagames/movingsprites/ +// SpaceShip and Missile have some methods in common. +// We can just as well have them inherit those methods + +// The protected modifier specifies that the member can only be accessed within its own package +// The private modifier specifies that the member can only be accessed within its own class. + package Game; import java.awt.Image;