/* Objectmover.java * * Copyright (c) 2002 * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Anton Feldmann */ /** * This class (Objectmover) needs the classes Spielplan and Spielstand. * To work the Objectmover need some Methods. * * From Spielstand : * * - checkLagerplatz * - getSpielplan * - getPunkezaehler * * From Spielplan: * * - getPosition * - hasBox * - setPosition * - moveBox */ package org.gzigzag; public class Objectmover { ZZCell window; Spielplan spielplan; Spielstand spielstand; Punktezaehler punktezaehler; /** * This Konstructor of the class Objectmover make some exemplars of the classes ZZCell and Sielplan. */ public Objectmover( Spielstand s ) { spielstand = s; spielplan = s.getSpielplan(); punktezaehler = s.getPunktezaehler(); System.out.println("pz init: "+punktezaehler); } /** * This Mehtod give a ZZCell after is got the reacton of the Sokoban class. * The Socoban class get a Keyevent and the method move() knows the figur moved. * Now the Method look if the next and the overnext cell is empty. * If the cells are not the method try to find out if on both cells are boxes and if it is true; * the boxes don't move. If there is only on or no box the figure is move and the box in front * of the figure is moved in the way of the cell link. */ public void move( String dim, int dir ) { ZZCell c = spielplan.getPosition(); ZZCell next = c.s(dim,dir); if(next == null) { return; } else if(spielplan.hasBox(next)) { ZZCell after = next.s(dim, dir); if(after == null || spielplan.hasBox(after)) { return; } else { spielplan.moveBox(next, after); spielplan.setPosition(next); punktezaehler.moved(); spielstand.checkLagerplaetze(); } } else { spielplan.setPosition(next); punktezaehler.moved(); spielstand.checkLagerplaetze(); } } }