From 65e7d1ffc5d9ebe0110be587675e4d1840ca9efd Mon Sep 17 00:00:00 2001 From: Eyal Minsky-Fenick Date: Fri, 26 Feb 2016 14:41:44 -0500 Subject: [PATCH] Fixed a heck of a lot of stupid bits. Also a lot of critique. --- src/images/Shipinter.java | 46 +++++++------ src/main/Game.java | 140 +++++++++++++++++++------------------- src/main/Main.java | 21 +++--- src/ship/PlayerShip.java | 7 ++ src/ship/Playership.java | 5 -- src/ship/ship.java | 25 ++++--- 6 files changed, 130 insertions(+), 114 deletions(-) create mode 100644 src/ship/PlayerShip.java delete mode 100644 src/ship/Playership.java diff --git a/src/images/Shipinter.java b/src/images/Shipinter.java index 1027eb6..54070b2 100644 --- a/src/images/Shipinter.java +++ b/src/images/Shipinter.java @@ -1,21 +1,25 @@ -package images; - -import java.awt.Image; - -public class Shipinter { - Image image; - public Shipinter(Image shipID){ - this.image = shipID; - } - //added a method to retrieve the size of the ship, so it can be drawn onto the actual game. - //the Size is stored in an array where [1] is the width and [2] is the height - //it can be used for both player ships and enemy ships - public int[] getsize(){ - int[] shipsize; - shipsize = new int[2]; - shipsize[1] = image.getWidth(null); - shipsize[2] = image.getHeight(null); - return shipsize; - } - -} +package images; + +import java.awt.Image; +// The fuck does shipinter stand for? +// Also, don't forget to PascalCase class names. +// I won't fix this one. +public class Shipinter { + Image image; + public Shipinter(Image shipID){ + this.image = shipID; + } + // WHY IS THE IMAGE PARAMETER CALLED SHIPID? + //added a method to retrieve the size of the ship, so it can be drawn onto the actual game. + // You'll need to have a method to either get the image or to draw it-Eyal + //the Size is stored in an array where [1] is the width and [2] is the height + //it can be used for both player ships and enemy ships + public int[] getsize(){ + int[] shipsize; + shipsize = new int[2]; + shipsize[1] = image.getWidth(null); + shipsize[2] = image.getHeight(null); + return shipsize; + } + +} diff --git a/src/main/Game.java b/src/main/Game.java index c029641..37eacec 100644 --- a/src/main/Game.java +++ b/src/main/Game.java @@ -1,70 +1,70 @@ -package main; - - - -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.image.BufferStrategy; - - - - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; - -public class Game implements ActionListener { - BufferStrategy strategy; - public Game(){ - JFrame container = new JFrame("CSE 2102"); - container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - JPanel panel = (JPanel) container.getContentPane(); - panel.setPreferredSize(new Dimension(800,600)); - panel.setLayout(null); - - panel.setBounds(0,0,800,600); - - panel.setIgnoreRepaint(true); - - JMenuBar jmenubar = new JMenuBar(); - - JMenu jmGameOptions = new JMenu("Game"); - - JMenuItem jmiOpen = new JMenuItem("Open"); - jmGameOptions.add(jmiOpen); - jmiOpen.addActionListener(this); - - JMenuItem jmiClose = new JMenuItem("Close"); - jmGameOptions.add(jmiClose); - jmiClose.addActionListener(this); - - JMenuItem jmiSave = new JMenuItem("Save"); - jmGameOptions.add(jmiSave); - jmiSave.addActionListener(this); - - JMenuItem jmiExit = new JMenuItem("Exit"); - jmGameOptions.add(jmiExit); - jmiExit.addActionListener(this); - - jmenubar.add(jmGameOptions); - - - container.setJMenuBar(jmenubar); - container.setVisible(true); - - - - container.pack(); - container.setResizable(false); - - - } - public void actionPerformed(ActionEvent ae) { - String comStr = ae.getActionCommand(); - System.out.println(comStr + " Selected"); - } -} +package main; + + + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.image.BufferStrategy; + + + + +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; + +public class Game implements ActionListener { + BufferStrategy strategy; + public Game() { + JFrame container = new JFrame("CSE 2102"); + container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPanel panel = (JPanel) container.getContentPane(); + panel.setPreferredSize(new Dimension(800,600)); + panel.setLayout(null); + + panel.setBounds(0,0,800,600); + + panel.setIgnoreRepaint(true); + + JMenuBar jmenubar = new JMenuBar(); + + JMenu jmGameOptions = new JMenu("Game"); + + JMenuItem jmiOpen = new JMenuItem("Open"); + jmGameOptions.add(jmiOpen); + jmiOpen.addActionListener(this); + + JMenuItem jmiClose = new JMenuItem("Close"); + jmGameOptions.add(jmiClose); + jmiClose.addActionListener(this); + + JMenuItem jmiSave = new JMenuItem("Save"); + jmGameOptions.add(jmiSave); + jmiSave.addActionListener(this); + + JMenuItem jmiExit = new JMenuItem("Exit"); + jmGameOptions.add(jmiExit); + jmiExit.addActionListener(this); + + jmenubar.add(jmGameOptions); + + + container.setJMenuBar(jmenubar); + container.setVisible(true); + + + + container.pack(); + container.setResizable(false); + + + } + public void actionPerformed(ActionEvent ae) { + String comStr = ae.getActionCommand(); + System.out.println(comStr + " Selected"); + } +} diff --git a/src/main/Main.java b/src/main/Main.java index 834aaea..2b8058b 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -1,10 +1,11 @@ -package main; - -import java.awt.Dimension; - -import javax.swing.*; -public class Main extends JFrame{ - public static void main(String[] args){ - new Game(); -} -} +package main; + +import java.awt.Dimension; +// I think it's ugly to have two separate classes. Just have one class. +// I won't change this, though. +import javax.swing.*; +public class Main extends JFrame{ + public static void main(String[] args){ + new Game(); + } +} diff --git a/src/ship/PlayerShip.java b/src/ship/PlayerShip.java new file mode 100644 index 0000000..b79e65c --- /dev/null +++ b/src/ship/PlayerShip.java @@ -0,0 +1,7 @@ +package ship; + +public class PlayerShip extends ship{ + public void move() {} // WHY ISN'T THIS IN SHIP? + // MAYBE SHIP SHOULD BE AN INTERFACE? + // ALSO ABSTRACT METHODS ARE BANNED FROM CONCRETE CLASSES. +} diff --git a/src/ship/Playership.java b/src/ship/Playership.java deleted file mode 100644 index bf7fee9..0000000 --- a/src/ship/Playership.java +++ /dev/null @@ -1,5 +0,0 @@ -package ship; - -public class Playership extends ship{ - public void abstract move(); -} diff --git a/src/ship/ship.java b/src/ship/ship.java index 5f6998d..f368575 100644 --- a/src/ship/ship.java +++ b/src/ship/ship.java @@ -1,8 +1,17 @@ -package ship; - -public class ship { - static int posx; - static int posy; - - -} +package ship; + +/* +NO +NO +NO +NO +NO +NO +EACH SHIP SHOULD HAVE ITS OWN POSITION. +(also, it doesn't hurt to keep positions as doubles and round them) + */ + +public class ship { + static int posx; + static int posy; +}