pygame.midi를 사용하여 미디 노트를 연주하는 함수를 만들었고, 스맥 잭이라는 게임도 만들었습니다. 멀티 프로세스를 사용하여 게임과 노래를 동시에 재생했지만 프로그램이 입력을 요청하기 위해 멈추지 않고 계속해서이 오류를 생성하는 오류가 발생했습니다.
loop_c의 126 행
action = input ( '') EOFError : 줄을 읽을 때 EOF
도와주세요, 감사합니다.
import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import pygame.midi
import time
from multiprocessing import Process
C = 0
Ch = 1
D = 2
Dh = 3
E = 4
F = 5
Fh = 6
G = 7
Gh = 8
A = 9
Ah = 10
B = 11
def playnote(i, n , x):
if n > -1:
i+=(12*(n)+12)
elif n == 0:
i+=12
pygame.midi.init()
player = pygame.midi.Output(0)
player.set_instrument(0)
player.note_on(i, 127)
time.sleep(x)
pygame.midi.quit()
def loop_a():
while True:
playnote(B, 2, 0.5)
playnote(Ch, 3, 0.5)
playnote(D, 3, 0.5)
playnote(E, 3, 0.5)
playnote(Fh, 3, 0.5)
playnote(D, 3, 0.5)
playnote(Fh, 3, 0.5)
playnote(F, 3, 0.5)
playnote(Ch, 3, 0.5)
playnote(F, 3, 0.5)
playnote(E, 3, 0.5)
playnote(C, 3, 0.5)
playnote(E, 3, 0.5)
#end of verse
playnote(B, 2, 0.5)
playnote(Ch, 3, 0.5)
playnote(D, 3, 0.5)
playnote(E, 3, 0.5)
playnote(Fh, 3, 0.5)
playnote(D, 3, 0.5)
playnote(Fh, 3, 0.5)
playnote(B, 3, 0.5)
playnote(A, 3, 0.5)
playnote(Fh, 3, 0.5)
playnote(D, 3, 0.5)
playnote(Fh, 3, 0.5)
playnote(A, 3, 0.5)
def loop_b():
while True:
playnote(B, 1, 0.5)
playnote(Fh, 1, 0.5)
def loop_c():
'''
YOU NEED TO INSTALL PYGAME
IF YOU DON'T THE SOUND WONT WORK
'''
import random
import time
import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import pygame.midi
# These are notes for the keyboard
C = 0
Ch = 1
D = 2
Dh = 3
E = 4
F = 5
Fh = 6
G = 7
Gh = 8
A = 9
Ah = 10
B = 11
# this is a function to play the note, i = the midi note number (c = 0, D = 2, etc.), n is the octave, x is the not duration.
def playnote(i, n, x):
if n > -1:
i += (12 * (n) + 12)
elif n == 0:
i += 12
pygame.midi.init()
player = pygame.midi.Output(0)
player.set_instrument(0)
player.note_on(i, 50)
time.sleep(x)
pygame.midi.quit()
dealercount = 0
dealertotal = 0
hitcounter = 0
cardtotal = 0
card = random.randrange(1, 11)
cardtotal += card
print('Welcome to SmackJack!')
print(" _____ _____")
print("|9 | |A . |")
print("|^ ^ ^| | /.\ |") # badass cards to set the mood
print("|^ ^ ^| |(_._)|")
print("|^ ^ ^| | | |")
print("|____6| |____V|")
print('your current card is', card, 'you can hit or stay, what would you like to do?')
playnote(C, 4, 1)
playnote(G, 4, 0.5)
action = input('')
while (action != 'hit') and (action != 'stay'):
print('you can hit or stay')
action = input()
aces = 0
while action == 'hit': # while loop to detect if player typed 'hit'
while (action != 'hit') and (action != 'stay'):
print('you can hit or stay')
action = input()
hitcounter += 1
card = random.randrange(1, 11)
cardtotal += card
if card == 11:
aces += 1
while cardtotal == 21:
print(cardtotal)
print('you have 21! YOU WIN!')
playnote(C, 4, 1)
playnote(G, 4, 0.5)
exit()
while cardtotal >= 22 and aces > 0:
aces -= 1
cardtotal -= 10
while cardtotal >= 22 and aces == 0:
print('you have', cardtotal)
print('you lose :(')
playnote(G, 4, 1)
playnote(C, 4, 0.5)
exit()
while hitcounter == 5:
print('your current total is')
print(cardtotal)
print('you must stay')
action = input()
print('you got', card, 'your current total is')
print(cardtotal)
print('you can hit or stay, what would you like to do?')
playnote(Fh, 4, 0.5)
action = input()
while action == 'stay':
dealercard = random.randrange(1, 11)
dealertotal += dealercard
dealercount += 1
print('the dealer draws', dealercard, 'their total is', dealertotal)
time.sleep(0.25)
if dealertotal > 21:
print('your total', cardtotal, 'dealers total', dealertotal)
print('you win :)')
playnote(C, 4, 1)
playnote(G, 4, 0.5)
exit()
elif dealercount == 5 and dealertotal > 21:
print('your total', cardtotal, 'dealers total', dealertotal)
print('you lose :(')
playnote(G, 4, 1)
playnote(C, 4, 0.5)
exit()
break
if dealertotal > cardtotal: # LOSE
print('your total', cardtotal, 'dealers total', dealertotal)
print('you lose :(')
playnote(G, 4, 1)
playnote(C, 4, 0.5)
exit()
elif cardtotal > dealertotal: # WIN
print('your total', cardtotal, 'dealers total', dealertotal)
print('you win :)')
playnote(C, 4, 1)
playnote(G, 4, 0.5)
exit()
if __name__ == '__main__':
Process(target=loop_a).start()
Process(target=loop_b).start()
Process(target=loop_c).start()
하위 프로세스에서 사용자 입력을 읽는 것은 좋지 않으므로 다음과 같이 기본 프로세스에서 "loop_c"함수를 실행하면됩니다.
(이것은 파일 끝에서 가져온 것입니다)
if __name__ == '__main__':
Process(target=loop_a).start()
Process(target=loop_b).start()
loop_c() # Running this function in the main process
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다