...
[AntiTD.git] / src / se / umu / cs / dit06ajnajs / Map.java
blobc14e3c5123e3a128e0f80b59c3615d66ff6755ea
1 package se.umu.cs.dit06ajnajs;
3 import java.awt.Point;
5 public class Map {
7 private int squareSize;
8 private int width;
9 private int height;
10 private MapSquare[][] squareMatrix;
12 public Map(int squareSize, MapSquare[][] squareMatrix) {
13 this.squareSize = squareSize;
14 int numCol;
15 int numRow;
16 try {
17 numCol = squareMatrix.length;
18 numRow = squareMatrix[0].length;
20 catch(NullPointerException e) {
21 //TODO Felmeddelande
22 e.printStackTrace();
23 return;
26 // Set width and height for map
27 this.width = squareSize * numCol;
28 this.height = squareSize * numRow;
29 // Create squareMatrix with right dimension
30 squareMatrix = new MapSquare[numCol][numRow];
33 // TODO Gör metod för att få ut bakgrundsbild. I denna klass eller någon annanstns
35 public MapSquare getMapSquareAtPos(Point point) {
36 //TODO testa algoritmen
37 int x = point.x;
38 int y = point.y;
40 if (x > width || y > height) {
41 throw new IllegalArgumentException("Position is " +
42 "outside of map bounds.");
45 int col = x/squareSize;
46 int row = y/squareSize;
48 return squareMatrix[col][row];