Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 60 additions & 36 deletions turtle.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import turtle as t
import random
import time

score = 0

def show_message(up, down): # 메세지 출력
def show_message(up, down): # 메세지 출력
player.goto(0,200)
player.write(up, False, "center", (20, "bold"))
player.write(up, False, "center", ("Arial", 20, "bold"))
player.goto(0,-200)
player.write(down, False, "center", (15, "bold"))
player.write(down, False, "center", ("Arial",15, "normal"))
player.goto(0,0)
player.showturtle()


def start(): # 게임 시작
playing = True
player.clear()
playing = game_play(playing)
game_end(playing)


def game_play(playing): # 게임 진행 함수
current_time = time.time()
Expand All @@ -25,7 +31,7 @@ def game_play(playing): # 게임 진행 함수

player.showturtle()
player.up()
location = random.choice(locatoin_list)
location = random.choice(location_list)
player.goto(location)
sleep_time = random.uniform(1, 2)
time.sleep(sleep_time)
Expand All @@ -35,24 +41,24 @@ def game_end(playing): # 게임 종료 함수
global score
if not playing:
score_board.clear()
message("Game Over!", text)
text = "Your Score : %d" % score
show_message("Game Over!", text)
score = 0

def turn_up(): # 오른쪽 방향키 함수
global score
if player.position() == (0.00, 200.00):
score = score + 1
player.hideturtle()
show_score(score)

def turn_down():
global score
if player.position() == (0.00, -200.00):
score = score + 1
player.hideturtle()
show_score(score)

def turn_left():
global score
if player.position() == (-200.00, 0.00):
Expand All @@ -68,44 +74,62 @@ def turn_right(): # 왼쪽 방향키 함수
score = score + 1
show_score()

def screen_setting(): # screen 객체 설정 함수
def show_score(score): # 점수 출력
score_board.clear()
score_board.color("white")
score_board.goto(150, 150)
score_board.pencolor("black")
score_board.write("Score : %d" % score, False, "left", ("Arial", 13, "bold"))
score_board.color("white")

screen = t.Screen()
screen.title("Catch Turtle") # 그래픽 창 이름 지정
screen.setup(500, 500) # 창 크기 500*500으로 설정
#def screen_setting(): # screen 객체 설정 함수

def score_board_setting(): # score_board 객체 설정 함수
# screen = t.Screen()
# screen.title("Catch Turtle") # 그래픽 창 이름 지정
# screen.setup(500, 500) # 창 크기 500*500으로 설정
# return screen

score_board = t.Turtle()
color = input("Color of score_board : ")
score_board.color("white") # 보드판 색깔 지정
score_board.goto(150,150)
#def score_board_setting(): # score_board 객체 설정 함수

def main(): # 메인 함수
# score_board = t.Turtle()
# color = input("Color of score_board : ")
# score_board.color("white") # 보드판 색깔 지정
# score_board.goto(150,150)
# return score_board

player = t.Turtle() # 거북이 객체 생성
shape = input("shape : ") # refer to turtle help
player.shape("turtle")
player.speed(0)
player.up()
# def main(): # 메인 함수

screen = screen_setting() # screen 객체 생성
score_board = score_board_setting() # score_board 객체 생성


location_list = [(0,200), (0,-200), (200,0), (-200,0)] # 거북이의 위치(위, 아래, 오른쪽, 왼쪽) 리스트로 생성
print("Welcome to the Catch Turtle Game!")
#main() # 메인 함수 호출
print("==============GAME START!===============")
shape = input("shape : ") # refer to turtle help

screen.onkeypress(game_start, "space") # 스페이스 바를 누르면 start 함수 실행
screen.onkeypress(turn_right, "Right") # 오른쪽 키를 누르면 turn_right 함수 실행
screen.onkeypress(turn_left, "Left") # 왼쪽 키를 누르면 turn_left 함수 실행
screen.onkeypress(turn_up, "Up") # 위 키를 누르면 turn_up 함수 실행
screen.onkeypress(turn_down, "Down") # 아래 키를 누르면 turn_down
screen.listen() # 이 명령어를 실행시켜야 키 입력모드가 실행되어 입력된 키에 반응
player = t.Turtle() # 거북이 객체 생성
player.shape(shape)
player.speed(0)
player.up()

message("Let's Catch Turtle!", "[Space]") # 게임 시작하기 전 첫 화면으로 "Catch Turtle"과 "[Space]"를 출력
screen = t.Screen()
screen.title("Catch Turtle") # 그래픽 창 이름 지정
screen.setup(500, 500) # 창 크기 500*500으로 설정

score_board = t.Turtle()
color = input("Color of score_board : ")
score_board.color(color) # 보드판 색깔 지정
score_board.goto(150,150)
location_list = [(0,200), (0,-200), (200,0), (-200,0)] # 거북이의 위치(위, 아래, 오른쪽, 왼쪽) 리스트로 생성

screen.onkeypress(start, "space") # 스페이스 바를 누르면 start 함수 실행
screen.onkeypress(turn_right, "Right") # 오른쪽 키를 누르면 right 함수 실행
screen.onkeypress(turn_left, "Left")
screen.onkeypress(turn_up, "Up")
screen.onkeypress(turn_down, "Down")
screen.listen() # 이 명령어를 실행시켜야 키 입력모드가 실행되어 입력된 키에 반응

show_message("Let's Catch Turtle!", "[Space]") # 게임 시작하기 전 첫 화면으로

t.done()

print("Welcome to the Catch Turtle Game!")
main() # 메인 함수 호출