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

Function to close the game #2

Open
renatocassino opened this issue Dec 7, 2019 · 1 comment
Open

Function to close the game #2

renatocassino opened this issue Dec 7, 2019 · 1 comment

Comments

@renatocassino
Copy link

Hello man

I'm creating the game and in the examples is only possible to close the game exiting the process, but I want to close one game and start another
When I see the code to instance.exit(), in the final the method call process.exit()

There is a way to close the game without close the process?

Can I make a PR to change this?

@robertrypula
Copy link
Owner

robertrypula commented Dec 17, 2019

Hey, sorry for delayed response. Thanks for using my lib! :) In general you should treat the instance of terminal-game-io as monitor and keyboard. As long you needs it it's alive. The logic of switching games should be inside your code. You don't delete your monitor and keyboard everytime you run diferent game in your operating system :) You just kill the process of one game and start another - monitor and keyboard is untouched until you reallly want to turn off the machine.

Just add another layer of abstraction in your code - something like Game class. Every game instance will use one instance of terminal-game-io as IO. There could be some menu that wraps everyting with list of games and something like "Quit to terminal" option which would run instance.exit() to really kill whole app.

I hope that helped :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants