tubeCoding
Python
Java demo
한국어(ko)
English(en)
한국어(ko)
로그인
회원가입
새 파일
CSV 파일 추가
파일 이름
취소
파일 생성
코드 실행
해당 파일은 텍스트 편집기에서 표시할 수 없습니다.
콘솔 출력
[{"type": "TextFile", "filename": "main.py", "content": "import turtle\r\n# \uc124\uc815\uac12\r\nHEIGHT = 10\r\nWIDTH = 20\r\nCELL_SIZE = 30 # \ud55c \uce78\uc758 \ud53d\uc140 \ud06c\uae30\r\nPLAYER_COLOR = 'blue'\r\nLANE_COLOR = 'black'\r\nBG_COLOR = 'white'\r\n# turtle \uc138\ud305\r\nscreen = turtle.Screen()\r\nscreen.setup(width=WIDTH * CELL_SIZE + 40, height=HEIGHT * CELL_SIZE + 40)\r\nscreen.bgcolor(BG_COLOR)\r\nscreen.title(\"Turtle Car Lane Game\")\r\nscreen.tracer(0)\r\n# \ucc28\uc120 \uadf8\ub9ac\uae30\uc6a9 turtle (lane)\r\nlane = turtle.Turtle()\r\nlane.hideturtle()\r\nlane.penup()\r\nlane.pensize(3)\r\nlane.color(LANE_COLOR)\r\n# \ucc28\ub7c9 \uc0dd\uc131 (\ud55c \ubc88\ub9cc)\r\ncar = turtle.Turtle()\r\ncar.shape(\"square\")\r\ncar.shapesize(stretch_wid=3, stretch_len=2)\r\ncar.color(PLAYER_COLOR)\r\ncar.penup()\r\ncar.goto(0 + 125 + CELL_SIZE, -HEIGHT // 2 * CELL_SIZE + CELL_SIZE // 2)\r\ncar.showturtle()\r\n# \ucc28\uc120 \uadf8\ub9ac\uae30 \ud568\uc218\r\ndef draw_lanes():\r\n lane.clear()\r\n # \uc88c\uce21 \ucc28\uc120\r\n x = -WIDTH // 2 * CELL_SIZE\r\n lane.goto(x, HEIGHT // 2 * CELL_SIZE)\r\n lane.pendown()\r\n lane.goto(x, -HEIGHT // 2 * CELL_SIZE)\r\n lane.penup()\r\n # \uc911\uc559\uc120\r\n x = 0\r\n lane.color('orange') # \uc911\uc559\uc120\uc744 \uc8fc\ud669\uc0c9\uc73c\ub85c \uc124\uc815\r\n lane.goto(x, HEIGHT // 2 * CELL_SIZE)\r\n lane.pendown()\r\n lane.goto(x, -HEIGHT // 2 * CELL_SIZE)\r\n lane.penup()\r\n lane.color(LANE_COLOR) # \ub2e4\ub978 \ucc28\uc120\uc740 \uc6d0\ub798 \uc0c9\uc0c1\uc73c\ub85c \ubcf5\uc6d0\r\n # \uc6b0\uce21 \ucc28\uc120\r\n x = (WIDTH // 2 - 1) * CELL_SIZE\r\n lane.goto(x, HEIGHT // 2 * CELL_SIZE)\r\n lane.pendown()\r\n lane.goto(x, -HEIGHT // 2 * CELL_SIZE)\r\n lane.penup()\r\n# \ucc28\ub7c9 \uc774\ub3d9 \uac70\ub9ac\r\nMOVE_STEP = 20\r\ndef move_left():\r\n # \uc790\uc720\ub86d\uac8c \uc88c\uce21\uc73c\ub85c \uc774\ub3d9\r\n car.setx(car.xcor() - MOVE_STEP)\r\n update()\r\ndef move_right():\r\n # \uc790\uc720\ub86d\uac8c \uc6b0\uce21\uc73c\ub85c \uc774\ub3d9\r\n car.setx(car.xcor() + MOVE_STEP)\r\n update()\r\ndef update():\r\n draw_lanes()\r\n screen.update()\r\n# \ud0a4 \ubc14\uc778\ub529\r\nscreen.listen()\r\nscreen.onkeypress(move_left, \"Left\")\r\nscreen.onkeypress(move_right, \"Right\")\r\nupdate()\r\nscreen.mainloop()", "locked": true}]