본문 바로가기
프로그램

[파이썬] 문제 : 터틀 주사위 게임(그림 사용)

by 오디세이99 2023. 4. 6.
728x90
반응형

import turtle
import random

t=turtle.Turtle()
# t.shape("turtle")

s=turtle.Screen()
img_lst = ["", "dice1.gif","dice2.gif","dice3.gif","dice4.gif","dice5.gif","dice6.gif"]              #이미지 불러오기

user_win = 0
comp_win = 0
while True:
    _ = input("사용자 주사위(Enter):")
    user_no = random.randint(1, 6)
    comp_no = random.randint(1, 6)

    t.home()
    t.clear()
    image = img_lst[user_no]
    s.addshape(image)         #이미지 추가하기
    t.shape(image)            #커서 모양을 이미지 모양으로
    t.stamp()                 #스탬프 찍기 
    
    t.up()
    t.goto(150, 0)
    t.down()
    
    image = img_lst[comp_no]
    s.addshape(image)         #이미지 추가하기
    t.shape(image)            #커서 모양을 이미지 모양으로
    t.stamp()                 #스탬프 찍기 
    
    t.up()
    t.goto(150, 0)
    t.down()
    
    if user_no > comp_no:
        print(f"플레이어 승리 (사용자 = {user_no}, 컴퓨터 = {comp_no})")
    elif user_no < comp_no:
        print(f"컴퓨터 승리 (사용자 = {user_no}, 컴퓨터 = {comp_no})")
    
    print()
    yn = input("다시 하시겠습니까?(재시작:r, 종료:q,Q): ")
    
    if yn.upper() == 'Q':      # r 입력시 재시작 이어야 하나 q가 아니면 모두 재시작이 됨
        break

dice1.gif
0.00MB
dice2.gif
0.00MB
dice3.gif
0.00MB
dice4.gif
0.00MB
dice5.gif
0.00MB
dice6.gif
0.00MB

728x90
반응형

댓글