From 5c0f253d5d59a042f57c4cb209092729ece8a310 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 8 Mar 2009 17:59:07 -0400 Subject: Engine: Commented a lot of code --- .../fourisland/fourpuzzle/PuzzleApplication.java | 43 ++++++++++-- .../fourpuzzle/gamestate/GameOverGameState.java | 10 +++ .../fourpuzzle/gamestate/TitleScreenGameState.java | 82 +++++++++++++--------- .../fourpuzzle/gamestate/mapview/ChipSet.java | 8 ++- .../fourpuzzle/gamestate/mapview/Map.java | 7 +- .../gamestate/mapview/MapViewGameState.java | 59 ++++++++++++++-- .../gamestate/mapview/event/AbstractEvent.java | 41 +++++++++-- .../mapview/event/specialmove/MoveEventThread.java | 2 +- src/com/fourisland/fourpuzzle/util/Functions.java | 66 ----------------- 9 files changed, 199 insertions(+), 119 deletions(-) delete mode 100755 src/com/fourisland/fourpuzzle/util/Functions.java (limited to 'src/com/fourisland') diff --git a/src/com/fourisland/fourpuzzle/PuzzleApplication.java b/src/com/fourisland/fourpuzzle/PuzzleApplication.java index 16de273..36dda19 100755 --- a/src/com/fourisland/fourpuzzle/PuzzleApplication.java +++ b/src/com/fourisland/fourpuzzle/PuzzleApplication.java @@ -43,9 +43,16 @@ public class PuzzleApplication extends Application { private void initGameDialog(boolean undecorated) { + /* Because the game form is accessed from many places at once, a + * Semaphore is used to control access to it */ gameDialogHandler.acquireUninterruptibly(); + /* If the dialog is already visible (for instance, when changing the + * from full screen mode to windowed or vice versa while the program is + * running), it has to be closed so it can be reinitalized */ gameDialog.setVisible(false); + + // Set up the actual dialog Container contentPane = gameDialog.getContentPane(); gameDialog = new JDialog(new JFrame(), false); gameDialog.setContentPane(contentPane); @@ -76,6 +83,9 @@ public class PuzzleApplication extends Application { { if (e.getKeyCode() == KeyEvent.VK_F4) { + /* The user is trying to switch the full screen mode; flip + * the status switch, reinitalize the dialog and then tell + * the GraphicsEnvironment what's happening */ stretchScreen = !stretchScreen; if (stretchScreen) @@ -88,20 +98,24 @@ public class PuzzleApplication extends Application { } } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) { + /* If debug mode is enabled, holding Shift down should put + * the game into hyperactive mode */ if (INSTANCE.getContext().getResourceMap().getBoolean("debugMode")) { debugSpeed = true; } - } else { - KeyboardInput.getKey().keyInput(e); - } + } else { + // If anything else is pressed, let the GameState handle it + KeyboardInput.getKey().keyInput(e); } + } @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SHIFT) { + // If Shift is let go of, hyperactive mode should end debugSpeed = false; } else { KeyboardInput.getKey().letGo(); @@ -110,30 +124,44 @@ public class PuzzleApplication extends Application { }); gameDialog.setVisible(true); + // As we're done with the game dialog, we can release the permit gameDialogHandler.release(); } @Override - protected void startup() { + protected void startup() + { INSTANCE = this; + // Create the game form initGameDialog(true); - + + // The game should start out in full screen mode GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(gameDialog); + // Create the game cycle and run it new Thread(new Runnable() { public void run() { try { Audio.init(); SystemGraphic.initalize(); + // The game starts with the Title Screen Game.setGameState(new TitleScreenGameState()); - + + /* The game cycle should run every tick (unless hyperactive + * mode is enabled, when it should run constantly */ Interval in = Interval.createTickInterval(1); while (true) { + /* If the game window is deactivated, the game should + * pause execution */ if (in.isElapsed() && !gameSleep) { + /* If there is currently a transition running, the + * only necessary function is rendering, otherwise + * process keyboard input and run GameState-specific + * game cycle code too */ if (!Display.isTransitionRunning()) { KeyboardInput.processInput(); @@ -141,6 +169,9 @@ public class PuzzleApplication extends Application { Game.getGameState().doGameCycle(); } + /* Now, render to the game dialog. Note that as it + * is used in many places, a Semaphore permit is + * required before rendering can start */ gameDialogHandler.acquireUninterruptibly(); Display.render(gameDialog.getContentPane()); gameDialogHandler.release(); diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java index ed379cc..7466788 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java @@ -24,11 +24,13 @@ public class GameOverGameState implements GameState { public void initalize() { + // Play the Database-specifed Game Over music Audio.playMusic(Database.getMusic(Music.GameOver)); } public void deinitalize() { + // Stop the music Audio.stopMusic(); } @@ -36,6 +38,13 @@ public class GameOverGameState implements GameState { { if (key.isActionDown()) { + /* When the user presses the action key to exit the game over + * screen, clear the save data and transition back to the title + * screen. + * + * NOTE: Clearing the save data may not actually be necessary here + * because TitleScreenGameState clears the save data before starting + * a new file */ Game.setSaveFile(new SaveFile()); try { @@ -53,6 +62,7 @@ public class GameOverGameState implements GameState { public void render(Graphics2D g) { + // Display the Game Over picture g.drawImage(ObjectLoader.getImage("Picture", "GameOver"), 0, 0, null); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index db6225e..6cfa829 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java @@ -30,8 +30,13 @@ public class TitleScreenGameState implements GameState { public void initalize() { + /* Play the Database-specified Title Screen music, which the client can + * change */ Audio.playMusic(Database.getMusic(Music.Title)); + /* Create the choice window, whose options are also taken from the + * Database. Then tell Display to render it and KeyboardInput to send + * keyboard events to it */ choices = new ChoiceWindow.Builder(Arrays.asList(Database.getVocab(Vocabulary.NewGame), Database.getVocab(Vocabulary.LoadGame), Database.getVocab(Vocabulary.EndGame)), ChoiceWindow.ChoiceWindowLocation.BottomLeft) .center(true) .build(); @@ -41,8 +46,10 @@ public class TitleScreenGameState implements GameState { public void deinitalize() { + // Stop the music because the title screen is closing Audio.stopMusic(); + // Also tell Display and KeyboardInput to forget about our ChoiceWindow Display.unregisterRenderable(choices); KeyboardInput.unregisterInputable(choices); } @@ -50,47 +57,57 @@ public class TitleScreenGameState implements GameState { PauseTimer pt = new PauseTimer(0); public void processInput(KeyInput key) { - if (pt.isElapsed()) + if (key.isActionDown()) { - if (key.isActionDown()) + /* If the player presses the action key, play the selection sound + * and act upon the choice they selected */ + Audio.playSound(Database.getSound(Sound.Selection)); + + if (choices.getSelected().equals(Database.getVocab(Vocabulary.NewGame))) { - Audio.playSound(Database.getSound(Sound.Selection)); - - if (choices.getSelected().equals(Database.getVocab(Vocabulary.NewGame))) - { - Game.setSaveFile(new SaveFile()); - - try { - Display.transition(Database.getTransition(Transitions.Generic), new MapViewGameState("TestMap", 1, 2), true); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.LoadGame))) - { - // Do nothing, yet - } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.EndGame))) - { - new Thread(new Runnable() { - public void run() { - try { - Display.transition(Database.getTransition(Transitions.Generic).getOutTransition()); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - - System.exit(0); - } - }).start(); + /* If the player starts a new game, set the save data to a blank + * instance */ + Game.setSaveFile(new SaveFile()); + + // Then transition to the map where the game starts + try { + Display.transition(Database.getTransition(Transitions.Generic), new MapViewGameState("TestMap", 1, 2), true); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); } - } else if (key.getKey() == KeyEvent.VK_UP) + } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.LoadGame))) + { + // Do nothing, yet + } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.EndGame))) + { + // End the game, but transition out before doing so + new Thread(new Runnable() { + public void run() { + try { + Display.transition(Database.getTransition(Transitions.Generic).getOutTransition()); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + + System.exit(0); + } + }).start(); + } + } else if (pt.isElapsed()) + { + if (key.getKey() == KeyEvent.VK_UP) { + /* Tell ChoiceWindow that the player wants to move up, then + * wait a second before allowing any more vertical movement so + * that the player has a chance to let go of the up key */ choices.moveUp(); - pt.setTimer(1); } else if (key.getKey() == KeyEvent.VK_DOWN) { + /* Tell ChoiceWindow that the player wants to move down, then + * wait a second before allowing any more vertical movement so + * that the player has a chance to let go of the down key */ choices.moveDown(); - pt.setTimer(1); } } @@ -103,6 +120,7 @@ public class TitleScreenGameState implements GameState { public void render(Graphics2D g) { + // Display the title screen picture g.drawImage(ObjectLoader.getImage("Picture", "Title"), 0, 0, null); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java index ddf7c94..a4d7ac3 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java @@ -10,11 +10,8 @@ import com.fourisland.fourpuzzle.PuzzleApplication; import com.fourisland.fourpuzzle.util.ObjectLoader; import com.fourisland.fourpuzzle.util.ResourceNotFoundException; import java.awt.image.BufferedImage; -import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.URISyntaxException; -import java.net.URL; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -26,6 +23,11 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; /** + * ChipSet stores information about the tilesets for mapview. + * + * I'm not really going to comment this class much yet because it currently + * parses Tiled-created chipset files and this is all going to be rewritten + * once I've written my own map editor. * * @author hatkirby */ diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index 33a8516..8b262dd 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java @@ -116,7 +116,8 @@ public class Map { { int x = ev.getLocation().x; int y = ev.getLocation().y; - + + // Check if the event is trying to move over the map boundaries if ((toMove == Direction.North) && (y == 0)) { return true; @@ -131,11 +132,14 @@ public class Map { return true; } + /* If the event is the hero and walkthrough is enabled, bypass the rest + * of the collision-checking */ if ((ev instanceof HeroEvent) && (((MapViewGameState) Game.getGameState()).debugWalkthrough)) { return false; } + // Check for layer events in the specified direction if ((toMove == Direction.North) && (checkForEventCollision(x, y-1))) { return true; @@ -156,6 +160,7 @@ public class Map { return true; } + // Check for obstructions on the map itself in the specified direction ChipSet cSI = ChipSet.getChipSet(chipSet); HashMap cSID = cSI.getChipSetData(); for (HashMap mapArea : getMapData()) diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 7635839..ec35db6 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java @@ -25,7 +25,6 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventTh import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint; import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; import com.fourisland.fourpuzzle.gamestate.menu.MenuGameState; -import com.fourisland.fourpuzzle.util.Functions; import java.awt.Graphics2D; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; @@ -44,14 +43,23 @@ public class MapViewGameState implements GameState { public MapViewGameState(String map, int x, int y) { + // Load the specified map into memory setCurrentMap(map); + + // Place the Hero at the specified location Game.getSaveFile().getHero().setLocation(x, y); + + // Create a new viewpoint for the map currentViewpoint = new AutomaticViewpoint(currentMap); + + // Tell SpecialEvent about the new map so it can access it SpecialEvent.setMapView(this); } public void initalize() { + /* Depending on the specified music type, either play music, stop the + * music or let the already playing music continue */ switch (currentMap.getMusicType()) { case NoMusic: Audio.stopMusic(); break; @@ -67,8 +75,11 @@ public class MapViewGameState implements GameState { public void processInput(KeyInput key) { + // Store the hero event in a local variable as it is used often HeroEvent hero = Game.getSaveFile().getHero(); + /* If debug mode is enabled and the control key is held down, set the + * walkthrough flag so the Hero can walk through stuff */ if (key.isCtrlDown() && !debugWalkthrough) { if (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode")) @@ -79,11 +90,14 @@ public class MapViewGameState implements GameState { debugWalkthrough = false; } + /* If the hero is not moving or the center of a MoveEvent action and no + * blocking special events are running, check the user input */ if (!hero.isMoving() && !MoveEventThread.isHeroActive() && !EventHandler.isRunningEvent()) { Direction toMove = null; Boolean letsMove = false; + // Translate the key input into the appropriate direction switch (key.getKey()) { case KeyEvent.VK_UP: @@ -104,17 +118,22 @@ public class MapViewGameState implements GameState { break; } + // If a movement key was indeed pressed, process it if (letsMove) { + // Try to move the hero in the specified direction if (!hero.startMoving(toMove)) { + /* If the hero is blocked in that direction, check to see + * if a middle-layer OnHeroTouch event is the blocker, if + * so, execute it */ for (LayerEvent ev : currentMap.getEvents()) { if (ev.getCalltime() == EventCallTime.OnHeroTouch) { if (ev.getLayer() == Layer.Middle) { - if (Functions.isFacing(hero, ev)) + if (hero.getDirection().to(hero.getLocation()).equals(ev.getLocation())) { ev.getCallback().activate(ev.getCalltime()); } @@ -124,6 +143,8 @@ public class MapViewGameState implements GameState { } } + /* If the player presses the action key, check if either of the two + * PushKey conditions are available */ if (key.isActionDown()) { for (LayerEvent ev : currentMap.getEvents()) @@ -132,12 +153,16 @@ public class MapViewGameState implements GameState { { if (ev.getLayer() == Layer.Middle) { - if (Functions.isFacing(hero, ev)) + /* If the event is middle-layered and the hero is + * facing it, execute it */ + if (hero.getDirection().to(hero.getLocation()).equals(ev.getLocation())) { ev.setDirection(hero.getDirection().opposite()); ev.getCallback().activate(ev.getCalltime()); } } else { + /* If the event is not middle-layered and the hero + * is on it, execute it */ if (ev.getLocation().equals(hero.getLocation())) { ev.getCallback().activate(ev.getCalltime()); @@ -146,7 +171,8 @@ public class MapViewGameState implements GameState { } } } - + + // If the player presses the escape key, open the menu if (key.getKey() == KeyEvent.VK_ESCAPE) { try { @@ -159,6 +185,8 @@ public class MapViewGameState implements GameState { if (EventHandler.isRunningEvent()) { + /* If debug mode is enabled and F11 is pressed, cancel any running + * events */ if ((key.getKey() == KeyEvent.VK_F11) && (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode"))) { for (LayerEvent ev : currentMap.getEvents()) @@ -171,11 +199,15 @@ public class MapViewGameState implements GameState { public void doGameCycle() { + // Store the hero event in a local variable as it is used often HeroEvent hero = Game.getSaveFile().getHero(); if (hero.isMoving()) { + // If the player is in the process of moving, continue it hero.processMoving(); + /* If the player has just finished moving, check for a non + * middle-layered OnHeroTouch on the Hero and execute it */ if (!hero.isMoving()) { for (LayerEvent ev : currentMap.getEvents()) @@ -198,6 +230,10 @@ public class MapViewGameState implements GameState { { if (!ev.isMoving()) { + /* If one of the map's layer events aren't moving or being + * processed by a MoveEvent action and no blocking special + * events are running, start it moving in the direction provided + * by its MovementType */ if (!MoveEventThread.isOtherActive(ev)) { if (!EventHandler.isRunningEvent()) @@ -206,23 +242,28 @@ public class MapViewGameState implements GameState { } } } else { + // If the event IS moving, process the movement ev.processMoving(); } if (ev.getCalltime() == EventCallTime.ParallelProcess) { + // If the event is a ParallelProcess, execute it ev.getCallback().activate(ev.getCalltime()); } } } public void render(Graphics2D g) - { + { + // Ask the current viewpoint where to render from int x = currentViewpoint.getX(); int y = currentViewpoint.getY(); + // Render the lower layer of the map g.drawImage(currentMap.renderLower(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); + // Render each lower and middle layered event onto a seperate canvas BufferedImage eventLayer = Display.createCanvas(currentMap.getSize().width*16, currentMap.getSize().height*16); Graphics2D g2 = eventLayer.createGraphics(); EventList events = currentMap.getEvents(); @@ -235,8 +276,10 @@ public class MapViewGameState implements GameState { } } + // Render the hero event onto the event canvas Game.getHeroEvent().render(g2); + // Render each above layered event onto the event canvas for (LayerEvent event : events) { if (event.getLayer() == Layer.Above) @@ -245,13 +288,19 @@ public class MapViewGameState implements GameState { } } + // Render the event canvas g.drawImage(eventLayer, 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); + + // Render the upper layer of the map g.drawImage(currentMap.renderUpper(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); } public void setCurrentMap(String mapName) { + // Tell the save data what map is currently loaded Game.getSaveFile().setCurrentMap(mapName); + + // Load the specified map from the database currentMap = Database.getMap(mapName); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index f859739..e9482f9 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java @@ -7,7 +7,6 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event; import com.fourisland.fourpuzzle.Direction; import com.fourisland.fourpuzzle.gamestate.mapview.Map; -import com.fourisland.fourpuzzle.util.Functions; import com.fourisland.fourpuzzle.util.Interval; import java.awt.Point; import java.util.ArrayList; @@ -46,22 +45,38 @@ public abstract class AbstractEvent implements Event { private int moveTimer; public boolean startMoving(Direction toMove) { + /* If the event is already moving (sometimes it manages to slip through + * the other filters), simply return without doing anything */ if (isMoving()) { return false; } + /* Attempt to turn in the correct direction and then check if it was + * done. It could fail in certain cases which would mean the event + * shouldn't move, for instance, if a LayerEvent's AnimationType was + * FixedGraphic. + * + * There is a slight problem with this, however. Currently, if the + * AnimationType is FixedGraphic, but the event is already facing the + * correct direction, the event will move anyway, despite being fixed */ setDirection(toMove); - if (getDirection() != toMove) { return false; } + /* Make sure that there are no present obstructions on the map in the + * specified direction */ if (!getParentMap().checkForCollision(this, toMove)) { + // Start the stepping animation setAnimationStep(2); + + // Ask the event's MoveSpeed for the length of the animation moveTimer = getMoveSpeed().getSpeed(); + + // Set the moving flag setMoving(true); return true; @@ -75,17 +90,25 @@ public abstract class AbstractEvent implements Event { { if (isMoving()) { + // Movement should be processed every half tick if (in.isElapsed()) { + // Decrement the move timer moveTimer--; + if (moveTimer <= 0) { + /* If movement has finished, stop the animation and unset + * the moving flag */ setAnimationStep(1); setMoving(false); + + // Move the event to the correct location setLocation(getDirection().to(getLocation())); } else if (moveTimer <= (getMoveSpeed().getSpeed() / 2)) { - setAnimationStep(0); + // If movement is half-complete, advance its animation + setAnimationStep(0); } } } @@ -93,14 +116,22 @@ public abstract class AbstractEvent implements Event { public boolean isOccupyingSpace(int x, int y) { + // Check if the event occupies the given location if (getLocation().equals(new Point(x,y))) { return true; } - if (Functions.isMovingTo(this, x, y)) + /* Because a moving event technically occupies two locations, we also + * need to check if the given location is where the event is moving to + * (if it's moving at all) */ + if (isMoving()) { - return true; + Point loc = getDirection().to(getLocation()); + if ((loc.x == x) && (loc.y == y)) + { + return true; + } } return false; diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java index 233c415..d05a3d8 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java @@ -39,7 +39,7 @@ public class MoveEventThread implements Runnable { public void start() { - for (Future f : eventThreads) + for (Future f : new ArrayList(eventThreads)) { if (f.isDone()) { diff --git a/src/com/fourisland/fourpuzzle/util/Functions.java b/src/com/fourisland/fourpuzzle/util/Functions.java deleted file mode 100755 index c7c1243..0000000 --- a/src/com/fourisland/fourpuzzle/util/Functions.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.fourisland.fourpuzzle.util; - -import com.fourisland.fourpuzzle.Direction; -import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; - -/** - * - * @author hatkirby - */ -public class Functions { - - public static boolean isFacing(Event ev1, Event ev2) - { - if ((ev1.getDirection() == Direction.North) && (ev2.getLocation().x == ev1.getLocation().x) && (ev2.getLocation().y == (ev1.getLocation().y - 1))) - { - return true; - } else if ((ev1.getDirection() == Direction.West) && (ev2.getLocation().x == (ev1.getLocation().x - 1)) && (ev2.getLocation().y == ev1.getLocation().y)) - { - return true; - } else if ((ev1.getDirection() == Direction.South) && (ev2.getLocation().x == ev1.getLocation().x) && (ev2.getLocation().y == (ev1.getLocation().y + 1))) - { - return true; - } else if ((ev1.getDirection() == Direction.East) && (ev2.getLocation().x == (ev1.getLocation().x + 1)) && (ev2.getLocation().y == ev1.getLocation().y)) - { - return true; - } - - return false; - } - - public static boolean isMovingTo(Event ev, int x, int y) - { - if (ev.isMoving() == false) - { - return false; - } - - if ((ev.getDirection() == Direction.North) && ((ev.getLocation().y-1) == y) && (ev.getLocation().x == x)) - { - return true; - } - - if ((ev.getDirection() == Direction.West) && (ev.getLocation().y == y) && ((ev.getLocation().x-1) == x)) - { - return true; - } - - if ((ev.getDirection() == Direction.South) && ((ev.getLocation().y+1) == y) && (ev.getLocation().x == x)) - { - return true; - } - - if ((ev.getDirection() == Direction.East) && (ev.getLocation().y == y) && ((ev.getLocation().x+1) == x)) - { - return true; - } - - return false; - } - -} -- cgit 1.4.1