From 202b4f03947763b2948c71d79d2c019953579389 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Tue, 19 Dec 2017 21:13:17 +0100 Subject: [PATCH] Final release --- README.md | 9 ++-- .../maze/controller/Controller.java | 8 +++ src/be/dylanvanassche/maze/model/Maze.java | 13 +++-- .../dylanvanassche/maze/view/MainFrame.java | 13 ++++- src/be/dylanvanassche/maze/view/MazeView.java | 8 +-- src/be/dylanvanassche/maze/view/MenuBar.java | 53 ++++++++++++++++--- .../dylanvanassche/maze/view/SquareView.java | 5 -- .../maze/view/SquareViewElement.java | 9 ++-- 8 files changed, 89 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 2a31229..35c81d6 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,15 @@ A simple maze game written in Java following the MVC principles. ## Features - MVC principles written in Java - Find the gold in the maze -- Full GUI -- Player name +- Full GUI with basic icons +- Customize the name of the player +- Key navigation (ALT + arrow keys) +- Generate a maze with a different size (2x2, 4x4 or 8x8) +- Scrollbars if the maze is too big for the screen ## To do - Backtracking algorithm to generate a solvable maze. -- Key bindings for the navigation of the player. +- Implement a real key listener for key navigation. ## Screenshots ![screenshot1](/docs/java-maze.png) diff --git a/src/be/dylanvanassche/maze/controller/Controller.java b/src/be/dylanvanassche/maze/controller/Controller.java index 712f532..cd7d9dc 100644 --- a/src/be/dylanvanassche/maze/controller/Controller.java +++ b/src/be/dylanvanassche/maze/controller/Controller.java @@ -90,4 +90,12 @@ public void movePlayer(MovementType movement) throws UnknownMovementDirection, B public void setPlayerName(String name) { this.getMaze().getPlayer().setName(name); } + + public void setMazeSize(int size) { + Maze.setMazeSize(size); + } + + public int getMazeSize() { + return Maze.getMazeSize(); + } } diff --git a/src/be/dylanvanassche/maze/model/Maze.java b/src/be/dylanvanassche/maze/model/Maze.java index 7768c16..aff4f6c 100644 --- a/src/be/dylanvanassche/maze/model/Maze.java +++ b/src/be/dylanvanassche/maze/model/Maze.java @@ -2,7 +2,7 @@ package be.dylanvanassche.maze.model; public class Maze { - public static final int mazeSize = 2; // define n + public static int mazeSize = 2; // define n public static final int tileSize = 3; private int currentTileIndex = 0; private int currentTileIndexRow = 0; @@ -49,6 +49,14 @@ public Tile[][] getTiles() { public void setTiles(Tile[][] tiles) { this.tiles = tiles; } + + public static int getMazeSize() { + return mazeSize; + } + + public static void setMazeSize(int mazeSize) { + Maze.mazeSize = mazeSize; + } /* * @brief: constructs a new random Maze @@ -68,7 +76,7 @@ public Maze() { while(target.getMiddleSquare().getContent() == SquareType.GOLD) { // It's never possible that the content is WALL target = this.getTiles()[(int)(Math.random()*2*mazeSize)][(int)(Math.random()*2*mazeSize)]; } - Position newPlayerPosition = this.getTiles()[(int)(Math.random()*2*mazeSize)][(int)(Math.random()*2*mazeSize)].enablePlayer(); + Position newPlayerPosition = target.enablePlayer(); this.getPlayer().setPosition(newPlayerPosition); } @@ -139,7 +147,6 @@ private Tile nextTileFromMovement(MovementType movement) throws UnknownMovementD // Retrieve the tileIndex by searching it in the ArrayList of Tiles int oldTileIndexRow = -1; int oldTileIndexColumn = -1; - int newTileIndex = -1; for(int i=0; i