[abe7b3d] | 1 | package com.medievaltech.game;
|
---|
[a0f5455] | 2 |
|
---|
[ebaddd9] | 3 | import java.util.LinkedList;
|
---|
[a0f5455] | 4 | import java.util.List;
|
---|
| 5 |
|
---|
[1a1e8c7] | 6 | import android.graphics.Canvas;
|
---|
| 7 | import android.graphics.Paint;
|
---|
[a0f5455] | 8 | import android.graphics.Point;
|
---|
| 9 |
|
---|
| 10 | public abstract class Unit
|
---|
| 11 | {
|
---|
[15ddb57] | 12 | public enum Type
|
---|
| 13 | {
|
---|
| 14 | LAND,SEA
|
---|
| 15 | }
|
---|
| 16 |
|
---|
[1a1e8c7] | 17 | private Paint p;
|
---|
| 18 |
|
---|
[15ddb57] | 19 | public Type type;
|
---|
| 20 | public Player owner;
|
---|
| 21 |
|
---|
[a0f5455] | 22 | public int maxHealth;
|
---|
| 23 | public int currentHealth;
|
---|
| 24 |
|
---|
| 25 | public int maxFuel;
|
---|
| 26 | public int currentFuel;
|
---|
| 27 |
|
---|
| 28 | public int sightRange;
|
---|
[ebaddd9] | 29 | protected int move;
|
---|
[a0f5455] | 30 |
|
---|
| 31 | public int minAttackRange;
|
---|
| 32 | public int maxAttackRange;
|
---|
| 33 | public Point location;
|
---|
| 34 |
|
---|
[1a1e8c7] | 35 | public Unit(Paint p) {
|
---|
| 36 | this.p = p;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
[ebaddd9] | 39 | public abstract boolean move(Point point);
|
---|
| 40 | public abstract boolean attack(Point point);
|
---|
| 41 |
|
---|
| 42 | public List<Point> getMovementRange() {
|
---|
| 43 | List<Point> l = new LinkedList<Point>();
|
---|
| 44 | List<Point> prev = new LinkedList<Point>();
|
---|
| 45 | List<Point> cur = new LinkedList<Point>();
|
---|
| 46 | boolean[][] visited = new boolean[move*2+1][move*2+1];
|
---|
| 47 |
|
---|
| 48 | for(int x=0; x<=move*2; x++)
|
---|
| 49 | for(int y=0; y<=move*2; y++)
|
---|
| 50 | visited[x][y] = false;
|
---|
| 51 |
|
---|
| 52 | prev.add(new Point(location));
|
---|
| 53 | l.addAll(prev);
|
---|
| 54 | visited[move][move] = true;
|
---|
| 55 |
|
---|
| 56 | for(int dist=1; dist <= move; dist++) {
|
---|
| 57 | for(Point p : prev) {
|
---|
| 58 | if(p.x>0 && p.x>location.x-move && !visited[p.x-location.x+move-1][p.y-location.y+move]) {
|
---|
| 59 | cur.add(new Point(p.x-1, p.y));
|
---|
| 60 | visited[p.x-location.x+move-1][p.y-location.y+move] = true;
|
---|
| 61 | }
|
---|
| 62 | if(p.x<8 && p.x<location.x+move && !visited[p.x-location.x+move+1][p.y-location.y+move]) {
|
---|
| 63 | cur.add(new Point(p.x+1, p.y));
|
---|
| 64 | visited[p.x-location.x+move+1][p.y-location.y+move] = true;
|
---|
| 65 | }
|
---|
| 66 | if(p.y>0 && p.y>location.y-move && !visited[p.x-location.x+move][p.y-location.y+move-1]) {
|
---|
| 67 | cur.add(new Point(p.x, p.y-1));
|
---|
| 68 | visited[p.x-location.x+move][p.y-location.y+move-1] = true;
|
---|
| 69 | }
|
---|
| 70 | if(p.y<6 && p.y<location.y+move && !visited[p.x-location.x+move][p.y-location.y+move+1]) {
|
---|
| 71 | cur.add(new Point(p.x, p.y+1));
|
---|
| 72 | visited[p.x-location.x+move][p.y-location.y+move+1] = true;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | l.addAll(cur);
|
---|
| 77 | prev.clear();
|
---|
| 78 | prev.addAll(cur);
|
---|
| 79 | cur.clear();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | return l;
|
---|
| 83 | }
|
---|
[a0f5455] | 84 |
|
---|
| 85 | public abstract List<Point> getAttackRange();
|
---|
| 86 |
|
---|
[1a1e8c7] | 87 | public void die() {
|
---|
[a0f5455] | 88 |
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[1a1e8c7] | 91 | public void draw(Canvas c, int x, int y) {
|
---|
| 92 | c.drawCircle(x, y, 20, p);
|
---|
| 93 | }
|
---|
[a0f5455] | 94 | }
|
---|