Changeset 113d7cf in advance-wars for src/com/medievaltech/advancewars/Game.java


Ignore:
Timestamp:
May 9, 2011, 6:23:05 PM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
bdd63ba
Parents:
ae564dc
Message:

Implemented saving/loading of the map and the units on it. Also did some package refactoring (renamed com.medievaltech.game to com.medievaltech.unit and moved some classes into com.medievaltech.advancewars)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/com/medievaltech/advancewars/Game.java

    rae564dc r113d7cf  
    11package com.medievaltech.advancewars;
    22
    3 import com.medievaltech.advancewars.R;
    4 import com.medievaltech.advancewars.GameView;
     3import java.io.*;
     4
    55import com.medievaltech.advancewars.GameView.DrawingThread;
    66
     
    1414
    1515public class Game extends Activity {
    16     private static final int MENU_EXIT = 1;
    17     private static final int MENU_NEW = 2;
     16        private static final int MENU_SAVE = 1;
     17        private static final int MENU_MAIN = 2;
     18    private static final int MENU_EXIT = 3;
    1819   
    1920    public enum State{BUST, ACTIVE, DOUBLEDOWN};
     
    3536        super.onCreateOptionsMenu(menu);
    3637
     38        menu.add(0, MENU_SAVE, 0, R.string.menu_save);
     39        menu.add(0, MENU_MAIN, 0, R.string.menu_main);
    3740        menu.add(0, MENU_EXIT, 0, R.string.menu_exit);
    3841        return true;
     
    4952    public boolean onOptionsItemSelected(MenuItem item) {
    5053        switch (item.getItemId()) {
     54                case MENU_SAVE:
     55                        try {
     56                                PrintWriter p = new PrintWriter(new FileWriter(android.os.Environment.getExternalStorageDirectory()+"/save.txt"));
     57                                mThread.mMap.save(p);
     58                                p.close();
     59                        }catch(IOException ioe) {
     60                                ioe.printStackTrace();
     61                        }
     62                        break;
     63                case MENU_MAIN:
     64                        mThread.mGameState = GameState.MAIN_MENU;
     65                        break;
    5166            case MENU_EXIT:
    52                 this.finish();
     67                finish();
    5368                break;
    5469        }
     
    93108           
    94109            mGameView.getThread().mGameState = (GameState)savedInstanceState.getSerializable("gameState");
    95            
    96                     mGameView.getThread().mPlayerWins = savedInstanceState.getInt("playerWins");
    97                     mGameView.getThread().mPlayerLosses = savedInstanceState.getInt("playerLosses");
    98110        }
    99111    }
     
    117129    protected void onSaveInstanceState(Bundle outState) {
    118130        outState.putSerializable("gameState", mGameView.getThread().mGameState);
    119             outState.putSerializable("playerWins", mGameView.getThread().mPlayerWins);
    120             outState.putSerializable("playerLosses", mGameView.getThread().mPlayerLosses);
    121            
     131       
    122132        super.onSaveInstanceState(outState);
    123         Log.w("Blackjack", "onSaveInstanceState called");
     133        Log.w("AdvanceWars", "onSaveInstanceState called");
    124134    }
    125135   
Note: See TracChangeset for help on using the changeset viewer.