{"id":38,"date":"2025-10-17T14:13:06","date_gmt":"2025-10-17T14:13:06","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/d_torres\/?p=38"},"modified":"2025-10-17T14:13:06","modified_gmt":"2025-10-17T14:13:06","slug":"free-friday-10-17-2025","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/d_torres\/2025\/10\/17\/free-friday-10-17-2025\/","title":{"rendered":"free friday 10\/17\/2025"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import os\nimport turtle\nimport time\nimport random\ndelay = .1\n# Score\nscore = 0\nhigh_score = 0\n\n# Reset the delay\ndelay = 0.1\n# Set up the screen\nwn = turtle.Screen()\nwn.title(\"Snake Game by @TokyoEdTech\")\nwn.bgcolor(\"green\")\nwn.setup(width=600, height=600)\nwn.tracer(0) # Turns off the screen updates\n\n# Snake food\nfood = turtle. Turtle()\nfood.speed(9)\nfood.shape(\"circle\")\nfood.color(\"red\")\nfood.penup()\nfood.goto(0,100)\n\nsegments = &#91;]\n\n# Pen\npen = turtle.Turtle()\npen.speed(0)\npen.shape(\"square\")\npen.penup()\npen.hideturtle()\npen.goto(0, 260)\npen.write(\"score: 0 high score: 0\", align=\"center\", font=(\"Courier\", 24, \"normal\"))\n\n\n\n#Snake head\nhead = turtle.Turtle()\nhead.speed(8)\nhead.shape(\"square\")\nhead.color(\"black\")\nhead.penup()\nhead.goto(0,0)\nhead.direction = \"stop\"\n\n#Functions\ndef move():\n    if head.direction == \"up\":\n        y = head.ycor()\n        head.sety(y + 20)\n    if head.direction == \"down\":\n        y = head.ycor()\n        head.sety(y - 20)\n    if head.direction == \"left\":\n        x = head.xcor()\n        head.setx(x - 20)\n    if head.direction == \"right\":\n        x = head.xcor()\n        head.setx(x + 20)\n# Functions\ndef go_up():\n    head.direction = \"up\"\n\ndef go_down():\n    head.direction = \"down\"\n\ndef go_left():\n    head.direction = \"left\"\n\ndef go_right():\n    head.direction = \"right\"\n\n#Keyboard bindings\nwn.listen()\nwn.onkeypress(go_up, \"w\")\nwn.onkeypress (go_down, \"s\")\nwn.onkeypress(go_left, \"a\")\nwn.onkeypress(go_right, \"d\")\n\n# Main game Loop\nwhile True:\n    wn.update()\n   \n    # Check for a collision with the border\n    if head.xcor()>290 or head.xcor()&lt;-290 or head.ycor()>290 or head.ycor()&lt;-290:\n        time.sleep(1)\n        head.goto(0,0)\n        head.direction = \"stop\"\n        # Clear the segments list\n        segments = &#91;]\n\n        # reset the score\n        score = 0\n        pen.clear()\n        pen.write(\"Score: {} high score: {}\".format(score, high_score),align=\"center\", font=(\"Courier\", 24, \"normal\"))\n    # Check for a collision with the food\n    if head.distance(food) &lt;20:\n        # Move the food to a random spot\n        x = random.randint(-298, 290)\n        y = random.randint(-290, 290)\n        food.goto(x,y)\n         # Hide the segments\n        for segment in segments:\n            segment.goto(1000, 1000)\n           \n        # Reset the delay\n        delay = 0.1\n\n        # Add a segment\n        new_segment = turtle. Turtle()\n        new_segment.speed(8)\n        new_segment.shape(\"square\")\n        new_segment.color(\"grey\")\n        new_segment.penup()\n        segments.append(new_segment)\n\n        # Shorten the delay\n        delay -= 0.001\n        # Increase the score\n        score += 10\n       \n        if score > high_score:\n            high_score = score\n\n        pen.clear()\n        pen.write(\"Score: {} high score: {}\".format(score, high_score),align=\"center\", font=(\"Courier\", 24, \"normal\"))\n    # Move the end segments first in reverse order\n    for index in range(len(segments)-1, 0, -1):\n        x = segments&#91;index-1].xcor()\n        y = segments &#91;index-1].ycor()\n        segments &#91;index].goto(x, y)\n    #Move segment to where the head is\n    if len(segments) > 0:\n        x = head.xcor()\n        y = head.ycor()\n        segments&#91;0].goto(x,y)\n\n    move()\n    #Check for head collision with the body segments\n    for segment in segments:\n        print(\"distance\",segment.distance)\n        if segment.distance (head) &lt; 20:\n            time.sleep(1)\n            head.goto (0,0)\n            head.direction = \"stop\"\n            # hide the segments\n            for segment in segments:\n                segment.goto(1000,1000)\n            # Clear the segments list\n            segments = &#91;]\n     ````````\n   \n    time.sleep(delay)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/posts\/38","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/comments?post=38"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/posts\/38\/revisions"}],"predecessor-version":[{"id":39,"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/posts\/38\/revisions\/39"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/media?parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/categories?post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_torres\/wp-json\/wp\/v2\/tags?post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}