Advertisement
jonnern7

Untitled

Apr 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. package main;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.graphics.PixelFormat;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.Menu;
  9. import android.view.Window;
  10.  
  11. import java.util.EmptyStackException;
  12.  
  13. import controller.ChessBoardController;
  14. import model.Board;
  15. import sheep.game.Game;
  16. import sheep.game.State;
  17. import view.GameState;
  18. import view.MenuState;
  19. import view.SettingState;
  20.  
  21. public class MainActivity extends Activity {
  22.     private Game game;
  23.     private MenuState menuState;
  24.  
  25.     @Override
  26.     protected void onCreate(Bundle savedInstanceState){
  27.         super.onCreate(savedInstanceState);
  28.         Window window = getWindow();
  29.         game = new Game(this, null);
  30.         menuState = new MenuState(game);
  31.         setContentView(game);
  32.     }
  33.  
  34.     @Override
  35.     public void onResume(){
  36.         super.onResume();
  37.         game.pushState(menuState);
  38.     }
  39.  
  40.     /**
  41.      * Directs the user to the main menu if playing a game
  42.      * If pressed back in the menu, pause the app
  43.      */
  44.     @Override
  45.     public void onBackPressed() {
  46.         game.popState();
  47.         if(game.getPreviousState() == null){
  48.             super.onBackPressed();
  49.         }
  50.     }
  51.  
  52.     @Override
  53.     public void onPause(){
  54.         super.onPause();
  55.         while (game.getPreviousState() != null){
  56.             game.popState();
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement