Changeset ebaddd9 in advance-wars for src/com/medievaltech/game/Unit.java
- Timestamp:
- Feb 2, 2011, 3:36:46 AM (14 years ago)
- Branches:
- master
- Children:
- 6a639f7
- Parents:
- 5d77d43
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/medievaltech/game/Unit.java
r5d77d43 rebaddd9 1 1 package com.medievaltech.game; 2 2 3 import java.util.LinkedList; 3 4 import java.util.List; 4 5 … … 26 27 27 28 public int sightRange; 28 p ublicint move;29 protected int move; 29 30 30 31 public int minAttackRange; … … 36 37 } 37 38 38 public abstract voidmove(Point point);39 public abstract voidattack(Point point);39 public abstract boolean move(Point point); 40 public abstract boolean attack(Point point); 40 41 41 public abstract List<Point> getRange(); 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 } 84 42 85 public abstract List<Point> getAttackRange(); 43 86
Note:
See TracChangeset
for help on using the changeset viewer.