Answer the question
In order to leave comments, you need to log in
Farm game in Python. How to program background actions?
Greetings. Such a question. I am writing a game like a farm in a chat bot. (buy a chicken, she lays 3 eggs a day, sell them, etc.) I looked at libraries in general for python games (pygame, Python Arcade) they are mainly aimed at the graphic component and are played in real time. But I need it to always work on the server and take into account how many chickens, roughly speaking, added the number of eggs they lay, and so on.
Tell me which libraries have similar functionality or in general how it can be implemented.
Answer the question
In order to leave comments, you need to log in
You don't need to calculate in real time.
Write down all the data with a timestamp, and make a function that recalculates how much everything should have been added since the last update.
Hang this function as a trigger for various actions, such as the user came in, pressed the button to do something.
The recalculation will take a little, but there is no load in the background at all.
1. The player sends a command to buy a chicken.
2. The game saves this action in the database
======== several days have passed ==========
3. The player sends a command to check the "balance"
4. number_of_eggs = (current_date - purchase_date) * 3
It is worth remembering that you are a programmer, and you should be able to write something yourself without any libraries. I have not seen any framework for such games before, but there is nothing complicated here, in most cases just accessing the database (you can use ORM for this). If you have no idea how to implement all this, you should practice on simple tasks. First, try to draw a database diagram on a piece of paper (or you can use Visio, but the old-fashioned way is better), and then you'll figure it out)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question