source: advance-wars/src/com/medievaltech/advancewars/Map.java@ 379005b

Last change on this file since 379005b was 379005b, checked in by dportnoy <devnull@…>, 13 years ago

Moved all the enums to an Enum.java file.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1package com.medievaltech.advancewars;
2
3import java.io.*;
4
5import android.graphics.*;
6
7import com.medievaltech.unit.Unit;
8
9public class Map {
10 private Tile[][] grid;
11 public Point offset;
12
13 public Map(int width, int height, Point offset) {
14 grid = new Tile[width][height];
15 this.offset = offset;
16 }
17
18 public Map(Tile t, int width, int height, Point offset) {
19 grid = new Tile[width][height];
20 this.offset = offset;
21
22 for(int x=0; x<getWidth(); x++)
23 for(int y=0; y<getHeight(); y++)
24 grid[x][y] = new Tile(t, new Point(x, y));
25 }
26
27 public int getWidth() {
28 return grid.length;
29 }
30
31 public int getHeight() {
32 return grid[0].length;
33 }
34
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
43 public void setTile(int x, int y, Tile t) {
44 grid[x][y] = t;
45 }
46
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);
64 p.println(u.location.x+","+u.location.y);
65 }
66 }
67 }
68 }
69
70 public void draw(Canvas c) {
71 for(int x=0; x<getWidth(); x++)
72 for(int y=0; y<getHeight(); y++)
73 grid[x][y].draw(c, offset.x+50*x, offset.y+50*y);
74 }
75
76 public void drawUnits(Canvas c) {
77 for(int x=0; x<getWidth(); x++)
78 for(int y=0; y<getHeight(); y++)
79 grid[x][y].drawUnit(c, offset.x+50*x, offset.y+50*y);
80 }
81}
Note: See TracBrowser for help on using the repository browser.