나는 프로그래밍 수업을위한 나의 소개를 위해 슬롯 머신 게임을 만들고있다. 게임에 6 개의 파일이 포함 된 5 개의 임의 이미지를 확보하고 빈 캔버스에 정렬 한 다음 사진을 비교하여 3-in-a-row가 있는지 확인할 수 있습니다. 당신이 이길 지 여부를 알려주고 다시 놀 것을 요청할 것입니다. 사용자가 "y/n"을 선택한 후 다시 실행되도록 게임을 반복해야합니다. 지금까지 제 코드가 있습니다.자이 썬 슬롯 머신 : 게임 루프 만들기
from random import *
def main():
pictureList = setMediaPath("F:\Class Stuff\INF 120\Project X\gamepics")
s = 1 # requestInteger("Slot machine image numbering begins at:")
e = 6 # requestInteger("Slot maching image numbering ends at:")
ext = "jpg" #requestString("Enter the extension ofthe slot machine image files (without a dot):")
mypic = []
for num in range(s, e+1):
mypic = mypic + [(makePicture("smImage" + str(num) + "." + ext))]
#set up the "game board" in a blank window
w = getWidth(mypic[0])
h = getHeight(mypic[0])
ePic = makeEmptyPicture(w*5, h)
show(ePic)
# start the actual game
win = False
inRow = 1
last = -1
#loop through all five slots and set pic for each one a new, random picture. Form list of pictures.
#make a loop to run through the game until win = true.
for i in range(0,5):
imgIndex = randrange(0,len(mypic))
copyInto(mypic[imgIndex], ePic, i*w, 0)
repaint(ePic)
if imgIndex == last:
inRow = inRow + 1
else:
inRow = 1
last = imgIndex
if inRow >= 3:
win = true
if win == true:
showInformation("YOU WIN!!")
rePlay = requestString("Would you like to play again? (y/n)")
else:
showInformation("You Lose...")
requestString("Play again? (y/n)")
미디어 경로는 이미지가있는 컴퓨터의 디렉토리로 설정됩니다. 여기에 이미지가있는 내 Google 드라이브에 대한 링크가 있습니다. https://drive.google.com/folderview?id=0B_ZDD1CZGQYlYjFQWEpjR0NzMGs&usp=sharing.이 작업을 실행하려면 그림이있는 위치와 일치하도록 코드에서 미디어 경로를 변경해야합니다.
감사합니다. 감사!