π Section 14: Main Loop + Entry Point
π Summary (What you will do)
In this section, you will wire everything together and make the game run. You will:
- Build the
main_loop()function - Show the dashboard each turn and process player choices
- Add the entry point so the program starts correctly
This is the moment where all your classes and functions become a working game.
β Checklist (You must complete these)
- Open
pet_manager.py - Scroll to the very bottom of the file
- Add
main_loop()and the entry point exactly as shown - Type the code by hand so you understand how the loop works
β No new constants/settings are added in this section, so you do not need to edit the top-of-file constants.
π Core Concepts (New learning for this section)
1) The main game loop
A game loop repeats forever until the player quits.
Each turn does the same pattern:
- Show the current state
- Ask the player what to do
- Run the chosen action
- Advance time
This loop is the heartbeat of the program.
2) Connecting UI and game logic
Inside the loop we call:
show_dashboard()to display infochoose_from()to get a valid menu choicecare_flow()oradopt_flow()to run actionstick_all()to advance time
This ties the UI helpers to the game objects you built.
3) The entry point
if __name__ == "__main__":
This block ensures the game only starts when the file is run directly, not when itβs imported by tests.
π» Code to Write (Type this by hand in pet_manager.py)
Directions:
- Open
pet_manager.py - Scroll to the very bottom of the file
- Type the following code by hand:
π Emoji Copy/Paste List
Use these emojis exactly as shown in the code:
π
π§ Code Review & Key Concepts (What important lines do)
Starting the game
player = Player(name)
This creates the Player object that will own all pets.
The main menu
choice = choose_from(...)
This uses your input helper to get a safe menu choice.
Quit behavior
sys.exit(0)
This cleanly exits the program when the player chooses βQuit.β
Entry point guard
if __name__ == "__main__":
This ensures main_loop() runs only when the file is executed directly.
