Created
September 24, 2012 21:09
-
-
Save narrowtux/3778394 to your computer and use it in GitHub Desktop.
Endless event-style methods for Components
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 class ComponentHolder { | |
// ... | |
public void onEvent(String methodName) { | |
for (Component c:getComponents()) { | |
if (c.getClass().hasMethod(methodName)) { | |
c.getClass().getMethod(methodName).execute(c); | |
} | |
} | |
} | |
// ... | |
} |
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 class GuiComponent extends Component { | |
public void onBuy() { | |
updateGui(); | |
} | |
} |
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 class TradeComponent extends Component { | |
@Override | |
public void onTick() { | |
if (someCondition) { | |
getHolder().onEvent("onBuy"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment