An interactive slot machine game built with Python and Streamlit, featuring animated spinning effects, real-time balance tracking, and a modern web interface.
- ๐ฐ Animated Spinning Effect - Watch symbols spin and slow down like a real slot machine
- ๐ฐ Real-time Balance Tracking - Monitor your money as you play
- ๐ฏ Multi-line Betting System - Bet on 1-3 lines simultaneously
- ๐ Live Statistics Dashboard - Track ROI, total wins, total bets, and spin count
- ๐จ Visual Win Indicators - Gold glow effects and arrows highlight winning lines
- ๐ Win Animations - Celebrate victories with balloon animations
- ๐ฑ Responsive Web Interface - Clean, modern design that works on any device
- ๐ Customizable Symbols - Easy to modify emojis and payout values
๐ฐ Slot Machine ๐ฐ
โค ๐ ๐ ๐ โค โ Winning line!
๐ ๐ ๐
๐ ๐ ๐
- Python 3.7 or higher
- pip (Python package manager)
-
Clone the repository
git clone https://github.com/PAT-07/slot-machine-game.git cd slot-machine-game -
Install dependencies
pip install streamlit
-
Run the application
streamlit run slot_machine.py
-
Open in browser
- The app will automatically open at
http://localhost:8501 - If not, manually navigate to the URL shown in the terminal
- The app will automatically open at
- Deposit Money - Start by depositing funds (default: $100)
- Select Lines - Choose how many lines to bet on (1-3)
- Set Bet Amount - Use the slider to set your bet per line ($1-$100)
- Hit SPIN! - Click the big spin button and watch the magic happen
- Win Big - Match symbols across lines to multiply your bet!
| Symbol | Multiplier | Rarity |
|---|---|---|
| ๐ Cherry | 5x | Rare |
| ๐ Lemon | 4x | Uncommon |
| ๐ Orange | 3x | Common |
| ๐ Grape | 2x | Very Common |
- All three symbols in a line must match
- Only lines you bet on count toward winnings
- Winnings = Symbol Value ร Bet Amount per line
Bet: $10 per line on 3 lines
Total Bet: $30
Result:
Line 1: ๐ ๐ ๐ โ Win $50 (5 ร $10)
Line 2: ๐ ๐ ๐ โ No win
Line 3: ๐ ๐ ๐ โ Win $20 (2 ร $10)
Total Win: $70
Net Profit: $70 - $30 = +$40
The sidebar displays comprehensive game statistics:
- Current Balance - Your available funds
- Total Spins - Number of times you've played
- Total Won - Cumulative winnings across all spins
- Total Bet - Cumulative amount wagered
- ROI (Return on Investment) - Your profit/loss percentage
Edit the symbols_count dictionary to modify symbols and their frequency:
symbols_count = {
"๐": 2, # Rare (high value)
"๐": 4, # Uncommon
"โญ": 6, # Common
"7๏ธโฃ": 8, # Very common (low value)
}Modify the symbols_value dictionary:
symbols_value = {
"๐": 10, # Higher multiplier
"๐": 5,
"โญ": 3,
"7๏ธโฃ": 2,
}Adjust the constants at the top of the file:
MAX_BET = 100 # Maximum bet per line
MIN_BET = 1 # Minimum bet per line
MAX_LINES = 3 # Maximum lines to bet onIn the display_slot_machine_animated() function:
spin_duration = 15 # Increase for longer animation
time.sleep(0.05 + (frame * 0.01)) # Adjust timing- Python 3.x - Core programming language
- Streamlit - Web application framework
- Random Module - Slot machine logic
- Time Module - Animation timing
slot_machine.py
โโโ Game Constants (symbols, values, limits)
โโโ Session State Management (balance, stats)
โโโ Core Functions
โ โโโ check_winnings() - Calculate wins
โ โโโ get_slot_machine_spin() - Generate results
โ โโโ display_slot_machine_animated() - Spinning effect
โ โโโ display_slot_machine_final() - Final display
โโโ Streamlit UI
โโโ Sidebar (stats, payout table)
โโโ Deposit Section
โโโ Game Controls (bet, spin)
Session State Management
- Streamlit reruns the script on every interaction
st.session_statepreserves data between reruns- Essential for maintaining balance and game state
Animation System
- Uses
st.empty()to create updateable container - Loops through random symbols with blur effect
- Progressive slowdown simulates real slot machine physics
Responsive Layout
st.columns()creates flexible grid system- Custom CSS widens sidebar and styles buttons
- Works seamlessly on desktop and mobile
# 1. Imports and Constants
import streamlit as st
import random
import time
# 2. Initialize Session State
if 'balance' not in st.session_state:
st.session_state.balance = 0
# 3. Game Logic Functions
def check_winnings(columns, lines, bet, values):
# Calculate winnings
# 4. Display Functions
def display_slot_machine_animated(placeholder):
# Animated spinning effect
# 5. Streamlit UI
st.set_page_config(...)
st.title("๐ฐ Slot Machine Game ๐ฐ")
# 6. Sidebar
with st.sidebar:
st.metric("Balance", f"${balance}")
# 7. Main Game
if st.button("๐ฐ SPIN!"):
# Spin logicโญ If you like this project, please give it a star on GitHub! โญ