Guest User

Untitled

a guest
Jun 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package sokoban1;
  2.  
  3. import java.awt.event.KeyEvent;
  4.  
  5. import acm.program.GraphicsProgram;
  6.  
  7. public class Sokoban extends GraphicsProgram {
  8.    
  9.     private Game oGame;
  10.     private Levels oLevels = new Levels();
  11.  
  12.     private final int IMAGE_WIDTH = 16;
  13.     private final int IMAGE_HEIGHT = 16;
  14.  
  15.     /**
  16.      *
  17.      */
  18.     private static final long serialVersionUID = 1L;
  19.    
  20.     public void init(){
  21.         this.newGame();
  22.         addKeyListeners();
  23.     }
  24.    
  25.     @Override
  26.     public void run() {
  27.         super.run();
  28.         UpdateTable();
  29.     }
  30.    
  31.    
  32.     public void UpdateTable() {
  33.         this.removeAll();
  34.         int iHeight = this.oGame.getHeight();
  35.         int iWidth = this.oGame.getWidth();
  36.         for(int i = 0; i < iHeight; i++){
  37.             for(int j = 0; j < iWidth; j++){;
  38.                 try {
  39.                     this.add(this.oGame.getImageAt(i, j),j*IMAGE_WIDTH, i*IMAGE_HEIGHT);
  40.                 } catch (Exception e) {
  41.                 }
  42.             }
  43.         }
  44.     }
  45.    
  46.     @Override
  47.     public void keyPressed(KeyEvent e) {
  48.         oGame.move(e.getKeyCode());
  49.         if (oGame.isDone()) {
  50.             this.newGame();
  51.         }
  52.         UpdateTable();
  53.     }
  54.    
  55.     protected void newGame() {
  56.         try {
  57.             this.oGame = new Game(this.oLevels.getNext());
  58.            
  59.         } catch (Exception e) {
  60.             print(e.getMessage());
  61.         }
  62.     }
  63.  
  64. }
Add Comment
Please, Sign In to add comment