0

I am making a Spyfall game, a game where all players are at a certain location, and their roles depend on which location they are at. Thus, each Location has their own set of roles that the players randomly receive.

Currently, there are about 27 locations, like the Casino. The Casino has the roles of the Bartender, Gambler, Dealer, etc.

When I create a list of my locations to use in my game, should I create a general Location class:

class Location:
    def __init__(self, name, *roles):
        self.name = name
        self.roles = roles

and use constructors with different parameters like

 Location(name="Passenger Airplane", "Economy Class Passenger"...so on
 Location(name="Bank Robbery", "Customer", ...so on

or should I create classes inheriting from Location and hard-code the values:

class Airplane(Location):
    def __init__(self):
        self.name = "Airplane", etc

In addition, I want to add a list of facts to each Location (e.g WWII was in the 1940s), and to me, putting that list in the constructor seems a bit much.

Assuming I use classes rather than use constructors, should I use a factory design pattern?

DurianHLN
  • 71
  • 4
  • 2
    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. [on topic](http://stackoverflow.com/help/on-topic) and [how to ask](http://stackoverflow.com/help/how-to-ask) apply here. As given, I feel your question is too broad: a specific answer depends on game design decisions that you haven't included here. In particular, what are the various interactions among the objects that will drive these structure decisions? Post an appropriately detailed design, and we may be able to help you discuss high-level implementation details. – Prune Jan 05 '17 at 01:13

2 Answers2

2

Classes should represent distinct objects or functionality within your program. If a class only differs from another class by the data it contains then it should be an object.

In your example, if your Airplane needed to be able to fly, that would be functionally distinct from other Locations and would justify having a separate class with a fly method.

James Emerton
  • 4,129
  • 2
  • 25
  • 33
0

Regarding your question on inheritance. It is advisable to use composition over inheritance.

See Prefer composition over inheritance?

Community
  • 1
  • 1
JWS
  • 158
  • 1
  • 8