From 83f39598ba29e833d7c4caef5149850691f90e8b Mon Sep 17 00:00:00 2001 From: jdm13003 Date: Fri, 26 Feb 2016 14:21:45 -0500 Subject: [PATCH] My Laptop is dying so I am going to push this. I have added a menu to the main screen along with buttons, they dont really do anything though. I have also added a method for retrieving the size of the ship images and storing it in an array --- .classpath | 1 + src/images/Shipinter.java | 21 ++++++++++++++ src/main/Game.java | 58 +++++++++++++++++++++++++++++++++++++-- src/main/Main.java | 13 ++------- src/ship/ship.java | 2 +- 5 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 src/images/Shipinter.java diff --git a/.classpath b/.classpath index d171cd4..1925a4d 100644 --- a/.classpath +++ b/.classpath @@ -2,5 +2,6 @@ + diff --git a/src/images/Shipinter.java b/src/images/Shipinter.java new file mode 100644 index 0000000..1027eb6 --- /dev/null +++ b/src/images/Shipinter.java @@ -0,0 +1,21 @@ +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; + } + +} diff --git a/src/main/Game.java b/src/main/Game.java index 2e40678..c029641 100644 --- a/src/main/Game.java +++ b/src/main/Game.java @@ -1,18 +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 { +public class Game implements ActionListener { + BufferStrategy strategy; public Game(){ - JFrame container = new JFrame("Padraic"); + 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); - setIgnoreRepaint(true); + + 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 d3568ce..834aaea 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -5,15 +5,6 @@ import java.awt.Dimension; import javax.swing.*; public class Main extends JFrame{ public static void main(String[] args){ - new Game(); - } - public void Game(){ - JFrame container = new JFrame("Padraic"); - JPanel panel = (JPanel) container.getContentPane(); - Dimension D = new Dimension(800,600); - panel.setPreferredSize(new Dimension(800,600)); - - - } - + new Game(); +} } diff --git a/src/ship/ship.java b/src/ship/ship.java index 19c68d9..5f6998d 100644 --- a/src/ship/ship.java +++ b/src/ship/ship.java @@ -3,6 +3,6 @@ package ship; public class ship { static int posx; static int posy; - static int health; + }