[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 | {
|
---|
[b23048f] | 14 | LAND,SEA,AIR
|
---|
[15ddb57] | 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 |
|
---|
[78d3c6f] | 35 | public Unit(Paint p)
|
---|
| 36 | {
|
---|
[1a1e8c7] | 37 | this.p = p;
|
---|
[78d3c6f] | 38 | maxHealth = 10;
|
---|
| 39 | currentHealth = 10;
|
---|
| 40 |
|
---|
[1a1e8c7] | 41 | }
|
---|
| 42 |
|
---|
[6a639f7] | 43 | public abstract void move(Point point);
|
---|
| 44 | public abstract void attack(Point point);
|
---|
[ebaddd9] | 45 |
|
---|
| 46 | public List<Point> getMovementRange() {
|
---|
| 47 | List<Point> l = new LinkedList<Point>();
|
---|
| 48 | List<Point> prev = new LinkedList<Point>();
|
---|
| 49 | List<Point> cur = new LinkedList<Point>();
|
---|
| 50 | boolean[][] visited = new boolean[move*2+1][move*2+1];
|
---|
| 51 |
|
---|
| 52 | for(int x=0; x<=move*2; x++)
|
---|
| 53 | for(int y=0; y<=move*2; y++)
|
---|
| 54 | visited[x][y] = false;
|
---|
| 55 |
|
---|
| 56 | prev.add(new Point(location));
|
---|
| 57 | l.addAll(prev);
|
---|
| 58 | visited[move][move] = true;
|
---|
| 59 |
|
---|
| 60 | for(int dist=1; dist <= move; dist++) {
|
---|
| 61 | for(Point p : prev) {
|
---|
| 62 | if(p.x>0 && 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 | }
|
---|
[b97a618] | 66 | if(p.x<5 && p.x<location.x+move && !visited[p.x-location.x+move+1][p.y-location.y+move]) {
|
---|
[ebaddd9] | 67 | cur.add(new Point(p.x+1, p.y));
|
---|
| 68 | visited[p.x-location.x+move+1][p.y-location.y+move] = true;
|
---|
| 69 | }
|
---|
| 70 | if(p.y>0 && 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 | }
|
---|
[b97a618] | 74 | if(p.y<7 && p.y<location.y+move && !visited[p.x-location.x+move][p.y-location.y+move+1]) {
|
---|
[ebaddd9] | 75 | cur.add(new Point(p.x, p.y+1));
|
---|
| 76 | visited[p.x-location.x+move][p.y-location.y+move+1] = true;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | l.addAll(cur);
|
---|
| 81 | prev.clear();
|
---|
| 82 | prev.addAll(cur);
|
---|
| 83 | cur.clear();
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | return l;
|
---|
| 87 | }
|
---|
[a0f5455] | 88 |
|
---|
| 89 | public abstract List<Point> getAttackRange();
|
---|
| 90 |
|
---|
[1a1e8c7] | 91 | public void die() {
|
---|
[a0f5455] | 92 |
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[1a1e8c7] | 95 | public void draw(Canvas c, int x, int y) {
|
---|
| 96 | c.drawCircle(x, y, 20, p);
|
---|
| 97 | }
|
---|
[a0f5455] | 98 | }
|
---|