haive.games.clue.ui¶
Clue rich UI visualization module.
This module provides a visually appealing terminal UI for Clue games, with styled components, animations, and comprehensive game information.
- It uses the Rich library to create a console-based UI with:
Game board visualization with players, suspects, weapons, and rooms
Guess history with detailed responses
Player cards and deduction notes
Game status and information
Thinking animations and guess visualization
Example
>>> from haive.games.clue.ui import ClueUI
>>> from haive.games.clue.state import ClueState
>>>
>>> ui = ClueUI()
>>> state = ClueState.initialize()
>>> ui.display_state(state) # Display the initial game state
>>>
>>> # Show thinking animation for player
>>> ui.show_thinking("player1")
>>>
>>> # Display a guess
>>> from haive.games.clue.models import ClueGuess, ValidSuspect, ValidWeapon, ValidRoom
>>> guess = ClueGuess(
>>> suspect=ValidSuspect.COLONEL_MUSTARD,
>>> weapon=ValidWeapon.KNIFE,
>>> room=ValidRoom.KITCHEN
>>> )
>>> ui.show_guess(guess, "player1")
Classes¶
Rich UI for beautiful Clue game visualization. |
Module Contents¶
- class haive.games.clue.ui.ClueUI[source]¶
Rich UI for beautiful Clue game visualization.
This class provides a visually appealing terminal UI for Clue games, with styled components, animations, and comprehensive game information.
- Features:
Game board visualization with suspects, weapons, and rooms
Guess history with detailed responses
Player cards and deduction notes
Game status and information
Thinking animations and guess visualization
- console¶
Rich console for output
- Type:
Console
- layout¶
Layout manager for UI components
- Type:
Layout
Examples
>>> ui = ClueUI() >>> state = ClueState.initialize() >>> ui.display_state(state) # Display the initial game state
Initialize the Clue UI with default settings.
- display_state(state)[source]¶
Display the current game state with rich formatting.
Renders the complete game state including suspects, weapons, rooms, guess history, player cards, and game information in a formatted layout.
- Parameters:
state (Union[ClueState, Dict[str, Any]]) – Current game state
- Returns:
None
- Return type:
None
Example
>>> ui = ClueUI() >>> state = ClueState.initialize() >>> ui.display_state(state)
- show_game_over(state)[source]¶
Display game over message with result.
Shows a game over panel with the winner highlighted in their color, and reveals the solution.
- Parameters:
state (ClueState) – Final game state
- Returns:
None
- Return type:
None
Example
>>> ui = ClueUI() >>> state = ClueState.initialize() >>> state.game_status = "player1_win" >>> state.winner = "player1" >>> ui.show_game_over(state)
- show_guess(guess, player)[source]¶
Display a guess being made.
Shows a formatted message indicating which player made a guess, including the suspect, weapon, and room.
- Parameters:
- Returns:
None
- Return type:
None
Example
>>> ui = ClueUI() >>> guess = ClueGuess( ... suspect=ValidSuspect.COLONEL_MUSTARD, ... weapon=ValidWeapon.KNIFE, ... room=ValidRoom.KITCHEN ... ) >>> ui.show_guess(guess, "player1")
- show_response(response, player)[source]¶
Display a response to a guess.
Shows a formatted message indicating the response to a guess, including which player responded and what card was shown.
- Parameters:
response (ClueResponse) – The response to the guess
player (str) – Player who made the guess (“player1” or “player2”)
- Returns:
None
- Return type:
None
Example
>>> ui = ClueUI() >>> response = ClueResponse( ... is_correct=False, ... responding_player="player2", ... refuting_card=ClueCard(name="Knife", card_type=CardType.WEAPON) ... ) >>> ui.show_response(response, "player1")
- show_thinking(player, message='Thinking...')[source]¶
Display a thinking animation for the current player.
Shows a spinner animation with player-colored text to indicate that the player is thinking about their guess.
- Parameters:
- Returns:
None
- Return type:
None
Example
>>> ui = ClueUI() >>> ui.show_thinking("player1", "Analyzing clues...")