Changeset 1a1e8c7 in advance-wars
- Timestamp:
- Jan 31, 2011, 11:44:53 PM (14 years ago)
- Branches:
- master
- Children:
- 00c432c
- Parents:
- abe7b3d
- Files:
-
- 5 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
res/layout/main.xml
rabe7b3d r1a1e8c7 3 3 android:layout_width="fill_parent" 4 4 android:layout_height="fill_parent"> 5 <com. example.advancewars.GameView android:id="@+id/lunar"5 <com.medievaltech.advancewars.GameView android:id="@+id/lunar" 6 6 android:layout_width="fill_parent" 7 7 android:layout_height="fill_parent" /> -
src/com/medievaltech/advancewars/GameView.java
rabe7b3d r1a1e8c7 1 1 package com.medievaltech.advancewars; 2 2 3 import com.medievaltech.game.*; 3 4 import com.medievaltech.gui.*; 4 5 … … 47 48 48 49 /** Paint to draw the lines on screen. */ 49 private Paint mLinePaint, mTextPaint, mButtonPaint, mTilePaint1, mTilePaint2; 50 private Paint mLinePaint, mTextPaint, mButtonPaint, mTilePaint1, mTilePaint2, 51 mUnitPaint; 50 52 51 53 private Map mMap; … … 88 90 mTilePaint2.setAntiAlias(true); 89 91 mTilePaint2.setARGB(255, 0, 0, 255); 92 93 mUnitPaint = new Paint(); 94 mUnitPaint.setAntiAlias(true); 95 mUnitPaint.setARGB(255, 255, 0, 0); 90 96 91 97 wndMainMenu = new com.medievaltech.gui.Window(0, 0, 320, 450);; … … 106 112 for(int y=0; y<mMap.getHeight(); y++) { 107 113 if(land) 108 mMap.setTile(x, y, grassTile);114 mMap.setTile(x, y, new Tile(grassTile)); 109 115 else 110 mMap.setTile(x, y, oceanTile);116 mMap.setTile(x, y, new Tile(oceanTile)); 111 117 land = !land; 112 118 } 113 119 land = !land; 114 120 } 121 122 mMap.getTile(2, 3).addUnit(new Soldier(mUnitPaint)); 123 mMap.getTile(5, 7).addUnit(new Soldier(mUnitPaint)); 115 124 116 125 mGameState = GameState.MAIN_MENU; -
src/com/medievaltech/game/Map.java
rabe7b3d r1a1e8c7 1 package com.medievaltech. advancewars;1 package com.medievaltech.game; 2 2 3 3 import android.graphics.Canvas; … … 16 16 for(int x=0; x<getWidth(); x++) 17 17 for(int y=0; y<getHeight(); y++) 18 grid[x][y] = t;18 grid[x][y] = new Tile(t); 19 19 } 20 20 … … 25 25 public int getHeight() { 26 26 return grid[0].length; 27 } 28 29 public Tile getTile(int x, int y) { 30 return grid[x][y]; 31 } 32 33 public Tile getTile(Point point) { 34 return grid[point.x][point.y]; 27 35 } 28 36 … … 36 44 grid[x][y].draw(c, xStart+50*x, yStart+50*y); 37 45 } 38 39 public Tile getTile(Point point)40 {41 return grid[point.x][point.y];42 }43 46 } -
src/com/medievaltech/game/Soldier.java
rabe7b3d r1a1e8c7 3 3 import java.util.List; 4 4 5 import android.graphics.Paint; 5 6 import android.graphics.Point; 6 7 7 8 public class Soldier extends Unit{ 8 9 public Soldier(Paint p) { 10 super(p); 11 } 12 9 13 @Override 10 14 public boolean move(Point point) { -
src/com/medievaltech/game/Tile.java
rabe7b3d r1a1e8c7 1 package com.medievaltech.advancewars; 2 3 import com.medievaltech.game.Unit; 1 package com.medievaltech.game; 4 2 5 3 import android.graphics.Canvas; … … 17 15 public Unit currentUnit; 18 16 public Point point; 17 private Paint p; 19 18 20 public void addUnit(Unit unit) 21 { 19 public Tile(Paint p) { 20 this.p = p; 21 this.currentUnit = null; 22 } 23 24 public Tile(Tile t) { 25 this.type = t.type; 26 this.moveCoefficent = t.moveCoefficent; 27 this.p = t.p; 28 } 29 30 public void addUnit(Unit unit) { 22 31 currentUnit = unit; 23 32 } 24 33 25 public void removeUnit(Unit unit) 26 { 27 if(currentUnit != null) 28 { 34 public void removeUnit(Unit unit) { 35 if(currentUnit != null) { 29 36 currentUnit = null; 30 37 } 31 38 32 39 } 33 private Paint p;34 35 public Tile(Paint p) {36 this.p = p;37 }38 40 39 41 public void draw(Canvas c, int x, int y) { 40 42 c.drawRect(x, y, x+50, y+50, p); 43 44 if(currentUnit != null) 45 currentUnit.draw(c, x+25, y+25); 41 46 } 42 47 } -
src/com/medievaltech/game/Transport.java
rabe7b3d r1a1e8c7 1 1 package com.medievaltech.game; 2 2 3 public abstract class Transport extends Unit 4 { 3 import android.graphics.Paint; 4 5 public abstract class Transport extends Unit { 5 6 public Unit storedUnit; 6 7 7 8 public Transport(Paint p) { 9 super(p); 10 } 8 11 } -
src/com/medievaltech/game/Unit.java
rabe7b3d r1a1e8c7 3 3 import java.util.List; 4 4 5 import android.graphics.Canvas; 6 import android.graphics.Paint; 5 7 import android.graphics.Point; 6 8 7 9 public abstract class Unit 8 10 { 9 public Unit()10 {11 12 }13 11 public enum Type 14 12 { … … 16 14 } 17 15 16 private Paint p; 17 18 18 public Type type; 19 19 public Player owner; … … 32 32 public Point location; 33 33 34 public Unit(Paint p) { 35 this.p = p; 36 } 37 34 38 public abstract boolean move(Point point); 35 39 public abstract boolean attack(Point point); … … 38 42 public abstract List<Point> getAttackRange(); 39 43 40 public void die() 41 { 44 public void die() { 42 45 43 46 } 44 47 45 46 47 48 49 50 51 48 public void draw(Canvas c, int x, int y) { 49 c.drawCircle(x, y, 20, p); 50 } 52 51 }
Note:
See TracChangeset
for help on using the changeset viewer.