From 14dfbea630efa5d9376b509a4d198b078505ba4e Mon Sep 17 00:00:00 2001
From: GabrielMagnus <Gabriel.Magnus@student.uib.no>
Date: Mon, 16 Mar 2020 16:46:22 +0100
Subject: [PATCH] Endret metodenavn for mer lesbarhet

---
 .../fiasko/roborally/objects/Board.java       | 26 ++++++++++---------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java
index 5ab22dc..b28eac4 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/Board.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java
@@ -345,7 +345,7 @@ public class Board {
      * @param walls The walls you want all positions for
      * @return A list of BoardElementContainers
      */
-    public List<BoardElementContainer<Wall>> getPositionsOfTileOnBoard(WallType ... walls) {
+    public List<BoardElementContainer<Wall>> getPositionsOfWallOnBoard(WallType ... walls) {
         List<BoardElementContainer<Wall>> combinedList = new ArrayList<>();
         for (WallType wall : walls) {
             combinedList.addAll(makeTileList(wall, this.walls));
@@ -367,18 +367,20 @@ public class Board {
         for (int y = grid.getHeight() - 1; y >= 0; y--) {
             for (int x = 0; x < grid.getWidth(); x++) {
                 T gridElement = grid.getElement(x, y);
-                if (gridElement.getClass().isAssignableFrom(Tile.class)) {
-                    Tile tile = (Tile) gridElement;
-                    if (tile.getTileType() == type) {
-                        objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
+                if (gridElement != null) {
+                    if (gridElement.getClass().isAssignableFrom(Tile.class)) {
+                        Tile tile = (Tile) gridElement;
+                        if (tile.getTileType() == type) {
+                            objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
+                        }
+                    } else if (gridElement.getClass().isAssignableFrom(Wall.class)) {
+                        Wall wall = (Wall) gridElement;
+                        if (wall.getWallType() == type) {
+                            objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
+                        }
+                    } else {
+                        throw new IllegalArgumentException("Grid has unknown type.");
                     }
-                } else if (gridElement.getClass().isAssignableFrom(Wall.class)) {
-                    Wall wall = (Wall) gridElement;
-                    if (wall.getWallType() == type) {
-                        objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
-                    }
-                } else {
-                    throw new IllegalArgumentException("Grid has unknown type.");
                 }
             }
         }