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