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