Skip to content

Instantly share code, notes, and snippets.

@dredhorse
Forked from Afforess/gist:4013360
Created November 4, 2012 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dredhorse/4013405 to your computer and use it in GitHub Desktop.
Save dredhorse/4013405 to your computer and use it in GitHub Desktop.
Death Cause Factory pattern
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