| 1 | package com.medievaltech.advancewars;
|
|---|
| 2 |
|
|---|
| 3 | import java.io.*;
|
|---|
| 4 |
|
|---|
| 5 | import com.medievaltech.unit.Unit;
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | import android.graphics.*;
|
|---|
| 9 |
|
|---|
| 10 | public class Map {
|
|---|
| 11 | private Tile[][] grid;
|
|---|
| 12 | public Point offset;
|
|---|
| 13 |
|
|---|
| 14 | public Map(int width, int height, Point offset) {
|
|---|
| 15 | grid = new Tile[width][height];
|
|---|
| 16 | this.offset = offset;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | public Map(Tile t, int width, int height, Point offset) {
|
|---|
| 20 | grid = new Tile[width][height];
|
|---|
| 21 | this.offset = offset;
|
|---|
| 22 |
|
|---|
| 23 | for(int x=0; x<getWidth(); x++)
|
|---|
| 24 | for(int y=0; y<getHeight(); y++)
|
|---|
| 25 | grid[x][y] = new Tile(t, new Point(x, y));
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | public int getWidth() {
|
|---|
| 29 | return grid.length;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | public int getHeight() {
|
|---|
| 33 | return grid[0].length;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | public Tile getTile(int x, int y) {
|
|---|
| 37 | return grid[x][y];
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | public Tile getTile(Point point) {
|
|---|
| 41 | return grid[point.x][point.y];
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | public void setTile(int x, int y, Tile t) {
|
|---|
| 45 | grid[x][y] = t;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | public void save(PrintWriter p) {
|
|---|
| 49 | p.println(getWidth());
|
|---|
| 50 | p.println(getHeight());
|
|---|
| 51 | p.println(offset.x+"x"+offset.y);
|
|---|
| 52 |
|
|---|
| 53 | for(int x=0; x<getWidth(); x++) {
|
|---|
| 54 | p.print(grid[x][0].type.ordinal());
|
|---|
| 55 | for(int y=1; y<getHeight(); y++)
|
|---|
| 56 | p.print(","+grid[x][y].type.ordinal());
|
|---|
| 57 | p.println();
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | for(int x=0; x<getWidth(); x++) {
|
|---|
| 61 | for(int y=1; y<getHeight(); y++) {
|
|---|
| 62 | if(grid[x][y].currentUnit != null) {
|
|---|
| 63 | Unit u = grid[x][y].currentUnit;
|
|---|
| 64 | //p.println(u.type);
|
|---|
| 65 | p.println(u.location.x+","+u.location.y);
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | public void draw(Canvas c) {
|
|---|
| 72 | for(int x=0; x<getWidth(); x++)
|
|---|
| 73 | for(int y=0; y<getHeight(); y++)
|
|---|
| 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);
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|