To implement a simple version of this feature, consider the following conceptual code structure:
Happy fragging.