Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Game class must be on a Singleton pattern #19

Open
naulan-chrzaszcz opened this issue Feb 1, 2023 · 2 comments
Open

The Game class must be on a Singleton pattern #19

naulan-chrzaszcz opened this issue Feb 1, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@naulan-chrzaszcz
Copy link
Member

naulan-chrzaszcz commented Feb 1, 2023

The game class must be a Singleton

class Game(object):
    """ 
        Environment where everything will works together. 
        This class have only one instance (Singleton Patern)
    """
    __instance = None    # Private variable

    def __new__(cls, *args, **kwargs):
        """ 
            Return only one instance of this class.
            @return Game instance into __instance variable
        """
        if cls.__instance is None:
            cls.__instance = super(Game, cls).__new__(cls, *args, **kwargs)
        return cls.__instance
   
    @staticmethod
    def get_instance():
        """ 
            Return only one instance of this class.
            @return Game instance into __instance variable
        """
        if Game.__instance is None:
            Game.__instance = Game()
        return Game.__instance
@naulan-chrzaszcz
Copy link
Member Author

On each entities, we don"t need to put game variable on arguments, we need just to call Game.get_instance()
So this issue #5 is invalid

@naulan-chrzaszcz
Copy link
Member Author

What do you think @TheblackReaper060303 about this ? We can close #5 issue ?

@naulan-chrzaszcz naulan-chrzaszcz added the enhancement New feature or request label Feb 1, 2023
@naulan-chrzaszcz naulan-chrzaszcz changed the title The Game class must be on a Singleton pattern The Game class must be on a Singleton pattern Feb 1, 2023
@naulan-chrzaszcz naulan-chrzaszcz added the question Further information is requested label Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants