source: advance-wars/src/com/medievaltech/advancewars/Game.java@ ae564dc

Last change on this file since ae564dc was abe7b3d, checked in by dportnoy <devnull@…>, 14 years ago

Changed the package names from com.example.* to com.medievaltech.*

  • Property mode set to 100644
File size: 4.0 KB
Line 
1package com.medievaltech.advancewars;
2
3import com.medievaltech.advancewars.R;
4import com.medievaltech.advancewars.GameView;
5import com.medievaltech.advancewars.GameView.DrawingThread;
6
7import android.app.Activity;
8import android.os.Bundle;
9import android.util.Log;
10import android.view.Menu;
11import android.view.MenuItem;
12import android.view.Window;
13import android.widget.TextView;
14
15public class Game extends Activity {
16 private static final int MENU_EXIT = 1;
17 private static final int MENU_NEW = 2;
18
19 public enum State{BUST, ACTIVE, DOUBLEDOWN};
20
21 /** A handle to the thread that's actually running the animation. */
22 public DrawingThread mThread;
23
24 /** A handle to the View in which the game is running. */
25 private GameView mGameView;
26
27 /**
28 * Invoked during init to give the Activity a chance to set up its Menu.
29 *
30 * @param menu the Menu to which entries may be added
31 * @return true
32 */
33 @Override
34 public boolean onCreateOptionsMenu(Menu menu) {
35 super.onCreateOptionsMenu(menu);
36
37 menu.add(0, MENU_EXIT, 0, R.string.menu_exit);
38 return true;
39 }
40
41 /**
42 * Invoked when the user selects an item from the Menu.
43 *
44 * @param item the Menu entry which was selected
45 * @return true if the Menu item was legit (and we consumed it), false
46 * otherwise
47 */
48 @Override
49 public boolean onOptionsItemSelected(MenuItem item) {
50 switch (item.getItemId()) {
51 case MENU_EXIT:
52 this.finish();
53 break;
54 }
55
56 return true;
57 }
58
59 /**
60 * Invoked when the Activity is created.
61 *
62 * @param savedInstanceState a Bundle containing state saved from a previous
63 * execution, or null if this is a new execution
64 */
65 @Override
66 protected void onCreate(Bundle savedInstanceState) {
67 Log.w("AdvanceWars", "We're inside onCreate");
68
69 super.onCreate(savedInstanceState);
70
71 Log.w("AdvanceWars", "the super constructor was called successfully");
72
73 // turn off the window's title bar
74 requestWindowFeature(Window.FEATURE_NO_TITLE);
75
76 // tell system to use the layout defined in our XML file
77 setContentView(R.layout.main);
78
79 mGameView = (GameView) findViewById(R.id.lunar);
80 mThread = mGameView.getThread();
81 mGameView.mGame = this;
82
83 mGameView.setTextView((TextView) findViewById(R.id.text));
84
85 if (savedInstanceState == null) { // we were just launched: set up a new game
86 Log.w("AdvanceWars", "SIS is null");
87
88 mThread.setState(AppState.RUNNING);
89 } else {
90 Log.w("AdvanceWars", "SIS is nonnull");
91
92 mThread.setState(AppState.RUNNING);
93
94 mGameView.getThread().mGameState = (GameState)savedInstanceState.getSerializable("gameState");
95
96 mGameView.getThread().mPlayerWins = savedInstanceState.getInt("playerWins");
97 mGameView.getThread().mPlayerLosses = savedInstanceState.getInt("playerLosses");
98 }
99 }
100
101 /**
102 * Invoked when the Activity loses user focus.
103 */
104 @Override
105 protected void onPause() {
106 super.onPause();
107 mGameView.getThread().pause(); // pause game when Activity pauses
108 }
109
110 /**
111 * Notification that something is about to happen, to give the Activity a
112 * chance to save state.
113 *
114 * @param outState a Bundle into which this Activity should save its state
115 */
116 @Override
117 protected void onSaveInstanceState(Bundle outState) {
118 outState.putSerializable("gameState", mGameView.getThread().mGameState);
119 outState.putSerializable("playerWins", mGameView.getThread().mPlayerWins);
120 outState.putSerializable("playerLosses", mGameView.getThread().mPlayerLosses);
121
122 super.onSaveInstanceState(outState);
123 Log.w("Blackjack", "onSaveInstanceState called");
124 }
125
126 @Override
127 protected void onStop() {
128 System.exit(1);
129 super.onStop();
130 }
131}
Note: See TracBrowser for help on using the repository browser.