[abe7b3d] | 1 | package com.medievaltech.advancewars;
|
---|
| 2 |
|
---|
[113d7cf] | 3 | import java.io.*;
|
---|
| 4 |
|
---|
[5d9e7bb] | 5 | import android.app.Activity;
|
---|
| 6 | import android.os.Bundle;
|
---|
| 7 | import android.util.Log;
|
---|
| 8 | import android.view.Menu;
|
---|
| 9 | import android.view.MenuItem;
|
---|
| 10 | import android.view.Window;
|
---|
| 11 |
|
---|
[379005b] | 12 | import com.medievaltech.advancewars.Enum.*;
|
---|
| 13 |
|
---|
[5d9e7bb] | 14 | public class Game extends Activity {
|
---|
[4666fae] | 15 |
|
---|
[5d9e7bb] | 16 | /**
|
---|
| 17 | * Invoked during init to give the Activity a chance to set up its Menu.
|
---|
| 18 | *
|
---|
| 19 | * @param menu the Menu to which entries may be added
|
---|
| 20 | * @return true
|
---|
| 21 | */
|
---|
| 22 | @Override
|
---|
| 23 | public boolean onCreateOptionsMenu(Menu menu) {
|
---|
| 24 | super.onCreateOptionsMenu(menu);
|
---|
| 25 |
|
---|
[fea4b77] | 26 | menu.add(0, MenuOption.END_TURN.ordinal(), 0, R.string.menu_end_turn);
|
---|
| 27 | menu.add(0, MenuOption.SAVE.ordinal(), 0, R.string.menu_save);
|
---|
| 28 | menu.add(0, MenuOption.MAIN.ordinal(), 0, R.string.menu_main);
|
---|
| 29 | menu.add(0, MenuOption.EXIT.ordinal(), 0, R.string.menu_exit);
|
---|
[5d9e7bb] | 30 | return true;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * Invoked when the user selects an item from the Menu.
|
---|
| 35 | *
|
---|
| 36 | * @param item the Menu entry which was selected
|
---|
| 37 | * @return true if the Menu item was legit (and we consumed it), false
|
---|
| 38 | * otherwise
|
---|
| 39 | */
|
---|
| 40 | @Override
|
---|
| 41 | public boolean onOptionsItemSelected(MenuItem item) {
|
---|
[fea4b77] | 42 | int i = item.getItemId();
|
---|
| 43 |
|
---|
| 44 | if(i == MenuOption.END_TURN.ordinal()) {
|
---|
[4666fae] | 45 | Static.turn = Turn.ENEMY_TURN;
|
---|
[fea4b77] | 46 | }else if(i == MenuOption.SAVE.ordinal()) {
|
---|
| 47 | try {
|
---|
| 48 | PrintWriter p = new PrintWriter(new FileWriter(android.os.Environment.getExternalStorageDirectory()+"/save.txt"));
|
---|
[41c11dd] | 49 | Static.map.save(p);
|
---|
[fea4b77] | 50 | p.close();
|
---|
| 51 | }catch(IOException ioe) {
|
---|
| 52 | ioe.printStackTrace();
|
---|
| 53 | }
|
---|
| 54 | }else if(i == MenuOption.MAIN.ordinal()) {
|
---|
[4666fae] | 55 | Static.gameState = GameState.MAIN_MENU;
|
---|
[fea4b77] | 56 | }else if(i == MenuOption.EXIT.ordinal()) {
|
---|
| 57 | finish();
|
---|
[5d9e7bb] | 58 | }
|
---|
| 59 |
|
---|
| 60 | return true;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * Invoked when the Activity is created.
|
---|
| 65 | *
|
---|
| 66 | * @param savedInstanceState a Bundle containing state saved from a previous
|
---|
| 67 | * execution, or null if this is a new execution
|
---|
| 68 | */
|
---|
| 69 | @Override
|
---|
| 70 | protected void onCreate(Bundle savedInstanceState) {
|
---|
[205f525] | 71 | Log.w("AdvanceWars", "We're inside onCreate");
|
---|
[5d9e7bb] | 72 |
|
---|
| 73 | super.onCreate(savedInstanceState);
|
---|
| 74 |
|
---|
[205f525] | 75 | Log.w("AdvanceWars", "the super constructor was called successfully");
|
---|
[5d9e7bb] | 76 |
|
---|
| 77 | // turn off the window's title bar
|
---|
| 78 | requestWindowFeature(Window.FEATURE_NO_TITLE);
|
---|
| 79 |
|
---|
| 80 | // tell system to use the layout defined in our XML file
|
---|
| 81 | setContentView(R.layout.main);
|
---|
| 82 |
|
---|
[4666fae] | 83 | Static.game = this;
|
---|
[5d9e7bb] | 84 |
|
---|
| 85 | if (savedInstanceState == null) { // we were just launched: set up a new game
|
---|
[205f525] | 86 | Log.w("AdvanceWars", "SIS is null");
|
---|
[5d9e7bb] | 87 | } else {
|
---|
[205f525] | 88 | Log.w("AdvanceWars", "SIS is nonnull");
|
---|
[5d9e7bb] | 89 |
|
---|
[4666fae] | 90 | Static.gameState = (GameState)savedInstanceState.getSerializable("gameState");
|
---|
[5d9e7bb] | 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | /**
|
---|
| 95 | * Notification that something is about to happen, to give the Activity a
|
---|
| 96 | * chance to save state.
|
---|
| 97 | *
|
---|
| 98 | * @param outState a Bundle into which this Activity should save its state
|
---|
| 99 | */
|
---|
| 100 | @Override
|
---|
| 101 | protected void onSaveInstanceState(Bundle outState) {
|
---|
[4666fae] | 102 | outState.putSerializable("gameState", Static.gameState);
|
---|
[113d7cf] | 103 |
|
---|
[5d9e7bb] | 104 | super.onSaveInstanceState(outState);
|
---|
[113d7cf] | 105 | Log.w("AdvanceWars", "onSaveInstanceState called");
|
---|
[5d9e7bb] | 106 | }
|
---|
| 107 |
|
---|
| 108 | @Override
|
---|
| 109 | protected void onStop() {
|
---|
| 110 | System.exit(1);
|
---|
| 111 | super.onStop();
|
---|
| 112 | }
|
---|
| 113 | } |
---|