Changeset 113d7cf in advance-wars
- Timestamp:
- May 9, 2011, 6:23:05 PM (14 years ago)
- Branches:
- master
- Children:
- bdd63ba
- Parents:
- ae564dc
- Files:
-
- 1 deleted
- 4 edited
- 9 moved
Legend:
- Unmodified
- Added
- Removed
-
AndroidManifest.xml
rae564dc r113d7cf 4 4 android:versionCode="1" 5 5 android:versionName="1.0"> 6 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> 6 7 <application android:icon="@drawable/icon" android:label="@string/app_name"> 7 <activity android:name=" .Game"8 <activity android:name="Game" 8 9 android:label="@string/app_name"> 9 10 <intent-filter> -
res/values/strings.xml
rae564dc r113d7cf 3 3 <string name="hello">Hello World, advancewars!</string> 4 4 <string name="app_name">Advance Wars</string> 5 <string name="menu_save">Save</string> 6 <string name="menu_main">Main Menu</string> 5 7 <string name="menu_exit">Exit</string> 6 8 </resources> -
src/com/medievaltech/advancewars/Game.java
rae564dc r113d7cf 1 1 package com.medievaltech.advancewars; 2 2 3 import com.medievaltech.advancewars.R;4 import com.medievaltech.advancewars.GameView; 3 import java.io.*; 4 5 5 import com.medievaltech.advancewars.GameView.DrawingThread; 6 6 … … 14 14 15 15 public class Game extends Activity { 16 private static final int MENU_EXIT = 1; 17 private static final int MENU_NEW = 2; 16 private static final int MENU_SAVE = 1; 17 private static final int MENU_MAIN = 2; 18 private static final int MENU_EXIT = 3; 18 19 19 20 public enum State{BUST, ACTIVE, DOUBLEDOWN}; … … 35 36 super.onCreateOptionsMenu(menu); 36 37 38 menu.add(0, MENU_SAVE, 0, R.string.menu_save); 39 menu.add(0, MENU_MAIN, 0, R.string.menu_main); 37 40 menu.add(0, MENU_EXIT, 0, R.string.menu_exit); 38 41 return true; … … 49 52 public boolean onOptionsItemSelected(MenuItem item) { 50 53 switch (item.getItemId()) { 54 case MENU_SAVE: 55 try { 56 PrintWriter p = new PrintWriter(new FileWriter(android.os.Environment.getExternalStorageDirectory()+"/save.txt")); 57 mThread.mMap.save(p); 58 p.close(); 59 }catch(IOException ioe) { 60 ioe.printStackTrace(); 61 } 62 break; 63 case MENU_MAIN: 64 mThread.mGameState = GameState.MAIN_MENU; 65 break; 51 66 case MENU_EXIT: 52 this.finish();67 finish(); 53 68 break; 54 69 } … … 93 108 94 109 mGameView.getThread().mGameState = (GameState)savedInstanceState.getSerializable("gameState"); 95 96 mGameView.getThread().mPlayerWins = savedInstanceState.getInt("playerWins");97 mGameView.getThread().mPlayerLosses = savedInstanceState.getInt("playerLosses");98 110 } 99 111 } … … 117 129 protected void onSaveInstanceState(Bundle outState) { 118 130 outState.putSerializable("gameState", mGameView.getThread().mGameState); 119 outState.putSerializable("playerWins", mGameView.getThread().mPlayerWins); 120 outState.putSerializable("playerLosses", mGameView.getThread().mPlayerLosses); 121 131 122 132 super.onSaveInstanceState(outState); 123 Log.w(" Blackjack", "onSaveInstanceState called");133 Log.w("AdvanceWars", "onSaveInstanceState called"); 124 134 } 125 135 -
src/com/medievaltech/advancewars/GameView.java
rae564dc r113d7cf 1 1 package com.medievaltech.advancewars; 2 2 3 import com.medievaltech.game.*; 3 import java.io.*; 4 5 import com.medievaltech.advancewars.Tile.TerrainType; 6 import com.medievaltech.unit.*; 4 7 import com.medievaltech.gui.*; 5 8 … … 12 15 import android.widget.TextView; 13 16 14 /**15 * View that draws, takes keystrokes, etc. for a simple LunarLander game.16 *17 * Has a mode which RUNNING, PAUSED, etc. Has a x, y, dx, dy, ... capturing the18 * current ship physics. All x/y etc. are measured with (0,0) at the lower left.19 * updatePhysics() advances the physics based on realtime. draw() renders the20 * ship, and does an invalidate() to prompt another draw() as soon as possible21 * by the system.22 */23 17 class GameView extends SurfaceView implements SurfaceHolder.Callback { 24 18 … … 39 33 private int mCanvasHeight = 1; 40 34 private int mCanvasWidth = 1; 41 public int mPlayerWins = 0, mPlayerLosses = 0;42 35 43 36 /** Message handler used by thread to interact with TextView */ … … 51 44 mUnitPaint; 52 45 53 private Map mMap; 46 //maybe make this private and make an accessor for it 47 public Map mMap; 48 49 public Tile grassTile, oceanTile; 54 50 55 51 /** Indicate whether the surface has been created & is ready to draw */ … … 59 55 private SurfaceHolder mSurfaceHolder; 60 56 61 private com.medievaltech.gui.Window wndMainMenu , wndBattleMap;57 private com.medievaltech.gui.Window wndMainMenu; 62 58 private Unit selectedUnit; 63 59 … … 66 62 mSurfaceHolder = surfaceHolder; 67 63 mHandler = handler; 68 mContext = context;69 64 70 65 mLinePaint = new Paint(); … … 107 102 wndMainMenu.addGUIObject("btnQuit", new Button("Quit", 100, 195, 120, 20, mLinePaint, mButtonPaint)); 108 103 109 Tile grassTile = new Tile(mTilePaint1);110 Tile oceanTile = new Tile(mTilePaint2);104 grassTile = new Tile(mTilePaint1, TerrainType.LAND); 105 oceanTile = new Tile(mTilePaint2, TerrainType.SEA); 111 106 112 107 mMap = new Map(grassTile, 6, 8, new Point(10, 25)); … … 336 331 private void doDraw(Canvas canvas) { 337 332 canvas.drawColor(Color.BLACK); 338 339 String text;340 Paint.FontMetrics metrics = mTextPaint.getFontMetrics();341 333 342 334 switch(mGameState) { … … 380 372 } 381 373 382 /** Handle to the application context, used to e.g. fetch Drawables. */383 private Context mContext;384 385 374 /** Pointer to the text view to display "Paused.." etc. */ 386 375 private TextView mStatusText; … … 421 410 thread.mGameState = GameState.BATTLE_MAP; 422 411 }else if(thread.wndMainMenu.getGUIObject("btnLoadGame").isClicked(event.getX(), event.getY())) { 412 BufferedReader b; 413 try { 414 b = new BufferedReader(new FileReader(android.os.Environment.getExternalStorageDirectory()+"/save.txt")); 415 416 int width = Integer.parseInt(b.readLine()); 417 int height = Integer.parseInt(b.readLine()); 418 419 String offset = b.readLine(); 420 Log.i("GameSave", offset); 421 int offsetX = Integer.parseInt(offset.substring(0, offset.indexOf("x"))); 422 int offsetY = Integer.parseInt(offset.substring(offset.indexOf("x")+1)); 423 424 thread.mMap = new Map(thread.grassTile, width, height, new Point(offsetX, offsetY)); 425 426 Log.i("GameSave", "Created the map"); 427 428 for(int x=0; x<width; x++) { 429 String line = b.readLine(); 430 Log.i("GameSave", line); 431 String[] arr = line.split(","); 432 for(int y=0; y<arr.length; y++) { 433 TerrainType type = TerrainType.values()[Integer.parseInt(arr[y])]; 434 if(type.equals(TerrainType.LAND)) 435 thread.mMap.setTile(x, y, new Tile(thread.grassTile, new Point(10, 25))); 436 else 437 thread.mMap.setTile(x, y, new Tile(thread.oceanTile, new Point(10, 25))); 438 } 439 } 440 441 while(b.ready()) { 442 String unit = b.readLine(); 443 Log.i("GameSave", unit); 444 int x = Integer.parseInt(unit.substring(0, unit.indexOf(","))); 445 int y = Integer.parseInt(unit.substring(unit.indexOf(",")+1)); 446 447 mGame.mThread.mMap.getTile(x, y).addUnit(new Soldier(mGame.mThread.mUnitPaint)); 448 } 449 450 b.close(); 451 }catch(IOException ioe) { 452 ioe.printStackTrace(); 453 } 423 454 thread.mGameState = GameState.BATTLE_MAP; 424 455 }else if(thread.wndMainMenu.getGUIObject("btnQuit").isClicked(event.getX(), event.getY())) { -
src/com/medievaltech/advancewars/Map.java
rae564dc r113d7cf 1 package com.medievaltech. game;1 package com.medievaltech.advancewars; 2 2 3 import android.graphics.Canvas; 4 import android.graphics.Point; 3 import java.io.*; 4 5 import com.medievaltech.unit.Unit; 6 7 8 import android.graphics.*; 5 9 6 10 public class Map { … … 42 46 } 43 47 48 public void save(PrintWriter p) { 49 p.println(getWidth()); 50 p.println(getHeight()); 51 p.println(offset.x+"x"+offset.y); 52 53 for(int x=0; x<getWidth(); x++) { 54 p.print(grid[x][0].type.ordinal()); 55 for(int y=1; y<getHeight(); y++) 56 p.print(","+grid[x][y].type.ordinal()); 57 p.println(); 58 } 59 60 for(int x=0; x<getWidth(); x++) { 61 for(int y=1; y<getHeight(); y++) { 62 if(grid[x][y].currentUnit != null) { 63 Unit u = grid[x][y].currentUnit; 64 //p.println(u.type); 65 p.println(u.location.x+","+u.location.y); 66 } 67 } 68 } 69 } 70 44 71 public void draw(Canvas c) { 45 72 for(int x=0; x<getWidth(); x++) -
src/com/medievaltech/advancewars/Tile.java
rae564dc r113d7cf 1 package com.medievaltech.game; 1 package com.medievaltech.advancewars; 2 3 import com.medievaltech.unit.Unit; 2 4 3 5 import android.graphics.Canvas; … … 17 19 private Paint p; 18 20 19 public Tile(Paint p ) {21 public Tile(Paint p, TerrainType type) { 20 22 this.p = p; 23 this.type = type; 21 24 this.currentUnit = null; 22 25 } -
src/com/medievaltech/unit/Artillery.java
rae564dc r113d7cf 1 package com.medievaltech. game;1 package com.medievaltech.unit; 2 2 3 3 import java.util.List; -
src/com/medievaltech/unit/Mech.java
rae564dc r113d7cf 1 package com.medievaltech. game;1 package com.medievaltech.unit; 2 2 3 3 import java.util.List; -
src/com/medievaltech/unit/Recon.java
rae564dc r113d7cf 1 package com.medievaltech. game;1 package com.medievaltech.unit; 2 2 3 3 import java.util.List; -
src/com/medievaltech/unit/SmTank.java
rae564dc r113d7cf 1 package com.medievaltech. game;1 package com.medievaltech.unit; 2 2 3 3 import java.util.List; -
src/com/medievaltech/unit/Soldier.java
rae564dc r113d7cf 1 package com.medievaltech. game;1 package com.medievaltech.unit; 2 2 3 3 import java.util.List; -
src/com/medievaltech/unit/Transport.java
rae564dc r113d7cf 1 package com.medievaltech. game;1 package com.medievaltech.unit; 2 2 3 3 import android.graphics.Paint; -
src/com/medievaltech/unit/Unit.java
rae564dc r113d7cf 1 package com.medievaltech. game;1 package com.medievaltech.unit; 2 2 3 import java.util.LinkedList; 4 import java.util.List; 5 6 import android.graphics.Canvas; 7 import android.graphics.Paint; 8 import android.graphics.Point; 3 import java.util.*; 4 import android.graphics.*; 9 5 10 6 public abstract class Unit … … 18 14 19 15 public Type type; 20 public Player owner;16 //public Player owner; 21 17 22 18 public int maxHealth;
Note:
See TracChangeset
for help on using the changeset viewer.