Changeset 205f525 in advance-wars
- Timestamp:
- Jan 30, 2011, 8:26:19 PM (14 years ago)
- Branches:
- master
- Children:
- 26a9fd6, a0f5455
- Parents:
- 90838a1
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
res/values/strings.xml
r90838a1 r205f525 2 2 <resources> 3 3 <string name="hello">Hello World, advancewars!</string> 4 <string name="app_name"> </string>4 <string name="app_name">Advance Wars</string> 5 5 <string name="menu_exit">Exit</string> 6 6 </resources> -
src/com/example/advancewars/Game.java
r90838a1 r205f525 52 52 this.finish(); 53 53 break; 54 case MENU_NEW:55 break;56 54 } 57 55 … … 67 65 @Override 68 66 protected void onCreate(Bundle savedInstanceState) { 69 Log.w(" Blackjack", "We're inside onCreate");67 Log.w("AdvanceWars", "We're inside onCreate"); 70 68 71 69 super.onCreate(savedInstanceState); 72 70 73 Log.w(" Blackjack", "the super constructor was called successfully");71 Log.w("AdvanceWars", "the super constructor was called successfully"); 74 72 75 73 // turn off the window's title bar … … 81 79 mGameView = (GameView) findViewById(R.id.lunar); 82 80 mThread = mGameView.getThread(); 81 mGameView.mGame = this; 83 82 84 83 mGameView.setTextView((TextView) findViewById(R.id.text)); 85 84 86 85 if (savedInstanceState == null) { // we were just launched: set up a new game 87 Log.w(" Blackjack", "SIS is null");86 Log.w("AdvanceWars", "SIS is null"); 88 87 89 88 mThread.setState(AppState.RUNNING); 90 89 } else { 91 Log.w(" Blackjack", "SIS is nonnull");90 Log.w("AdvanceWars", "SIS is nonnull"); 92 91 93 92 mThread.setState(AppState.RUNNING); -
src/com/example/advancewars/GameView.java
r90838a1 r205f525 2 2 3 3 import java.util.*; 4 5 import com.example.gui.*; 4 6 5 7 import android.content.Context; … … 57 59 private SurfaceHolder mSurfaceHolder; 58 60 59 public DrawingThread(SurfaceHolder surfaceHolder, Context context, 60 Handler handler) { 61 private Hashtable<String, GUIObject> drawableObjects; 62 63 public DrawingThread(SurfaceHolder surfaceHolder, Context context, Handler handler) { 61 64 // get handles to some important objects 62 65 mSurfaceHolder = surfaceHolder; … … 72 75 mTextPaint.setARGB(255, 255, 255, 255); 73 76 mTextPaint.setTextSize(12); 77 mTextPaint.setTextAlign(Paint.Align.CENTER); 74 78 75 79 mButtonPaint = new Paint(); … … 86 90 mTilePaint2.setAntiAlias(true); 87 91 mTilePaint2.setARGB(255, 0, 0, 255); 92 93 drawableObjects = new Hashtable<String, GUIObject>(); 94 95 drawableObjects.put("txtTitle", new Text("Main Menu", 100, 30, 120, 20, mTextPaint)); 96 drawableObjects.put("btnNewGame", new Button("New Game", 100, 90, 120, 20, mLinePaint, mButtonPaint)); 97 drawableObjects.put("btnLoadGame", new Button("Load Game", 100, 125, 120, 20, mLinePaint, mButtonPaint)); 98 drawableObjects.put("btnMapEditor", new Button("Map Editor", 100, 160, 120, 20, mLinePaint, mButtonPaint)); 99 drawableObjects.put("btnQuit", new Button("Quit", 100, 195, 120, 20, mLinePaint, mButtonPaint)); 88 100 89 101 Tile grassTile = new Tile(mTilePaint1); … … 116 128 mLastTime = System.currentTimeMillis() + 100; 117 129 setState(AppState.RUNNING); 118 Log.i(" Blackjack", "Player's turn starting now");130 Log.i("AdvanceWars", "Player's turn starting now"); 119 131 mGameState = GameState.MAIN_MENU; 120 132 } … … 234 246 mCanvasHeight = height; 235 247 236 Log.i(" Blackjack", "width: "+mCanvasWidth+", height: "+mCanvasHeight);248 Log.i("AdvanceWars", "width: "+mCanvasWidth+", height: "+mCanvasHeight); 237 249 } 238 250 } … … 319 331 switch(mGameState) { 320 332 case MAIN_MENU: 321 text = "Main Menu"; 322 canvas.drawText(text, 0, 450-(metrics.ascent+metrics.descent)/2, mTextPaint); 333 for (GUIObject o : drawableObjects.values()) { 334 o.draw(canvas); 335 } 323 336 break; 324 337 case BATTLE_MAP: … … 360 373 /** The thread that actually draws the animation */ 361 374 private DrawingThread thread; 375 376 public Game mGame; 362 377 363 378 public GameView(Context context, AttributeSet attrs) { … … 381 396 382 397 @Override public boolean onTouchEvent(MotionEvent event) { 383 Log.i(" Blackjack", "Detected touch event");398 Log.i("AdvanceWars", "Detected touch event"); 384 399 385 400 if(event.getAction() == MotionEvent.ACTION_UP) { 386 Log.i(" Blackjack", "Detected UP touch action");401 Log.i("AdvanceWars", "Detected UP touch action"); 387 402 switch(thread.mGameState) { 388 403 case MAIN_MENU: 389 Log.i("Blackjack", "Switching to battle map"); 390 thread.mGameState = GameState.BATTLE_MAP; 404 Log.i("AdvanceWars", "Switching to battle map"); 405 if(thread.drawableObjects.get("btnNewGame").isClicked(event.getX(), event.getY())) { 406 thread.mGameState = GameState.BATTLE_MAP; 407 }else if(thread.drawableObjects.get("btnLoadGame").isClicked(event.getX(), event.getY())) { 408 thread.mGameState = GameState.BATTLE_MAP; 409 }else if(thread.drawableObjects.get("btnQuit").isClicked(event.getX(), event.getY())) { 410 mGame.finish(); 411 } 391 412 break; 392 413 case BATTLE_MAP: 393 Log.i("Blackjack", "Touch event detected on battle map"); 414 Log.i("AdvanceWars", "Touch event detected on battle map"); 415 thread.mGameState = GameState.MAIN_MENU; 394 416 break; 395 417 }
Note:
See TracChangeset
for help on using the changeset viewer.