source: advance-wars/src/com/example/advancewars/Game.java@ 90838a1

Last change on this file since 90838a1 was dd3e793, checked in by sdanshin <devnull@…>, 14 years ago

Created a blank window where the main menu should be. Touching the screen shows the screen with the blue and green grid.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1package com.example.advancewars;
2
3import com.example.advancewars.R;
4import com.example.advancewars.GameView;
5import com.example.advancewars.GameView.DrawingThread;
6import android.app.Activity;
7import android.os.Bundle;
8import android.util.Log;
9import android.view.Menu;
10import android.view.MenuItem;
11import android.view.Window;
12import android.widget.TextView;
13import java.io.*;
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 case MENU_NEW:
55 break;
56 }
57
58 return true;
59 }
60
61 /**
62 * Invoked when the Activity is created.
63 *
64 * @param savedInstanceState a Bundle containing state saved from a previous
65 * execution, or null if this is a new execution
66 */
67 @Override
68 protected void onCreate(Bundle savedInstanceState) {
69 Log.w("Blackjack", "We're inside onCreate");
70
71 super.onCreate(savedInstanceState);
72
73 Log.w("Blackjack", "the super constructor was called successfully");
74
75 // turn off the window's title bar
76 requestWindowFeature(Window.FEATURE_NO_TITLE);
77
78 // tell system to use the layout defined in our XML file
79 setContentView(R.layout.main);
80
81 mGameView = (GameView) findViewById(R.id.lunar);
82 mThread = mGameView.getThread();
83
84 mGameView.setTextView((TextView) findViewById(R.id.text));
85
86 if (savedInstanceState == null) { // we were just launched: set up a new game
87 Log.w("Blackjack", "SIS is null");
88
89 mThread.setState(AppState.RUNNING);
90 } else {
91 Log.w("Blackjack", "SIS is nonnull");
92
93 mThread.setState(AppState.RUNNING);
94
95 mGameView.getThread().mGameState = (GameState)savedInstanceState.getSerializable("gameState");
96
97 mGameView.getThread().mPlayerWins = savedInstanceState.getInt("playerWins");
98 mGameView.getThread().mPlayerLosses = savedInstanceState.getInt("playerLosses");
99 }
100 }
101
102 /**
103 * Invoked when the Activity loses user focus.
104 */
105 @Override
106 protected void onPause() {
107 super.onPause();
108 mGameView.getThread().pause(); // pause game when Activity pauses
109 }
110
111 /**
112 * Notification that something is about to happen, to give the Activity a
113 * chance to save state.
114 *
115 * @param outState a Bundle into which this Activity should save its state
116 */
117 @Override
118 protected void onSaveInstanceState(Bundle outState) {
119 outState.putSerializable("gameState", mGameView.getThread().mGameState);
120 outState.putSerializable("playerWins", mGameView.getThread().mPlayerWins);
121 outState.putSerializable("playerLosses", mGameView.getThread().mPlayerLosses);
122
123 super.onSaveInstanceState(outState);
124 Log.w("Blackjack", "onSaveInstanceState called");
125 }
126
127 @Override
128 protected void onStop() {
129 System.exit(1);
130 super.onStop();
131 }
132}
Note: See TracBrowser for help on using the repository browser.