Package org.jpacman.framework.controller

Source Code of org.jpacman.framework.controller.RandomGhostMover

package org.jpacman.framework.controller;

import org.jpacman.framework.model.Ghost;
import org.jpacman.framework.model.IGameInteractor;
import org.jpacman.framework.model.Direction;


/**
* Example, simple ghost mover that just moves ghosts randomly.
*
* @author Arie van Deursen; Aug 18, 2003
*/
public class RandomGhostMover extends AbstractGhostMover {

    /**
     * Start a new mover with the given engine.
     *
     * @param theEngine Engine used.
     */
    public RandomGhostMover(final IGameInteractor theEngine) {
        super(theEngine);
    }

    /**
     * Actually conduct a random move in the underlying engine.
     */
    public void doTick() {
        synchronized (gameInteraction()) {
            Ghost theGhost = getRandomGhost();
            if (theGhost == null) {
                return;
            }
            int dirIndex = getRandomizer().nextInt(Direction.values().length);
            final Direction dir = Direction.values()[dirIndex];
            gameInteraction().moveGhost(theGhost, dir);
        }
    }
}
TOP

Related Classes of org.jpacman.framework.controller.RandomGhostMover

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.