1 | package com.medievaltech.game;
|
---|
2 |
|
---|
3 | import android.graphics.Canvas;
|
---|
4 | import android.graphics.Point;
|
---|
5 |
|
---|
6 | public class Map {
|
---|
7 | private Tile[][] grid;
|
---|
8 | public Point offset;
|
---|
9 |
|
---|
10 | public Map(int width, int height, Point offset) {
|
---|
11 | grid = new Tile[width][height];
|
---|
12 | this.offset = offset;
|
---|
13 | }
|
---|
14 |
|
---|
15 | public Map(Tile t, int width, int height, Point offset) {
|
---|
16 | grid = new Tile[width][height];
|
---|
17 | this.offset = offset;
|
---|
18 |
|
---|
19 | for(int x=0; x<getWidth(); x++)
|
---|
20 | for(int y=0; y<getHeight(); y++)
|
---|
21 | grid[x][y] = new Tile(t, new Point(x, y));
|
---|
22 | }
|
---|
23 |
|
---|
24 | public int getWidth() {
|
---|
25 | return grid.length;
|
---|
26 | }
|
---|
27 |
|
---|
28 | public int getHeight() {
|
---|
29 | return grid[0].length;
|
---|
30 | }
|
---|
31 |
|
---|
32 | public Tile getTile(int x, int y) {
|
---|
33 | return grid[x][y];
|
---|
34 | }
|
---|
35 |
|
---|
36 | public Tile getTile(Point point) {
|
---|
37 | return grid[point.x][point.y];
|
---|
38 | }
|
---|
39 |
|
---|
40 | public void setTile(int x, int y, Tile t) {
|
---|
41 | grid[x][y] = t;
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void draw(Canvas c) {
|
---|
45 | for(int x=0; x<getWidth(); x++)
|
---|
46 | for(int y=0; y<getHeight(); y++)
|
---|
47 | grid[x][y].draw(c, offset.x+50*x, offset.y+50*y);
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void drawUnits(Canvas c) {
|
---|
51 | for(int x=0; x<getWidth(); x++)
|
---|
52 | for(int y=0; y<getHeight(); y++)
|
---|
53 | grid[x][y].drawUnit(c, offset.x+50*x, offset.y+50*y);
|
---|
54 | }
|
---|
55 | }
|
---|