[113d7cf] | 1 | package com.medievaltech.advancewars;
|
---|
[2e798d9] | 2 |
|
---|
[113d7cf] | 3 | import java.io.*;
|
---|
| 4 |
|
---|
| 5 | import android.graphics.*;
|
---|
[2e798d9] | 6 |
|
---|
[379005b] | 7 | import com.medievaltech.unit.Unit;
|
---|
| 8 |
|
---|
[2e798d9] | 9 | public class Map {
|
---|
| 10 | private Tile[][] grid;
|
---|
[b97a618] | 11 | public Point offset;
|
---|
[2e798d9] | 12 |
|
---|
[b97a618] | 13 | public Map(int width, int height, Point offset) {
|
---|
[2e798d9] | 14 | grid = new Tile[width][height];
|
---|
[b97a618] | 15 | this.offset = offset;
|
---|
[2e798d9] | 16 | }
|
---|
| 17 |
|
---|
[b97a618] | 18 | public Map(Tile t, int width, int height, Point offset) {
|
---|
[2e798d9] | 19 | grid = new Tile[width][height];
|
---|
[b97a618] | 20 | this.offset = offset;
|
---|
[2e798d9] | 21 |
|
---|
| 22 | for(int x=0; x<getWidth(); x++)
|
---|
| 23 | for(int y=0; y<getHeight(); y++)
|
---|
[ebaddd9] | 24 | grid[x][y] = new Tile(t, new Point(x, y));
|
---|
[2e798d9] | 25 | }
|
---|
| 26 |
|
---|
| 27 | public int getWidth() {
|
---|
| 28 | return grid.length;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public int getHeight() {
|
---|
| 32 | return grid[0].length;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[1a1e8c7] | 35 | public Tile getTile(int x, int y) {
|
---|
| 36 | return grid[x][y];
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public Tile getTile(Point point) {
|
---|
| 40 | return grid[point.x][point.y];
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[2e798d9] | 43 | public void setTile(int x, int y, Tile t) {
|
---|
| 44 | grid[x][y] = t;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[113d7cf] | 47 | public void save(PrintWriter p) {
|
---|
| 48 | p.println(getWidth());
|
---|
| 49 | p.println(getHeight());
|
---|
| 50 | p.println(offset.x+"x"+offset.y);
|
---|
| 51 |
|
---|
| 52 | for(int x=0; x<getWidth(); x++) {
|
---|
| 53 | p.print(grid[x][0].type.ordinal());
|
---|
| 54 | for(int y=1; y<getHeight(); y++)
|
---|
| 55 | p.print(","+grid[x][y].type.ordinal());
|
---|
| 56 | p.println();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | for(int x=0; x<getWidth(); x++) {
|
---|
| 60 | for(int y=1; y<getHeight(); y++) {
|
---|
| 61 | if(grid[x][y].currentUnit != null) {
|
---|
| 62 | Unit u = grid[x][y].currentUnit;
|
---|
| 63 | //p.println(u.type);
|
---|
[c3ad11c] | 64 | //we also need to save the owner of the unit
|
---|
[113d7cf] | 65 | p.println(u.location.x+","+u.location.y);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[b97a618] | 71 | public void draw(Canvas c) {
|
---|
[2e798d9] | 72 | for(int x=0; x<getWidth(); x++)
|
---|
| 73 | for(int y=0; y<getHeight(); y++)
|
---|
[b97a618] | 74 | grid[x][y].draw(c, offset.x+50*x, offset.y+50*y);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | public void drawUnits(Canvas c) {
|
---|
| 78 | for(int x=0; x<getWidth(); x++)
|
---|
| 79 | for(int y=0; y<getHeight(); y++)
|
---|
| 80 | grid[x][y].drawUnit(c, offset.x+50*x, offset.y+50*y);
|
---|
[2e798d9] | 81 | }
|
---|
[41c11dd] | 82 |
|
---|
| 83 | public void drawBuildings(Canvas c) {
|
---|
| 84 | for(int x=0; x<getWidth(); x++)
|
---|
| 85 | for(int y=0; y<getHeight(); y++)
|
---|
| 86 | grid[x][y].drawBuilding(c, offset.x+50*x, offset.y+50*y);
|
---|
| 87 | }
|
---|
[2e798d9] | 88 | }
|
---|