Changeset ebaddd9 in advance-wars
- Timestamp:
- Feb 2, 2011, 3:36:46 AM (14 years ago)
- Branches:
- master
- Children:
- 6a639f7
- Parents:
- 5d77d43
- Location:
- src/com/medievaltech
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/medievaltech/advancewars/GameView.java
r5d77d43 rebaddd9 48 48 49 49 /** Paint to draw the lines on screen. */ 50 private Paint mLinePaint, mTextPaint, mButtonPaint, mTilePaint1, mTilePaint2, 50 private Paint mLinePaint, mTextPaint, mButtonPaint, mTilePaint1, mTilePaint2, mSelectionPaint, 51 51 mUnitPaint; 52 52 … … 60 60 61 61 private com.medievaltech.gui.Window wndMainMenu, wndBattleMap; 62 private Unit selectedUnit; 63 private boolean test = false; 62 64 63 65 public DrawingThread(SurfaceHolder surfaceHolder, Context context, Handler handler) { … … 94 96 mUnitPaint.setAntiAlias(true); 95 97 mUnitPaint.setARGB(255, 255, 0, 0); 98 99 mSelectionPaint = new Paint(); 100 mSelectionPaint.setAntiAlias(true); 101 mSelectionPaint.setARGB(255, 255, 127, 0); 96 102 97 103 wndMainMenu = new com.medievaltech.gui.Window(0, 0, 320, 450);; … … 112 118 for(int y=0; y<mMap.getHeight(); y++) { 113 119 if(land) 114 mMap.setTile(x, y, new Tile(grassTile ));120 mMap.setTile(x, y, new Tile(grassTile, new Point(x, y))); 115 121 else 116 mMap.setTile(x, y, new Tile(oceanTile ));122 mMap.setTile(x, y, new Tile(oceanTile, new Point(x, y))); 117 123 land = !land; 118 124 } … … 122 128 mMap.getTile(2, 3).addUnit(new Soldier(mUnitPaint)); 123 129 mMap.getTile(5, 7).addUnit(new Soldier(mUnitPaint)); 130 131 selectedUnit = mMap.getTile(2, 3).currentUnit; 124 132 125 133 mGameState = GameState.MAIN_MENU; … … 343 351 344 352 mMap.draw(canvas, 10, 25); 353 354 for(Point p : selectedUnit.getMovementRange()) { 355 canvas.drawRect(p.x*50+10, p.y*50+25, p.x*50+50+10, p.y*50+50+25, mSelectionPaint); 356 if(!test) 357 Log.i("AdvanceWars", "("+p.x+","+p.y+")"); 358 } 359 test = true; 345 360 346 361 text = "Advance Wars grid test"; -
src/com/medievaltech/game/Map.java
r5d77d43 rebaddd9 16 16 for(int x=0; x<getWidth(); x++) 17 17 for(int y=0; y<getHeight(); y++) 18 grid[x][y] = new Tile(t );18 grid[x][y] = new Tile(t, new Point(x, y)); 19 19 } 20 20 -
src/com/medievaltech/game/Soldier.java
r5d77d43 rebaddd9 9 9 public Soldier(Paint p) { 10 10 super(p); 11 12 move = 2; 11 13 } 12 14 … … 24 26 25 27 @Override 26 public List<Point> getRange() { 27 // TODO Auto-generated method stub 28 return null; 28 public List<Point> getMovementRange() { 29 return super.getMovementRange(); 29 30 } 30 31 -
src/com/medievaltech/game/Tile.java
r5d77d43 rebaddd9 22 22 } 23 23 24 public Tile(Tile t ) {24 public Tile(Tile t, Point point) { 25 25 this.type = t.type; 26 26 this.moveCoefficent = t.moveCoefficent; 27 27 this.p = t.p; 28 this.point = point; 28 29 } 29 30 30 31 public void addUnit(Unit unit) { 31 currentUnit = unit; 32 currentUnit = unit; 33 unit.location = point; 32 34 } 33 35 -
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.