{"id":58,"date":"2025-10-24T15:07:15","date_gmt":"2025-10-24T15:07:15","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/a_mehraban\/?p=58"},"modified":"2025-10-24T15:07:15","modified_gmt":"2025-10-24T15:07:15","slug":"about-what-i-did-today-or-what-i-learn","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/a_mehraban\/2025\/10\/24\/about-what-i-did-today-or-what-i-learn\/","title":{"rendered":"About what I did today or what I learn"},"content":{"rendered":"\n<p>hey so I made a snake game <\/p>\n\n\n\n<p>here it is code for the snake game <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Simple Snake Game in Python 3 for Beginners\n# By @TokyoEdTech\n\nimport turtle\nimport time\nimport random\n\ndelay = 0.1\n\n# Score\nscore = 0\nhigh_score = 0\n\n# Set up the screen\nwn = turtle.Screen()\nwn.title(\"Snake Game by @TokyoEdTech\")\nwn.bgcolor(\"pink\")\nwn.setup(width=600, height=600)\nwn.tracer(0) # Turns off the screen updates\n\n# Snake head\nhead = turtle.Turtle()\nhead.speed(0)\nhead.shape(\"square\")\nhead.color(\"black\")\nhead.penup()\nhead.goto(0,0)\nhead.direction = \"stop\"\n\n# Snake food\nfood = turtle.Turtle()\nfood.speed(0)\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.color(\"white\")\npen.penup()\npen.hideturtle()\npen.goto(0, 260)\npen.write(\"Score: 0  High Score: 0\", align=\"center\", font=(\"Courier\", 24, \"normal\"))\n\n# Functions\ndef go_up():\n    if head.direction != \"down\":\n        head.direction = \"up\"\n\ndef go_down():\n    if head.direction != \"up\":\n        head.direction = \"down\"\n\ndef go_left():\n    if head.direction != \"right\":\n        head.direction = \"left\"\n\ndef go_right():\n    if head.direction != \"left\":\n        head.direction = \"right\"\n\ndef move():\n    if head.direction == \"up\":\n        y = head.ycor()\n        head.sety(y + 20)\n\n    if head.direction == \"down\":\n        y = head.ycor()\n        head.sety(y - 20)\n\n    if head.direction == \"left\":\n        x = head.xcor()\n        head.setx(x - 20)\n\n    if head.direction == \"right\":\n        x = head.xcor()\n        head.setx(x + 20)\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\n        # Hide the segments\n        for segment in segments:\n            segment.goto(1000, 1000)\n        \n        # Clear the segments list\n        segments.clear()\n\n        # Reset the score\n        score = 0\n\n        # Reset the delay\n        delay = 0.1\n\n        pen.clear()\n        pen.write(\"Score: {}  High Score: {}\".format(score, high_score), align=\"center\", font=(\"Courier\", 24, \"normal\")) \n\n\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(-290, 290)\n        y = random.randint(-290, 290)\n        food.goto(x,y)\n\n        # Add a segment\n        new_segment = turtle.Turtle()\n        new_segment.speed(0)\n        new_segment.shape(\"square\")\n        new_segment.color(\"blue\")\n        new_segment.penup()\n        segments.append(new_segment)\n\n        # Shorten the delay\n        delay -= 0.001\n\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\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\n    # Move segment 0 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\n    # Check for head collision with the body segments\n    for segment in segments:\n        if segment.distance(head) &lt; 20:\n            time.sleep(1)\n            head.goto(0,0)\n            head.direction = \"stop\"\n        \n            # Hide the segments\n            for segment in segments:\n                segment.goto(1000, 1000)\n        \n            # Clear the segments list\n            segments.clear()\n\n            # Reset the score\n            score = 0\n\n            # Reset the delay\n            delay = 0.1\n        \n            # Update the score display\n            pen.clear()\n            pen.write(\"Score: {}  High Score: {}\".format(score, high_score), align=\"center\", font=(\"Courier\", 24, \"normal\"))\n\n    time.sleep(delay)\n\nwn.mainloop()<\/code><\/pre>\n\n\n\n<p>and here i post the picture <\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"590\" height=\"601\" data-id=\"60\" src=\"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-24-095312.png\" alt=\"\" class=\"wp-image-60\" srcset=\"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-24-095312.png 590w, https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-24-095312-295x300.png 295w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>and I also work on project stump<\/p>\n","protected":false},"excerpt":{"rendered":"<p>hey so I made a snake game here it is code for the snake game and here i post the [&hellip;]<\/p>\n","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-58","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":61,"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/posts\/58\/revisions\/61"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_mehraban\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}