private void increaseTime() { time += speed; if (time > animation.length) { time = time - animation.length; for (PlayerListener listener : listeners) listener.animationFinished(animation); } if (time < 0) { for (PlayerListener listener : listeners) listener.animationFinished(animation); time += animation.length; } }
/** * Sets the animation of this player. * * @param animation the new animation * @throws SpriterException if the animation is <code>null</code> or the current animation is not * a member of the current set entity */ public void setAnimation(Animation animation) { Animation prevAnim = this.animation; if (animation == this.animation) return; if (animation == null) throw new SpriterException("animation can not be null!"); if (!this.entity.containsAnimation(animation) && animation.id != -1) throw new SpriterException("animation has to be in the same entity as the current set one!"); if (animation != this.animation) time = 0; this.animation = animation; int tempTime = this.time; this.time = 0; this.update(); this.time = tempTime; for (PlayerListener listener : listeners) listener.animationChanged(prevAnim, animation); }
public void testPlayerVP() throws RulesBrokenException { PlayerColor blue = new PlayerColor("Blue", Color.blue, 'b'); Player p = new Player(blue, changeNo, mockConstraints); Achievement largestArmy = new Achievement("Largest Army", 2, "LH", 'l', "LargestArmy", 1); mockListener.playerVPChanged(new PlayerEvent(p)); expectLastCall().times(3); replay(mockListener); p.addPlayerListener(mockListener); p.setVP(10); p.add(largestArmy); p.remove(largestArmy); // check the remove works p.removePlayerListener(mockListener); // none of these should pass events to mockListener: p.setVP(12); p.add(largestArmy); p.remove(largestArmy); verify(mockListener); }
/** Test renaming of Players including checking events are raised */ public void testPlayerNaming() throws RulesBrokenException { PlayerColor blue = new PlayerColor("Blue", Color.blue, 'b'); Player p = new Player(blue, changeNo, mockConstraints); mockListener.playerRenamed(new PlayerEvent(p)); mockListener.playerRenamed(new PlayerEvent(p)); replay(mockListener); p.addPlayerListener(mockListener); // Check the default name works assertEquals(p.getName(), blue.toString()); // Can we change it (and does the right event fire?) p.setName("BLAH"); assertEquals(p.getName(), "BLAH"); // Back to where we started (along with another event) p.resetName(); assertEquals(p.getName(), blue.toString()); // Check the remove works (the next setName shouldn't send an event) p.removePlayerListener(mockListener); p.setName("MORE BLAHS"); verify(mockListener); }
/** * Updates this player. This means the current time gets increased by {@link #speed} and is * applied to the current animation. */ public void update() { for (PlayerListener listener : listeners) listener.preProcess(this); if (dirty) this.updateRoot(); this.animation.update(time, root); this.currentKey = this.animation.currentKey; if (prevKey != currentKey) { for (PlayerListener listener : listeners) listener.mainlineKeyChanged(prevKey, currentKey); prevKey = currentKey; } if (copyObjects) { tweenedKeys = tempTweenedKeys; unmappedTweenedKeys = tempUnmappedTweenedKeys; this.copyObjects(); } else { tweenedKeys = animation.tweenedKeys; unmappedTweenedKeys = animation.unmappedTweenedKeys; } for (Attachment attach : attachments) attach.update(); for (PlayerListener listener : listeners) listener.postProcess(this); this.increaseTime(); }
public void notify(PlayerListener listener) { listener.onPlayerMove(this); }