Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

๐ŸŽฐ Animated Slot Machine Game

An interactive slot machine game built with Python and Streamlit, featuring animated spinning effects, real-time balance tracking, and a modern web interface.

Python Streamlit License

โœจ Features

  • ๐ŸŽฐ 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

๐ŸŽฎ Demo

    ๐ŸŽฐ Slot Machine ๐ŸŽฐ
    โžค  ๐Ÿ’  ๐Ÿ’  ๐Ÿ’  โžค   โ† Winning line!
       ๐Ÿ‹  ๐ŸŠ  ๐Ÿ‡
       ๐Ÿ‡  ๐Ÿ‡  ๐Ÿ‡

๐Ÿš€ Installation

Prerequisites

  • Python 3.7 or higher
  • pip (Python package manager)

Steps

  1. Clone the repository

    git clone https://github.com/PAT-07/slot-machine-game.git
    cd slot-machine-game
  2. Install dependencies

    pip install streamlit
  3. Run the application

    streamlit run slot_machine.py
  4. Open in browser

    • The app will automatically open at http://localhost:8501
    • If not, manually navigate to the URL shown in the terminal

๐ŸŽฒ How to Play

  1. Deposit Money - Start by depositing funds (default: $100)
  2. Select Lines - Choose how many lines to bet on (1-3)
  3. Set Bet Amount - Use the slider to set your bet per line ($1-$100)
  4. Hit SPIN! - Click the big spin button and watch the magic happen
  5. Win Big - Match symbols across lines to multiply your bet!

๐Ÿ† Game Rules

Symbol Values (Payout Multipliers)

Symbol Multiplier Rarity
๐Ÿ’ Cherry 5x Rare
๐Ÿ‹ Lemon 4x Uncommon
๐ŸŠ Orange 3x Common
๐Ÿ‡ Grape 2x Very Common

Winning Conditions

  • All three symbols in a line must match
  • Only lines you bet on count toward winnings
  • Winnings = Symbol Value ร— Bet Amount per line

Example

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

๐Ÿ“Š Statistics Tracked

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

๐Ÿ› ๏ธ Customization

Change Symbols

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)
}

Adjust Payouts

Modify the symbols_value dictionary:

symbols_value = {
    "๐Ÿ’Ž": 10,  # Higher multiplier
    "๐Ÿ””": 5,
    "โญ": 3,
    "7๏ธโƒฃ": 2,
}

Change Betting Limits

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 on

Modify Animation Speed

In the display_slot_machine_animated() function:

spin_duration = 15  # Increase for longer animation
time.sleep(0.05 + (frame * 0.01))  # Adjust timing

๐Ÿ—๏ธ Technical Details

Technology Stack

  • Python 3.x - Core programming language
  • Streamlit - Web application framework
  • Random Module - Slot machine logic
  • Time Module - Animation timing

Architecture

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)

Key Features Explained

Session State Management

  • Streamlit reruns the script on every interaction
  • st.session_state preserves 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

๐Ÿ“ Code Structure

# 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! โญ

About

Interactive slot machine game built with Python and Streamlit. Features real-time betting, balance tracking, and win animations.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages