How Do I Implement SRP Across A Few Classes?

43 views Asked by At

My friend and I are working on a game. Right now the game is very simple but we want to understand how we would go about implementing the Single Responsibility Principle between three objects. We have player, enemy, and bullet classes.

  1. The player and enemy both need to be able attack and move, while the bullet only needs to be able to move.
  2. They all need to be able to collide with one another.
  3. The player moves and attacks based on user input
  4. The enemy moves and attacks based on predetermined attack patterns.

We're really really struggling with the class structure and how to organize the code - we were debating using objects that just hold state and then big controller classes that each do one thing (manage collisions, manage attacking, etc.). Could someone please provide a suggested architecture that follows SRP?

Thank you!

0

There are 0 answers