본문 바로가기

Chat

슬롯머신 효과음 무료 다운로드 사이트_by python

https://uppbeat.io/sfx/category/gaming/slot-machine  Slot machine sound effects

효과음 다운로드 사이트

 

효과음 연결 안된 소스:   https://cs-essay.tistory.com/82

 

Pygame을 윈도우 터미널에서 설치하려면, 다음 단계를 따라하세요:

1. 터미널 열기: 시작 메뉴에서 "명령 프롬프트" 또는 "Windows PowerShell"을 검색하여 엽니다.
pip 설치 확인: pip가 설치되어 있는지 확인합니다. 다음 명령어를 입력하세요:

pip --version

 

2. 만약 설치되어 있지 않다면, Python을 설치할 때 pip 옵션을 선택해야 합니다.
Pygame 설치: 다음 명령어를 입력하여 Pygame을 설치합니다:

pip install pygame


3. 설치 확인: 설치가 완료되면, Pygame이 제대로 설치되었는지 확인하기 위해 다음 명령어를 입력하세요:

python -m pygame --version


이 과정을 통해 Pygame을 성공적으로 설치할 수 있습니다.

 

 

코드 수정할 부분

효과음 관련 수정할 부분: 찾기(ctrl+f)에서 'sound'로 검색. 나머지도 앞 부분 첫 단어로 검색해 수정.

import pygame  # pygame 라이브러리 추가

# 초기화
pygame.mixer.init()
spin_sound = pygame.mixer.Sound('spin_sound.wav')  # 효과음 파일 경로. 같은 폴더에 넣으면 된다

def play_sound():
    """사운드를 반복 재생하는 함수."""
    spin_sound.play(-1)

def stop_sound():
    """사운드를 정지하는 함수."""
    spin_sound.stop()

슬롯머신 소스 코드: 사운도 연결 추가된 코드

import random
import keyboard
import time
import pygame

total_score = 0  # 총 점수 초기화

# 초기화
pygame.init()  # pygame 전체 초기화
pygame.mixer.init()  # mixer 초기화

# 사운드 파일 경로 확인
try:
    spin_sound = pygame.mixer.Sound('spin_sound.wav')  # 효과음 파일 경로
except pygame.error as e:
    print(f"Error loading sound: {e}")

def slot_machine():
    global total_score
    symbols = ['★', '●', '◆', '♠', '♥', '♣', '㉿', '®', '㈜']
     
    spin_sound.stop()  # 사운드 멈추기 (이전 재생이 있을 경우)
    spin_sound.play(0)  # 효과음 반복 재생 시작
    result = []
    for _ in range(15):  # 15회 반복
        result = random.choices(symbols, k=3)
        blue_result = [f"\033[94m{symbol}\033[0m" for symbol in result]
        print("Slot machine result: ", ' | '.join(blue_result))
        time.sleep(0.1)  # 0.1초 대기
        print("\033[F\033[K", end='')  # 커서를 위로 이동하고 줄을 지움

        # 스페이스 바가 눌리면 애니메이션 멈추기
        if keyboard.is_pressed('space'):
            break

        spin_sound.stop()  # 사운드 멈추기 
    
    blue_result = [f"\033[94m{symbol}\033[0m" for symbol in result]
    print("Slot machine result: ", ' | '.join(blue_result))

    # score 계산
    score = 0
    if result[0] == result[1] == result[2]:  # 잭팟
        score = 100
        for _ in range(3):  # 메시지를 3번 반복 출력
            print("")
            time.sleep(0.5)  # 0.5초 대기
            print("\033[F\033[K", end='')  # 이전 출력 지우기
            print("\033[91mCongratulations! Jackpot! Score: 100\033[0m")
            time.sleep(0.5)  # 잠시 대기
            print("\033[F\033[K", end='')  # 이전 출력 지우기
    elif result[0] == result[1] or result[1] == result[2] or result[0] == result[2]:  # 두 개가 같은 경우
        score = 10
        for _ in range(3):  # 메시지를 3번 반복 출력
            print("")
            time.sleep(0.5)  # 0.5초 대기
            print("\033[F\033[K", end='')  # 이전 출력 지우기
            print("\033[34mTwo symbols are the same! Score: 10\033[0m")  # 파란색 출력                  
            time.sleep(0.5)  # 잠시 대기
            print("\033[F\033[K", end='')  # 이전 출력 지우기
    else:
        print("Try again! current Score: 0\n")

    total_score += score  # 총 score 합산
    print(f"\033[93mCurrent total score: {total_score} points\033[0m\n")  # 총 점수 출력

print("Press the space bar to start the Slot machine game.")
print("Press 'g', 's', or 't' to add the current score, 'q' to quit.")

while True:
    if keyboard.is_pressed('space'):
        slot_machine()
        while keyboard.is_pressed('space'):
            pass  # 스페이스바가 더 이상 눌리지 않을 때까지 대기
    elif keyboard.is_pressed('g') or keyboard.is_pressed('s') or keyboard.is_pressed('t'):
        print(f"Current total score added: {total_score} points")
    elif keyboard.is_pressed('q'):
        print("Exiting the game.")
        break
    elif keyboard.is_pressed('esc'):
        pass  # Esc 키가 눌리면 아무 작업도 하지 않음