Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Customizable Electronic Card Deck

#1
Here's an Arduino project to create an electronic card deck. It reduces the deck each time you take a card so you won't have the same card reappearing. It is customizable for any game you want to create, and it's easy to build. 

==================================================================================
I made the suits Tan, Brown, Olive Green, and Black. You can change them to whatever you want. The cards are also numbered 1 to 10 and have three generals to separate them (Jack, Queen, King). All of the Generals count as ten points.

The images (
Code:
tan.png
,
Code:
brown.png
,
Code:
olive_green.png
,
Code:
black.png
) should be around 150 pixels wide by 200 pixels tall to match the code's resizing dimensions.
If the images are larger or smaller, the script will resize them to 150x200 pixels, but starting with images of similar dimensions will ensure they display well and maintain quality.
Suggested Image Dimensions:
  • Width: 150 pixels
  • Height: 200 pixels
Make sure each image clearly shows the suit or symbol so it's easily recognizable when displayed in the application.

============================================================================
INSTRUCTIONS ARE BELOW, PAST THIS INTO THE EDITOR> DON'T DELETE THE INSTRUCTIONS. They won't show when there's a # in front of the sentence.

=============================================================================

import random
import tkinter as tk
from PIL import Image, ImageTk

import random
import tkinter as tk
from PIL import Image, ImageTk

# Step-by-Step Instructions for a non-coders to Build This Project

# Parts List:
# 1. Computer with Python installed
# 2. Tkinter library (comes with Python)
# 3. PIL (Pillow) library for image handling (install with: pip install Pillow)
# 4. Images of cards saved in an 'images' folder:
#    - tan.png
#    - brown.png
#    - olive_green.png
#    - black.png

# Assembly Instructions for the Coding Project

# Step 1: Install Python and Libraries
# - First, install Python from the official website (https://www.python.org/downloads/).
# - Once Python is installed, open the Command Prompt (Windows) or Terminal (Mac/Linux).
# - Install the PIL (Pillow) library by typing the following command and pressing Enter:
#  pip install Pillow

# Step 2: Set Up the Folder Structure
# - Create a new folder on your computer where you will save your game files. You can name it something like 'CardDrawingGame'.
# - Inside this folder, create another folder named 'images'.
# - Save the images of the cards inside the 'images' folder. The images should have the following names:
#  - tan.png
#  - brown.png
#  - olive_green.png
#  - black.png

# Step 3: Write the Python Code
# - Open a text editor like Notepad (Windows) or VS Code (recommended for beginners).
# - Copy and paste the Python code provided below into the text editor.
# - Save the file with the name 'card_game.py' inside the 'CardDrawingGame' folder you created earlier.

# Step 4: Run the Card Drawing Game
# - Open the Command Prompt or Terminal on your computer.
# - Navigate to the 'CardDrawingGame' folder using the 'cd' command. For example, if the folder is on your desktop, type:
#  cd Desktop/CardDrawingGame
# - Once you are inside the 'CardDrawingGame' folder, run the Python code by typing:
#  python card_game.py
# - You should see a window pop up that lets you draw cards by pressing the button.


End of instructions. Code is below
# Python Code for the Card Drawing Game

def create_deck():
    suits = ['Tan', 'Brown', 'Olive Green', 'Black']
    values = [str(i) for i in range(1, 11)] + ['Maj General', 'Lt General', 'General']
    deck = [f'{value} of {suit}' for suit in suits for value in values]
    deck.append('Ambush 1')
    deck.append('Ambush 2')
    return deck

def draw_card(deck):
    if not deck:
        return None
    card = random.choice(deck)
    deck.remove(card)
    return card

def show_card(card):
    if card:
        card_label.config(text=card)
        display_card_image(card)
    else:
        card_label.config(text="The deck is empty! Turn off and on to reshuffle the new deck.")
        draw_button.config(state=tk.DISABLED)

def draw():
    card = draw_card(deck)
    show_card(card)

def display_card_image(card):
    # Extract suit from card description
    suit = card.split(' ')[-1].lower().replace(" ", "_")
    image_path = f"images/{suit}.png"
    try:
        card_image = Image.open(image_path)
        card_image = card_image.resize((150, 200), Image.ANTIALIAS)
        card_image_tk = ImageTk.PhotoImage(card_image)
        card_image_label.config(image=card_image_tk)
        card_image_label.image = card_image_tk
    except FileNotFoundError:
        card_image_label.config(image='')
        card_image_label.image = None

# Create the deck and initialize the GUI
deck = create_deck()

root = tk.Tk()
root.title("Card Drawing Game")

card_label = tk.Label(root, text="Press the button to draw a card.", font=("Helvetica", 16))
card_label.pack(pady=20)

card_image_label = tk.Label(root)
card_image_label.pack(pady=10)

draw_button = tk.Button(root, text="Draw a Card", command=draw, font=("Helvetica", 14))
draw_button.pack(pady=10)

root.mainloop()
Reply

Reply

Reply

#4
skaskanew.ru see more gratiavitae.ru click here slame-rp.ru here agrorubo agrorubo flamandrose.ru click here to learn more fantastikmir more info on this page pavel3333 site vladgate.ru read more vr-point.ru more info on this page homeimprovementstore.ru details craftingmaterials craftingmaterials modernlighting visit the site for details digitalartprints.ru see more beautyandwellness source
Reply

#5
skaskanew.ru read more gratiavitae example slame-rp.ru source agrorubo.ru click here flamandrose.ru details fantastikmir fantastikmir pavel3333.ru click here to learn more vladgate.ru visit the site for details vr-point.ru click here to learn more homeimprovementstore go to craftingmaterials craftingmaterials modernlighting the article digitalartprints.ru source beautyandwellness details
Reply

#6
skaskanew link gratiavitae.ru that slame-rp.ru the article agrorubo example flamandrose this website fantastikmir.ru fantastikmir.ru pavel3333.ru page vladgate.ru online vr-point vr-point homeimprovementstore.ru visit the site craftingmaterials.ru online modernlighting that digitalartprints learn more beautyandwellness.ru the article
Reply

#7
skaskanew.ru page gratiavitae.ru visit the site for details slame-rp slame-rp agrorubo details flamandrose visit the site for details fantastikmir.ru click here to learn more pavel3333 this website vladgate online vr-point link homeimprovementstore learn more craftingmaterials click here to learn more modernlighting click here digitalartprints.ru click here to learn more beautyandwellness beautyandwellness
Reply

#8
skaskanew.ru source gratiavitae.ru learn more slame-rp that agrorubo.ru site flamandrose the article fantastikmir.ru details pavel3333.ru that vladgate.ru more info on this page vr-point visit the site for details homeimprovementstore.ru details craftingmaterials.ru this website modernlighting.ru modernlighting digitalartprints here beautyandwellness.ru beautyandwellness
Reply

#9
As an exporter, your bank is the first requirement for AD Code registration. With requesting the registration on your company's letterhead, provide a letter that is addressed to your bank. Requesting request for registration, forward this information to DGFT and customs through the bank to complete the first step in the registration process.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016