Best practices to follow while designing game interactions using GamePlay objects

  • Keep isTriggered() and performAction() methods as simple as possible
  • Most, if not all, conditional checks should be inside isTriggered() method not in performAction() method.
  • Identify the actors involved in the GamePlay clearly.
  • Same actors may be involved in different interactions based on their internal states. Model these interactions using separate GamePlay classes.
  • GamePlay objects should be functional and self contained i.e. they should not access any data structure in the game other than those provided to the GamePlay object using setter methods.
  • if your isTriggered() or performAction() method contains complex pieces of code containg many conditional statements and loops as in a flowchart, then it is a clear indication that you need to model this as two or more GamePlay objects.
  • Make sure isTriggered() method does not return true always or false always.
  • The performAction() method typically should change the state of one or more of the actors in the GamePlay to invalidate the trigger condition. If it does not do that the interaction will take place perpetually.