Changeset 113d7cf in advance-wars for src/com/medievaltech/advancewars/GameView.java
- Timestamp:
- May 9, 2011, 6:23:05 PM (14 years ago)
- Branches:
- master
- Children:
- bdd63ba
- Parents:
- ae564dc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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())) {
Note:
See TracChangeset
for help on using the changeset viewer.