約 59,100 件の結果
リンクを新しいタブで開く
  1. Creating a SnakeIO-style game in Python can be done using either Turtle (built-in) or Pygame (more advanced). Below is a simple and functional implementation using the Turtle module, which is beginner-friendly and requires no external installation.

    import turtle as t
    import time
    import random

    delay = 0.1
    score = 0
    high_score = 0

    # Screen setup
    sc = t.Screen()
    sc.title("SnakeIO Game")
    sc.bgcolor("black")
    sc.setup(width=600, height=600)
    sc.tracer(0)

    # Snake head
    head = t.Turtle()
    head.shape("square")
    head.color("green")
    head.penup()
    head.goto(0, 0)
    head.direction = "stop"

    # Food
    food = t.Turtle()
    food.speed(0)
    food.shape("circle")
    food.color("red")
    food.penup()
    food.goto(0, 100)

    segments = []

    # Score display
    pen = t.Turtle()
    pen.speed(0)
    pen.color("white")
    pen.penup()
    pen.hideturtle()
    pen.goto(0, 260)
    pen.write("Score: 0 High Score: 0", align="center", font=("Courier", 24, "normal"))

    # Movement functions
    def go_up():
    if head.direction != "down":
    head.direction = "up"
    def go_down():
    if head.direction != "up":
    head.direction = "down"
    def go_left():
    if head.direction != "right":
    head.direction = "left"
    def go_right():
    if head.direction != "left":
    head.direction = "right"

    def move():
    if head.direction == "up":
    head.sety(head.ycor() + 20)
    if head.direction == "down":
    head.sety(head.ycor() - 20)
    if head.direction == "left":
    head.setx(head.xcor() - 20)
    if head.direction == "right":
    head.setx(head.xcor() + 20)

    # Key bindings
    sc.listen()
    sc.onkeypress(go_up, "Up")
    sc.onkeypress(go_down, "Down")
    sc.onkeypress(go_left, "Left")
    sc.onkeypress(go_right, "Right")

    # Main game loop
    while True:
    sc.update()

    # Border collision
    if abs(head.xcor()) > 290 or abs(head.ycor()) > 290:
    time.sleep(1)
    head.goto(0, 0)
    head.direction = "stop"
    for segment in segments:
    segment.goto(1000, 1000)
    segments.clear()
    score = 0
    delay = 0.1
    pen.clear()
    pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 24, "normal"))

    # Food collision
    if head.distance(food) < 20:
    x, y = random.randint(-290, 290), random.randint(-290, 290)
    food.goto(x, y)

    new_segment = t.Turtle()
    new_segment.speed(0)
    new_segment.shape("square")
    new_segment.color("grey")
    new_segment.penup()
    segments.append(new_segment)

    delay -= 0.001
    score += 10
    high_score = max(high_score, score)
    pen.clear()
    pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 24, "normal"))

    # Move body segments
    for i in range(len(segments)-1, 0, -1):
    x, y = segments[i-1].xcor(), segments[i-1].ycor()
    segments[i].goto(x, y)
    if segments:
    segments[0].goto(head.xcor(), head.ycor())

    move()

    # Self collision
    for segment in segments:
    if segment.distance(head) < 20:
    time.sleep(1)
    head.goto(0, 0)
    head.direction = "stop"
    for seg in segments:
    seg.goto(1000, 1000)
    segments.clear()
    score = 0
    delay = 0.1
    pen.clear()
    pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 24, "normal"))

    time.sleep(delay)

    t.done()
    コピーしました。
    フィードバック
    ありがとうございました!詳細をお聞かせください
  2. A Simple Snake Game made in Python 3 · GitHub

    Simple and fun snake concept with great Python implementation. Key controls are convenient, and the mechanics of eating food and making the snake bigger add …

  3. python snake game

    You learned how to create the game snake in Python along with concepts such as collision detection, image loading and event handling. Many things could be …

  4. あなたの興味がありそうな検索

  5. Build Snake Game in Python Using Turtle Module

    • Here, we will explain the easy way to code the snake gamein python. It is recommended to go throw the below step. Step 1: Firstly, we will import all the modules into the program, and we will give the default value for the game. Step 2: 1. Now, we will create the window screen for the game, and also we will create the head of the snake and food for...
    pythonguides.com でさらに表示
  6. How to Make a Snake Game in Python - The Python Code

    • さらに表示

    Learn how to build a classic snake game using Pygame in Python. This detailed step-by-step tutorial explains how to initialize Pygame, generate food for the snake, draw game objects, update the snake's …

  7. Pythonade - Building a Snake Game with Python and Pygame

    In this tutorial, we'll build a classic Snake game using Python's Pygame library, focusing on vector graphics for a clean, retro aesthetic. We'll break this down into four progressive stages, each adding …

  8. Snake Game Using Python - 101 Computing

    2024年3月21日 · In this Python programming challenge, we are going to revisit the classic game called Snake. In this game, the player controls a snake using the arrow keys of the keyboard.

  9. Create a Snake Game in Python using Turtle [Full Code …

    2024年4月3日 · Create Snake Game in Python with this step-by-step guide. Final code available with expert tips. No prior experience needed!

  10. Python Code for Snake Game Using Pygame - Full …

    2024年7月20日 · Learn how to code a Snake game in Python with Pygame. This tutorial includes the complete source code and step-by-step instructions for …

  11. Mastering the Snake Game in Python: A Comprehensive Guide

    2025年4月19日 · In this blog, we will delve into the fundamental concepts of the Snake Game in Python, explore usage methods, discuss common practices, and highlight best practices to create an …