터틀 모듈을 뿌셔버리자 - !
🐢 천하제일 거북이 레이스 컴페티션
from turtle import Turtle,Screen
import random
screen = Screen()
# 창 크기 설정
screen.setup(width=500, height=400)
chosen = screen.textinput(title="골라 골라😜", prompt="어느색이 이길까요?(영어로 입력)")
color_list= ["red","orange","yellow","green","blue","navy","purple"]
all_turtles = []
i = 0
race_continue = False
for tur in color_list :
new_tur = Turtle(shape="turtle")
new_tur.color(tur)
new_tur.penup()
new_tur.goto(x=-230 ,y = (-120 + i))
i += 40
all_turtles.append(new_tur)
# 선택한 색이 있으면 시작
if chosen in color_list:
race_continue = True
while race_continue :
for tur in all_turtles:
# 랜덤하게 터틀이 움직이는 범위
tur_go = random.randint(0,10)
tur.forward(tur_go)
if tur.xcor() > 230 :
race_continue = False
result = "땡 - !"
if(chosen == tur.color()) :
result = "승리 - !"
screen.textinput("😝",f"{result} , 일등 : {tur.color()[0]}")
screen.exitonclick()
🐢 실행 결과
'Python 🎧' 카테고리의 다른 글
| [python] 핑퐁 게임 - turtle/class/상속/class/super/init (0) | 2024.08.31 |
|---|---|
| [Python] 간단 snake 게임 만들기 - 클래스/슬라이싱/상속 (0) | 2024.08.26 |
| [python] turtle - 한줄 그림 그리기 (이벤트 리스너) (2) | 2024.08.19 |
| [python] turtle 모듈 예제 - n각형/점선/랜덤컬러/스피로그래프 (2) | 2024.08.18 |
| [python] 클래스 - 생성/속성/메소드/초기화 (2) | 2024.08.16 |