{"id":10,"date":"2025-10-10T14:12:53","date_gmt":"2025-10-10T14:12:53","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/q_alobeid\/?p=10"},"modified":"2025-10-10T14:14:38","modified_gmt":"2025-10-10T14:14:38","slug":"the-table-tennis-game-is-over","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/q_alobeid\/2025\/10\/10\/the-table-tennis-game-is-over\/","title":{"rendered":"The ping pong game is over."},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Very fun game I had fun making it<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import turtle\n\nwindow = turtle.Screen()\nwindow.title(\"ping pong Game By sabryHosny\")\nwindow.setup(width=800, height=600)\nwindow.tracer(0)\nwindow.bgcolor(.1, .1, .1)\n\nball = turtle.Turtle()\nball.speed(0)\nball.shape(\"square\")\nball.color(\"white\")\n\nball.shapesize(stretch_len=1, stretch_wid=1)\nball.goto(x=0, y=0)\nball.penup()\nball_dx, ball_dy = 1, -1\nball_speed = .5\n\ncenter_line = turtle.Turtle()\ncenter_line.speed(0)\ncenter_line.shape(\"square\")\ncenter_line.color(\"white\")\n\ncenter_line.shapesize(stretch_len=.1, stretch_wid=25)\ncenter_line.penup()\ncenter_line.goto(0, 0)\n\nplayer1 = turtle.Turtle()\nplayer1.speed(0)\nplayer1.shape(\"square\")\nplayer1.shapesize(stretch_len=.1, stretch_wid=5)\nplayer1.color(\"blue\")\nplayer1.penup()\nplayer1.goto(x=-350, y=0)\n\n\nplayer2 = turtle.Turtle()\nplayer2.speed(0)\nplayer2.shape(\"square\")\nplayer2.shapesize(stretch_len=.1, stretch_wid=5)\nplayer2.color(\"red\")\nplayer1.penup()\nplayer2.goto(x=350, y=0)\n\nscore = turtle.Turtle()\nscore.speed(0)\nscore.color(\"white\")\nscore.penup()\nscore.goto(x=0, y=260)\nscore.write(\"player1: 0 player: 0\", align=\"center\", \n            font=(\"Courier\", 14, \"normal\"))\nscore.hideturtle()\np1_scor, p2_scor = 0, 0\n\nplayers_speed = 20\n\n\ndef p1_move_up():\n    player1.sety(player1.ycor() + players_speed)\n\ndef p1_move_down():\n    player1.sety(player1.ycor() - players_speed)\n\ndef p2_move_up():\n    player2.sety(player2.ycor() + players_speed)\n\ndef p2_move_down():\n    player2.sety(player2.ycor() - players_speed)\n\nwindow.listen()\nwindow.onkeypress(p1_move_up, \"w\")\nwindow.onkeypress(p1_move_down, \"s\")\nwindow.onkeypress(p2_move_up, \"Up\")\nwindow.onkeypress(p2_move_down, \"Down\")\n\n\nwhile True:\n    window.update()\n\n    ball.setx(ball.xcor() + (ball_dx * ball_speed))\n    ball.setx(ball.xcor() + (ball_dx * ball_speed))   \n\n    if(ball.ycor() > 290):\n        ball.sety(290)\n        ball_dy *= -1\n\n    if(ball.ycor() > -290):\n        ball.sety(-290)\n        ball_dy *= -1\n\n    if ball.xcor() &lt; -340 and ball.xcor() > -350 and ball.ycor() > (player1.ycor()-60) and ball.ycor() &lt; (player1.ycor()+60):\n        ball.setx(-340)\n        ball_dx *=-1\n\n    if ball.xcor() > -340 and ball.xcor() &lt; -350 and ball.ycor() > (player2.ycor()-60) and ball.ycor() &lt; (player2.ycor()+60):\n        ball.setx(-340)\n        ball_dx *=-1\n\n    if(ball.xcor() > 390):\n       ball.goto(0, 0)\n       ball_dx *= -1\n       score.clear()\n       p1_score += -1\n       score.write(f\"player1: {p1_score} player: {p2_score}\", align=\"center\", \n            font=(\"Courier\", 14, \"normal\"))\n    \n    if(ball.xcor() &lt; -390): \n       ball.goto(0, 0)\n       ball_dx *= -1\n       score.clear()\n       ball_dx *= -1\n       p2_score += 1\n       score.write(f\"player1: {p1_score} player: {p2_score}\", align=\"center\", \n               font=(\"Courier\", 14, \"normal\"))<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Very fun game I had fun making it<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":2,"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":12,"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/posts\/10\/revisions\/12"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/q_alobeid\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}