diff --git a/.classpath b/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..74f62e7d30042151cf9384b63c45f203b3a0288c --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="res"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/.project b/.project new file mode 100644 index 0000000000000000000000000000000000000000..86872b1b40a5e0ecd3e890ca4c34422d4dfffd77 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>MazeGame</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/bin/GameFrame.class b/bin/GameFrame.class new file mode 100644 index 0000000000000000000000000000000000000000..7ddad53284790d0e768677b4b4d4c385702466ec Binary files /dev/null and b/bin/GameFrame.class differ diff --git a/bin/GamePanel.class b/bin/GamePanel.class new file mode 100644 index 0000000000000000000000000000000000000000..f97b802e1acc2a824a8fe6aa934476c6883e1644 Binary files /dev/null and b/bin/GamePanel.class differ diff --git a/bin/Main.class b/bin/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..fe4dcc691dedccd7463f01b4e0ba6bd0eb82d839 Binary files /dev/null and b/bin/Main.class differ diff --git a/bin/ReadFile.class b/bin/ReadFile.class new file mode 100644 index 0000000000000000000000000000000000000000..e7ab8f9608e4e81c3c5c16f156bc9309c428c037 Binary files /dev/null and b/bin/ReadFile.class differ diff --git a/bin/Walls.class b/bin/Walls.class new file mode 100644 index 0000000000000000000000000000000000000000..2fc35d2197f20890fe5155e7b6f4c008e56a08c5 Binary files /dev/null and b/bin/Walls.class differ diff --git a/bin/ggwp.png b/bin/ggwp.png new file mode 100644 index 0000000000000000000000000000000000000000..ee41f582dc6ee5ad4bfacc21daec4b79b1c42bfb Binary files /dev/null and b/bin/ggwp.png differ diff --git a/bin/walls1.txt b/bin/walls1.txt new file mode 100644 index 0000000000000000000000000000000000000000..5070330f64ae6a2ec07100a7b82d75f549e22f65 --- /dev/null +++ b/bin/walls1.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +gggggggggggggggw +gggggggggggggggw +gggggggggggggggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwwggw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw \ No newline at end of file diff --git a/bin/walls2.txt b/bin/walls2.txt new file mode 100644 index 0000000000000000000000000000000000000000..24c9985441ad766fd6f0f4a356b701c6875d968e --- /dev/null +++ b/bin/walls2.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggwwwwwwwwwwwwww +wgggggwwwwwwwwww +wwwwwgwwwwwwwwww +wwwwwgggwwwwwwww +wwwwwwwgwwwwwwww +wwwwwwwgwwwwwwww +wwwwwwwgwwwwwwww +wwwwwwwgwwgggwww +wwwwwwwgwwgwgwww +wwwwwwwggggwgwww +wwwwwwwwwwwwgggw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw \ No newline at end of file diff --git a/bin/walls3.txt b/bin/walls3.txt new file mode 100644 index 0000000000000000000000000000000000000000..d1ab37d340ac87412b383cbcb1f6f558f3789e98 --- /dev/null +++ b/bin/walls3.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggwggggwwwgggwww +wgggwwgggwgwgggw +wwwwwwwwgggwwwgw +wwwwwwwwwwwwgggw +wwwwwwwggggwgwww +wwwwwwwgwwgggwww +wwggggggwwwwwwww +wwgwgwwwwwwwwwww +wwgggwwwwwwwwwww +wwwgwwwggggwwwww +wgggwwwgwwgwgggw +wgwwwwwgwwgwgwgw +wgggwwggwwgwgwgw +wwwggggwwwgggwgw +wwwwwwwwwwwwwwgg \ No newline at end of file diff --git a/bin/walls4.txt b/bin/walls4.txt new file mode 100644 index 0000000000000000000000000000000000000000..e590dddf7acfcb3dd2ed6cbe95099a46f64250fe --- /dev/null +++ b/bin/walls4.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggggwwwwwwwwwwww +wwwgwwgggwwwwwww +wwwgwwgwggwwwwww +wwwgwwgwwgwwwwww +wwwggggwwgwwwwww +wwwwwwwwwgwwwwww +wwwwwwwwwgwwwwww +wwwwwwggggwwwwww +wwwwwwgwwwwwwwww +wwwwwwgggwwwwwww +wwwwwwwwgwwwwwww +wwwwwwwwgwwwwwww +wwwwwwwwgggggggw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw \ No newline at end of file diff --git a/bin/walls5.txt b/bin/walls5.txt new file mode 100644 index 0000000000000000000000000000000000000000..65ab082ca0fd2685e8d4410a2032167efa24d37b --- /dev/null +++ b/bin/walls5.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggggwgggwgggwwww +wwwgwgwgwgwgwwww +wwwgwgwgwgwgwwww +wgggwgwgwgwgwwww +wgwwwgwgwgwgwwww +wgggggwgwgwgwwww +wwwwwwwgwgwgwwww +wgggggggwgwgwwww +wgwwwwwwwgwgwwww +wgggggggggwgwwww +wwwwwwwwwwwgwwww +wgggggggggggwwww +wgwwwwwwwwwwwwww +wggggggggggggggw +wwwwwwwwwwwwwwgw \ No newline at end of file diff --git a/bin/walls6.txt b/bin/walls6.txt new file mode 100644 index 0000000000000000000000000000000000000000..cb32e5ee8d94c804b64abbb59005437d6209846a --- /dev/null +++ b/bin/walls6.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggwwwgggggggggww +wgwwggwwwwwwwgww +wgwggwwgggwgggww +wgwgwwggwgggwwww +ggwggwgwwwwwwwww +gwwwgwggggggggww +gwwggwwwwwwwwggw +ggwgwwwwwwwwwwgw +wgwggwgggggggggw +ggwwgwgwwwwwwwww +gwwggwgggggggggw +ggwgwwwwwwwwwwgw +wgwgwwgggggggggw +wgggwwgwwwwwwwww +wwwwwwgggggggggw diff --git a/res/ggwp.png b/res/ggwp.png new file mode 100644 index 0000000000000000000000000000000000000000..ee41f582dc6ee5ad4bfacc21daec4b79b1c42bfb Binary files /dev/null and b/res/ggwp.png differ diff --git a/res/walls1.txt b/res/walls1.txt new file mode 100644 index 0000000000000000000000000000000000000000..5070330f64ae6a2ec07100a7b82d75f549e22f65 --- /dev/null +++ b/res/walls1.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +gggggggggggggggw +gggggggggggggggw +gggggggggggggggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwgggw +wwwwwwwwwwwwwggw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw \ No newline at end of file diff --git a/res/walls2.txt b/res/walls2.txt new file mode 100644 index 0000000000000000000000000000000000000000..24c9985441ad766fd6f0f4a356b701c6875d968e --- /dev/null +++ b/res/walls2.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggwwwwwwwwwwwwww +wgggggwwwwwwwwww +wwwwwgwwwwwwwwww +wwwwwgggwwwwwwww +wwwwwwwgwwwwwwww +wwwwwwwgwwwwwwww +wwwwwwwgwwwwwwww +wwwwwwwgwwgggwww +wwwwwwwgwwgwgwww +wwwwwwwggggwgwww +wwwwwwwwwwwwgggw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw \ No newline at end of file diff --git a/res/walls3.txt b/res/walls3.txt new file mode 100644 index 0000000000000000000000000000000000000000..d1ab37d340ac87412b383cbcb1f6f558f3789e98 --- /dev/null +++ b/res/walls3.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggwggggwwwgggwww +wgggwwgggwgwgggw +wwwwwwwwgggwwwgw +wwwwwwwwwwwwgggw +wwwwwwwggggwgwww +wwwwwwwgwwgggwww +wwggggggwwwwwwww +wwgwgwwwwwwwwwww +wwgggwwwwwwwwwww +wwwgwwwggggwwwww +wgggwwwgwwgwgggw +wgwwwwwgwwgwgwgw +wgggwwggwwgwgwgw +wwwggggwwwgggwgw +wwwwwwwwwwwwwwgg \ No newline at end of file diff --git a/res/walls4.txt b/res/walls4.txt new file mode 100644 index 0000000000000000000000000000000000000000..e590dddf7acfcb3dd2ed6cbe95099a46f64250fe --- /dev/null +++ b/res/walls4.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggggwwwwwwwwwwww +wwwgwwgggwwwwwww +wwwgwwgwggwwwwww +wwwgwwgwwgwwwwww +wwwggggwwgwwwwww +wwwwwwwwwgwwwwww +wwwwwwwwwgwwwwww +wwwwwwggggwwwwww +wwwwwwgwwwwwwwww +wwwwwwgggwwwwwww +wwwwwwwwgwwwwwww +wwwwwwwwgwwwwwww +wwwwwwwwgggggggw +wwwwwwwwwwwwwwgw +wwwwwwwwwwwwwwgw \ No newline at end of file diff --git a/res/walls5.txt b/res/walls5.txt new file mode 100644 index 0000000000000000000000000000000000000000..65ab082ca0fd2685e8d4410a2032167efa24d37b --- /dev/null +++ b/res/walls5.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggggwgggwgggwwww +wwwgwgwgwgwgwwww +wwwgwgwgwgwgwwww +wgggwgwgwgwgwwww +wgwwwgwgwgwgwwww +wgggggwgwgwgwwww +wwwwwwwgwgwgwwww +wgggggggwgwgwwww +wgwwwwwwwgwgwwww +wgggggggggwgwwww +wwwwwwwwwwwgwwww +wgggggggggggwwww +wgwwwwwwwwwwwwww +wggggggggggggggw +wwwwwwwwwwwwwwgw \ No newline at end of file diff --git a/res/walls6.txt b/res/walls6.txt new file mode 100644 index 0000000000000000000000000000000000000000..773c783e653f6fe54da66d28d0fb8d30a5d6c028 --- /dev/null +++ b/res/walls6.txt @@ -0,0 +1,16 @@ +gwwwwwwwwwwwwwww +ggwwwgggggggggww +wgwwggwwwwwwwgww +wgwggwwgggwgggww +wgwgwwggwgggwwww +ggwggwgwwwwwwwww +gwwwgwggggggggww +gwwggwwwwwwwwggw +ggwgwwwwwwwwwwgw +wgwggwgggggggggw +ggwwgwgwwwwwwwww +gwwggwgggggggggw +ggwgwwwwwwwwwwgw +wgwgwwgggggggggw +wgggwwgwwwwwwwww +wwwwwwgggggggggw \ No newline at end of file diff --git a/src/GameFrame.java b/src/GameFrame.java index 68b715daf4c5029f53dc6cfb7a64f62ff24511a8..cf333e9f99fbb9f1da2eebc04055c2af5f505148 100644 --- a/src/GameFrame.java +++ b/src/GameFrame.java @@ -11,6 +11,9 @@ public class GameFrame extends JFrame implements ActionListener { JPanel start; JButton resetButton; JButton startGame; + JButton nextMap; + JButton previousMap; + int mapN = 1; public GameFrame(int width, int height, String title) { @@ -20,52 +23,83 @@ public class GameFrame extends JFrame implements ActionListener { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); - resetButton = new JButton(); resetButton.setText("Reset"); - resetButton.setSize(100,30); + resetButton.setSize(100, 30); resetButton.addActionListener(this); resetButton.setFocusable(false); startGame = new JButton(); startGame.setText("Start"); - startGame.setSize(200,200); - startGame.setLocation(250,250); startGame.addActionListener(this); startGame.setFocusable(false); + nextMap = new JButton(); + nextMap.setText("Next Map"); + nextMap.addActionListener(this); + nextMap.setFocusable(false); + + previousMap = new JButton(); + previousMap.setText("Previous Map"); + previousMap.addActionListener(this); + previousMap.setFocusable(false); + score = new JPanel(); score.setBackground(Color.black); + score.add(previousMap); score.add(resetButton); + score.add(nextMap); score.setFocusable(true); start = new JPanel(); start.setBackground(Color.black); - start.setSize(getWidth(),getHeight()); - start.setLocation(0,0); - start.add(startGame); - + start.setSize(getWidth(), getHeight()); + start.setLocation(0, 0); + start.add(startGame, BorderLayout.CENTER); this.add(start); this.setVisible(true); + } @Override public void actionPerformed(ActionEvent e) { - if(e.getSource() == resetButton){ + if (e.getSource() == resetButton) { this.remove(game); - game = new GamePanel(); + game = new GamePanel(mapN); this.add(game); SwingUtilities.updateComponentTreeUI(this); game.requestFocus(); } - if(e.getSource() == startGame){ + if (e.getSource() == startGame) { this.remove(start); - game = new GamePanel(); - this.add(score,BorderLayout.NORTH); + mapN = 1; + game = new GamePanel(mapN); + this.add(score, BorderLayout.NORTH); this.add(game); SwingUtilities.updateComponentTreeUI(this); game.requestFocus(); } + if (e.getSource() == nextMap) { + if (mapN < 6) { + this.remove(game); + mapN++; + game = new GamePanel(mapN); + this.add(game); + SwingUtilities.updateComponentTreeUI(this); + game.requestFocus(); + } + + } + if (e.getSource() == previousMap) { + if (mapN >= 1) { + this.remove(game); + mapN--; + game = new GamePanel(mapN); + this.add(game); + SwingUtilities.updateComponentTreeUI(this); + game.requestFocus(); + } + } } } diff --git a/src/GameObject.java b/src/GameObject.java deleted file mode 100644 index fe33303516c33875a89a0c9b7661562bb073e5c9..0000000000000000000000000000000000000000 --- a/src/GameObject.java +++ /dev/null @@ -1,19 +0,0 @@ -import java.awt.*; -import java.awt.event.*; - -public class GameObject extends Rectangle{ - - Color color; - - GameObject(int x, int y, int width, int height, Color color){ - this.x=x; - this.y=y; - this.width=width; - this.height=height; - this.color=color; - } - public void draw(Graphics g) { - g.setColor(this.color); - g.fillRect(this.x, this.y, this.width, this.height); - } -} diff --git a/src/GamePanel.java b/src/GamePanel.java index 364208a64c1ec59f132f4607baa8e35d295872e0..7ce88365d528e31b19c4fa135c874e84d442f935 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -4,79 +4,81 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; -import java.util.concurrent.TimeUnit; public class GamePanel extends JPanel implements ActionListener, KeyListener { private static final long serialVersionUID = 1L; + ImageIcon ggwp; + ImageIcon ground; + ImageIcon steve; Timer timer = new Timer(5, this); - int x = 0, y = 0, velX = 0, velY = 0, veldX = 0, veldY = 0; - int playerSize = 22; + int x = 10, y = 10, velX = 0, velY = 0, veldX = 0, veldY = 0; + int playerSize = 27; int movmentSpeed = 4; int faildRounds; - ImageIcon ggwp; - - private Walls finishWall; private Walls walls; - private boolean play = true; + private boolean running; + private boolean nextMap = false; - public GamePanel() { + public GamePanel(int mapN) { timer.start(); addKeyListener(this); setFocusable(true); setFocusTraversalKeysEnabled(false); - walls = new Walls(); - ggwp = new ImageIcon("res\\ggwp.png"); - this.setSize(817,840); - this.setLocation(100,0); + running = true; + walls = new Walls(mapN); + ggwp = new ImageIcon(getClass().getClassLoader().getResource("ggwp.png")); + this.setSize(817, 840); + this.setLocation(100, 0); this.requestFocus(true); + } public void paintComponent(Graphics g) { super.paintComponent(g); - g.setColor(Color.black); - g.fillRect(0,0,getWidth(),getWidth()); + // Background; + g.setColor(Color.cyan); + g.fillRect(0, 0, getWidth(), getWidth()); - //Walls - walls.draw(this,g); + // Walls + walls.draw(this, g); - //Player - if(play) { - g.setColor(Color.red); - g.fillOval(x, y, playerSize, playerSize); + // Player + if (running) { + g.setColor(Color.blue); + g.fillRect(x, y, playerSize, playerSize); } - if(walls.wallsCollision(x,y,playerSize,playerSize)){ - x = 0; - y=0; + if (walls.wallsCollision(x, y, playerSize, playerSize)) { + x = 10; + y = 10; } - if(walls.finishWallsCollision(x,y,playerSize,playerSize)){ - play=false; + if (walls.finishWallsCollision(x, y, playerSize, playerSize)) { + running = false; } - if(!play) { - gameOver(g); + if (!running) { + RoundFinishe(g); } } - public void gameOver(Graphics g) { - if(!play){ + public void RoundFinishe(Graphics g) { + if (!running) { g.setColor(Color.black); - g.fillRect(0,0,getWidth(),getHeight()); - ggwp.paintIcon(this,g,280,250); + g.fillRect(0, 0, getWidth(), getHeight()); + ggwp.paintIcon(this, g, 280, 250); faildRounds++; + nextMap = true; + } } - public int getFailedRounds(){ - return faildRounds; - } @Override public void keyPressed(KeyEvent e) { int c = e.getKeyCode(); - if(play) { + if (running) { if (c == KeyEvent.VK_LEFT || c == KeyEvent.VK_A) veldX = -movmentSpeed; if (c == KeyEvent.VK_RIGHT || c == KeyEvent.VK_D) @@ -92,7 +94,7 @@ public class GamePanel extends JPanel implements ActionListener, KeyListener { @Override public void keyReleased(KeyEvent e) { int c = e.getKeyCode(); - if(play) { + if (running) { if (c == KeyEvent.VK_LEFT || c == KeyEvent.VK_A) veldX = 0; if (c == KeyEvent.VK_RIGHT || c == KeyEvent.VK_D) diff --git a/src/ReadFile.java b/src/ReadFile.java new file mode 100644 index 0000000000000000000000000000000000000000..4b57897819037cecac3badb92e24eff469e4f8f1 --- /dev/null +++ b/src/ReadFile.java @@ -0,0 +1,65 @@ +import java.io.File; +import java.util.Scanner; + +public class ReadFile { + private Scanner scanner; + public int col = 1; + String[] map = new String[16]; + + public void openFile(int mapN) { + if (mapN == 1) { + try { + scanner = new Scanner(getClass().getClassLoader().getResourceAsStream("walls1.txt")); + } catch (Exception e) { + System.out.println("could not find File"); + } + } else if (mapN == 2) { + try { + scanner = new Scanner(getClass().getClassLoader().getResourceAsStream("walls2.txt")); + } catch (Exception e) { + System.out.println("could not find File"); + } + } else if (mapN == 3) { + try { + scanner = new Scanner(getClass().getClassLoader().getResourceAsStream("walls3.txt")); + } catch (Exception e) { + System.out.println("could not find File"); + } + } else if (mapN == 4) { + try { + scanner = new Scanner(getClass().getClassLoader().getResourceAsStream("walls4.txt")); + } catch (Exception e) { + System.out.println("could not find File"); + } + } else if (mapN == 5) { + try { + scanner = new Scanner(getClass().getClassLoader().getResourceAsStream("walls5.txt")); + } catch (Exception e) { + System.out.println("could not find File"); + } + } else if (mapN == 6) { + try { + scanner = new Scanner(getClass().getClassLoader().getResourceAsStream("walls6.txt")); + } catch (Exception e) { + System.out.println("could not find File"); + } + } + } + + public String getTile(int x, int y) { + String index = map[y].substring(x, x + 1); + return index; + } + + public void readFile() { + while (scanner.hasNext()) { + for (int i = 0; i < 16; i++) { + map[i] = scanner.next(); + } + } + } + + public void closeFile() { + scanner.close(); + } +} \ No newline at end of file diff --git a/src/Walls.java b/src/Walls.java index 6596f44942067a574cf3786212643ca951248a8c..5ede959961b8423e3e87e9e37f6a986bd08383fa 100644 --- a/src/Walls.java +++ b/src/Walls.java @@ -1,119 +1,73 @@ import java.awt.*; +import java.util.Scanner; public class Walls { public int unit_size = 50; - int[] wallXPos = { - //upper wall - 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 - //left wall - ,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - //down wall - 1,2,3,4,5,6,7,8,9,10,11,12,13, - //right wall - 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, - //rest - 1,1,1,1, - 2,2,2,2, - 3,3,3,3,3, - 4,4,4,4,4,4, - 5,5,5,5,5,5,5,5,5, - 6,6,6,6, - 7,7,7,7,7,7,7, - 8,8,8,8,8,8, - 9,9,9,9,9,9,9,9, - 10,10,10,10,10, - 11,11,11,11,11,11,11, - 12,12,12,12, - 13,13,13, - 14,14,14 + private Scanner scanner; + private String Map[] = new String[16]; + ReadFile r = new ReadFile(); - }; - int[] wallYPos = { - //upper wall - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - //left wall - 2,3,4,5,6,7,8,9,10,11,12,13,14,15, - //down wall - 15,15,15,15,15,15,15,15,15,15,15,15,15, - //right wall - 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, - //rest - //1 - 3,8,9,12, - //2 - 1,3,6,12, - //3 - 3,6,7,10,14, - //4 - 2,3,7,8,10,12, - //5 - 2,3,4,8,9,10,11,12,13, - //6 - 4,8,9,13, - //7 - 1,2,4,6,7,8,11, - //8 - 4,8,11,12,13,14, - //9 - 1,2,4,5,6,8,10,11, - //10 - 1,4,8,11,13, - //11 - 4,6,7,8,9,11,13, - //12 - 8,11,13,4, - //13 - 8,11,13, - //14 - 3,8,13 - }; + int[][] walls = new int[16][17]; + public Walls(int mapN) { + r.openFile(mapN); + r.readFile(); + r.closeFile(); - public Walls() { + for (int y = 0; y < 16; y++) { + for (int x = 0; x < 16; x++) { + if (r.getTile(x, y).equals("w")) { + walls[y][x] = 1; + } + if (r.getTile(x, y).equals("g")) { + walls[y][x] = 0; + } + } + } } - public void draw(Component c, Graphics g) { - for(int i=0; i< wallXPos.length;i++) - { - g.setColor(Color.GRAY); - g.fillRect(wallXPos[i]*unit_size,wallYPos[i]*unit_size,unit_size,unit_size); + for (int i = 0; i < walls.length; i++) { + for (int j = 0; j < walls.length; j++) { + if (walls[i][j] == 1) { + g.setColor(Color.black); + g.fillRect(j * unit_size, i * unit_size, unit_size, unit_size); + } } - g.setColor(Color.yellow); - g.fillRect(14*unit_size,15*unit_size,2*unit_size,unit_size); + } + g.setColor(Color.red); + g.fillRect(14 * unit_size, 15 * unit_size, 2 * unit_size, unit_size); + } - public boolean wallsCollision(int x, int y,int width,int height) - { + public boolean wallsCollision(int x, int y, int width, int height) { boolean collided = false; - for(int i=0; i< wallXPos.length;i++) - { - if(new Rectangle(x, y, width, height).intersects(new Rectangle(wallXPos[i]*unit_size, wallYPos[i]*unit_size, 50, 50))) - { - collided = true; - break; + for (int i = 0; i < walls.length; i++) { + for (int j = 0; j < walls.length; j++) { + if (walls[i][j] == 1) { + if (new Rectangle(x, y, width, height) + .intersects(new Rectangle(j * unit_size, i * unit_size, 50, 50))) { + collided = true; + break; + } + } } } return collided; } - public boolean finishWallsCollision(int x, int y,int width,int height) - { + public boolean finishWallsCollision(int x, int y, int width, int height) { boolean finishCollided = false; - if(new Rectangle(x, y, width, height).intersects(new Rectangle(14*unit_size, 15*unit_size, 50, 50))) - { - finishCollided = true; - } + if (new Rectangle(x, y, width, height) + .intersects(new Rectangle(14 * unit_size, 15 * unit_size, 2 * unit_size, unit_size))) { + finishCollided = true; + } return finishCollided; } - - - - }