Permalink
Browse files

updated Editor and MouseHandler (not working yet)

  • Loading branch information...
1 parent c0ef4bf commit 98f2c5099eedcd3c234d62f42137be92c731333a @kmooren kmooren committed Jul 2, 2012
Showing with 96 additions and 12 deletions.
  1. +31 −3 src/game/MouseHandler.java
  2. +65 −9 src/level/Editor.java
@@ -1,34 +1,62 @@
package game;
+import java.awt.Container;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
-public class MouseHandler implements MouseListener {
+import level.Editor;
+/**
+ *
+ * @author kyra
+ *
+ */
+
+public class MouseHandler extends Editor implements MouseListener {
+
+ public MouseHandler(Container frame) {
+ super(frame);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * determine what happens if mouse is clicked
+ */
@Override
public void mouseClicked(MouseEvent arg0) {
- // TODO Auto-generated method stub
- // setComponent(arg0.getX(), arg0.getY());
+ this.setComponent(arg0.getX(), arg0.getY());
}
+ /**
+ * determine what happens if mouse enters field
+ */
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
+ /**
+ * determines what happens if mouse exits field
+ */
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
+ /**
+ * determines what happens if mouse is pressed
+ */
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
+ /**
+ * determines what happens if mouse is released
+ */
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
View
@@ -1,15 +1,19 @@
package level;
+import game.Game;
import game.Main;
import game.MouseHandler;
import graphics.Image;
import graphics.Sprite;
import java.awt.Canvas;
import java.awt.Container;
+import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.Scanner;
import javax.swing.JFileChooser;
@@ -71,13 +75,16 @@
*/
private JFrame editorframe;
- private int element;
+ protected int element;
private String filename;
private Image images[][];
+ private int position[][];
int x = 0, type, y = 0;
private Scanner maps;
+ private Container frame;
+ private Graphics g;
/**
* default constructor for Editor, sets frame and buttons
@@ -88,15 +95,14 @@ public Editor(Container frame) {
/**
* create new JFrame called "Leveleditor" and set properties
*/
-
JFrame editorframe = new JFrame("Leveleditor");
editorframe.setTitle("Leveleditor");
editorframe.setSize(500, 500);
editorframe.setLocationRelativeTo(frame);
editorframe.setVisible(true);
- MouseHandler mousehandler = new MouseHandler();
+ MouseHandler mousehandler = new MouseHandler(frame);
editorframe.addMouseListener(mousehandler);
/**
@@ -154,8 +160,6 @@ public Editor(Container frame) {
editorframe.setJMenuBar(this.menubar);
- this.loadMap("Map3");
-
}
/**
@@ -192,7 +196,7 @@ public void actionPerformed(ActionEvent arg0) {
int returnVal = fileChooser.showSaveDialog(this.editorframe);
if (returnVal == JFileChooser.APPROVE_OPTION) {
- // save file
+ this.saveMap();
}
// if "neu" is pressed, load default Map
@@ -262,8 +266,9 @@ public void loadMap(String filename) {
//
}
-
+ this.draw(this.g);
}
+
this.y++;
}
@@ -274,10 +279,10 @@ public void loadMap(String filename) {
}
public void setComponent(int x, int y) {
+
this.x = x;
this.y = y;
- // set position
if (this.element == 0) {
this.images = Sprite.load("background.png", 100, 100);
} else if (this.element == 1) {
@@ -289,10 +294,61 @@ public void setComponent(int x, int y) {
} else if (this.element == 4) {
this.images = Sprite.load("finish.png", 100, 100);
} else if (this.element == 5) {
- //
}
+ this.draw(this.g);
+ }
+
+ public void draw(Graphics g) {
+ g.drawImage((this.images[this.x][this.y]).image, this.x, this.y,
+ Game.BLOCK_SIZE, Game.BLOCK_SIZE, null);
+ }
+
+ /**
+ * Method to save Map
+ */
+ public void saveMap() {
+
+ int x = 0;
+ int y = 0;
+ try {
+ FileWriter fw = new FileWriter(this.getName() + ".txt");
+
+ while (y < Game.FIELD_HEIGHT) {
+ while (x < Game.FIELD_WIDTH) {
+
+ try {
+ if (this.images == Sprite.load("background.png", 100,
+ 100)) {
+ this.element = 0;
+ } else if (this.images == Sprite.load("w1.png", 100,
+ 100)) {
+ this.element = 1;
+ } else if (this.images == Sprite.load("wall.png", 100,
+ 100)) {
+ this.element = 2;
+ } else if (this.images == Sprite.load("bomberman.png",
+ 55, 90)) {
+ this.element = 3;
+ } else if (this.images == Sprite.load("finish.png",
+ 100, 100)) {
+ this.element = 4;
+ }
+
+ fw.write(this.element);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ x++;
+ }
+ y++;
+ }
+ fw.close();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
}

0 comments on commit 98f2c50

Please sign in to comment.