Created
November 4, 2012 19:55
-
-
Save Afforess/4013360 to your computer and use it in GitHub Desktop.
Death Cause Factory pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum DeathCause implements DeathCauseFactory { | |
DROWNING { | |
public Cause<?> buildCause(Entity victim, Entity killer) { | |
return new DrowningCause(victim); | |
} | |
}, | |
FALLING { | |
public Cause<?> buildCause(Entity victim, Entity killer) { | |
//TODO | |
} | |
}, | |
FIRE { | |
public Cause<?> buildCause(Entity victim, Entity killer) { | |
//TODO | |
} | |
}, | |
ARROW { | |
public Cause<?> buildCause(Entity victim, Entity killer) { | |
return new ProjectileCause(victim, killer); | |
} | |
}, | |
SKELETON, | |
... | |
; | |
} | |
interface DeathCauseFactory { | |
public Cause<?> buildCause(Entity victim, Entity killer); | |
} | |
class DrowningCause extends PlayerCause { | |
public DrowningCause(Player p) { | |
super(p); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment