Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sokoban1;
- import java.awt.event.KeyEvent;
- import acm.program.GraphicsProgram;
- public class Sokoban extends GraphicsProgram {
- private Game oGame;
- private Levels oLevels = new Levels();
- private final int IMAGE_WIDTH = 16;
- private final int IMAGE_HEIGHT = 16;
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- public void init(){
- this.newGame();
- addKeyListeners();
- }
- @Override
- public void run() {
- super.run();
- UpdateTable();
- }
- public void UpdateTable() {
- this.removeAll();
- int iHeight = this.oGame.getHeight();
- int iWidth = this.oGame.getWidth();
- for(int i = 0; i < iHeight; i++){
- for(int j = 0; j < iWidth; j++){;
- try {
- this.add(this.oGame.getImageAt(i, j),j*IMAGE_WIDTH, i*IMAGE_HEIGHT);
- } catch (Exception e) {
- }
- }
- }
- }
- @Override
- public void keyPressed(KeyEvent e) {
- oGame.move(e.getKeyCode());
- if (oGame.isDone()) {
- this.newGame();
- }
- UpdateTable();
- }
- protected void newGame() {
- try {
- this.oGame = new Game(this.oLevels.getNext());
- } catch (Exception e) {
- print(e.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment