Python Arcade Suite is built with a modular architecture that separates concerns between the main application router and individual game modules. This design enables easy maintenance, scalability, and the ability to add new games without modifying existing code.
python-arcade-suite/├── streamlit_app.py # Main entry point and router├── blackjack/│ └── streamlit_game.py # Blackjack game module├── Hangman/│ ├── streamlit_game.py # Hangman game module│ └── DATA/│ └── DATA.txt # Word list for Hangman└── Rock_paper_or_scissors/ └── streamlit_game.py # Rock Paper Scissors module
Each game is self-contained in its own directory with a streamlit_game.py file that exposes an app() function. This consistent interface makes the router simple and predictable.
The application follows standard Python conventions with a main() function as the entry point. This function is called when the script is executed directly.
import streamlit as stfrom blackjack import streamlit_game as blackjackfrom Hangman import streamlit_game as hangmanfrom Rock_paper_or_scissors import streamlit_game as rps
Key Design Decisions:
Namespace Aliasing: Each game module is imported with a short alias (blackjack, hangman, rps) for cleaner code
Consistent Interface: All games expose an app() function that can be called uniformly
Lazy Loading: While imports happen at startup, game logic only executes when selected
The router uses a simple conditional chain to delegate control to the appropriate game module:
if game_choice == "Inicio": st.header("Bienvenido a la colección de Juegos Simples") st.markdown(""" Esta aplicación contiene tres juegos clásicos: 1. **Blackjack 🃏**: Intenta llegar a 21 sin pasarte. 2. **Ahorcado 🔤**: Adivina la palabra antes de que se acaben los intentos. 3. **Piedra, Papel o Tijeras ✂️**: Juega contra la computadora. ¡Selecciona uno en la barra lateral para empezar! """)elif game_choice == "Blackjack": blackjack.app()elif game_choice == "Ahorcado": hangman.app()elif game_choice == "Piedra, Papel o Tijeras": rps.app()
Streamlit re-runs the entire script from top to bottom on every user interaction. The session state persists between re-runs, which is crucial for maintaining game state.
# new_game/streamlit_game.pydef init_game(): # Initialize game state passdef app(): # Main game logic pass
Update router:
# streamlit_app.pyfrom new_game import streamlit_game as new_gamegame_choice = st.sidebar.selectbox( "Elige un juego", ("Inicio", "Blackjack", "Ahorcado", "Piedra, Papel o Tijeras", "New Game"))# Add routing conditionelif game_choice == "New Game": new_game.app()
The modular architecture makes this extension process straightforward and predictable.