聊群
2026-03-26 16:23:02
发布于:浙江
发言发下面↓↓↓↓↓
全部评论 19
import turtle
import time
import random初始化屏幕
wn = turtle.Screen()
wn.title("双人贪吃蛇")
wn.bgcolor("black")
wn.setup(width=800, height=600)
wn.tracer(0)游戏状态
game_paused = False
边界
border = turtle.Turtle()
border.speed(0)
border.color("white")
border.penup()
border.goto(-390, -290)
border.pendown()
for _ in range(2):
border.forward(780)
border.left(90)
border.forward(580)
border.left(90)
border.hideturtle()玩家1的蛇
player1 = turtle.Turtle()
player1.speed(1)
player1.shape("square")
player1.color("blue")
player1.penup()
player1.goto(0, 100)
player1.direction = "stop"玩家2的蛇
player2 = turtle.Turtle()
player2.speed(5)
player2.shape("square")
player2.color("red")
player2.penup()
player2.goto(0, -100)
player2.direction = "stop"食物
food = turtle.Turtle()
food.speed(0)
food.shape("circle")
food.color("green")
food.penup()
food.goto(0, 0)分数显示
score_display = turtle.Turtle()
score_display.speed(0)
score_display.color("white")
score_display.penup()
score_display.hideturtle()
score_display.goto(0, 260)2026-03-26 来自 浙江
1暂停提示
pause_display = turtle.Turtle()
pause_display.speed(0)
pause_display.color("yellow")
pause_display.penup()
pause_display.hideturtle()
pause_display.goto(0, 0)分数
score1 = 0
score2 = 0蛇身
segments1 = []
segments2 = []移动函数
def move():
if player1.direction == "up":
y = player1.ycor()
player1.sety(y + 20)
if player1.direction == "down":
y = player1.ycor()
player1.sety(y - 20)
if player1.direction == "left":
x = player1.xcor()
player1.setx(x - 20)
if player1.direction == "right":
x = player1.xcor()
player1.setx(x + 20)if player2.direction == "up": y = player2.ycor() player2.sety(y + 20) if player2.direction == "down": y = player2.ycor() player2.sety(y - 20) if player2.direction == "left": x = player2.xcor() player2.setx(x - 20) if player2.direction == "right": x = player2.xcor() player2.setx(x + 20)2026-03-26 来自 浙江
1键盘控制
def go_up1():
if player1.direction != "down" and not game_paused:
player1.direction = "up"def go_down1():
if player1.direction != "up" and not game_paused:
player1.direction = "down"def go_left1():
if player1.direction != "right" and not game_paused:
player1.direction = "left"def go_right1():
if player1.direction != "left" and not game_paused:
player1.direction = "right"玩家2控制
def go_up2():
if player2.direction != "down" and not game_paused:
player2.direction = "up"def go_down2():
if player2.direction != "up" and not game_paused:
player2.direction = "down"def go_left2():
if player2.direction != "right" and not game_paused:
player2.direction = "left"def go_right2():
if player2.direction != "left" and not game_paused:
player2.direction = "right"2026-03-26 来自 浙江
1暂停/继续游戏
def toggle_pause():
global game_paused
game_paused = not game_paused
if game_paused:
pause_display.write("游戏暂停 - 按空格键继续", align="center", font=("Courier", 24, "normal"))
else:
pause_display.clear()键盘绑定
wn.listen()
wn.onkeypress(go_up1, "w")
wn.onkeypress(go_down1, "s")
wn.onkeypress(go_left1, "a")
wn.onkeypress(go_right1, "d")
wn.onkeypress(go_up2, "Up")
wn.onkeypress(go_down2, "Down")
wn.onkeypress(go_left2, "Left")
wn.onkeypress(go_right2, "Right")
wn.onkeypress(toggle_pause, "space") # 空格键暂停/继续重置玩家函数
def reset_player(player, segments, start_x, start_y):
player.goto(start_x, start_y)
player.direction = "stop"
for seg in segments:
seg.goto(1000, 1000)
segments.clear()
return 0检查碰撞函数
def check_collisions():
global score1, score2# 边界碰撞检测 if (abs(player1.xcor()) > 380 or abs(player1.ycor()) > 280): score1 = reset_player(player1, segments1, 0, 100) if (abs(player2.xcor()) > 380 or abs(player2.ycor()) > 280): score2 = reset_player(player2, segments2, 0, -100) # 蛇头相撞检测 if player1.distance(player2) < 20: len1 = len(segments1) + 1 # 包括头部 len2 = len(segments2) + 1 if len1 > len2: # 玩家1更长,玩家2死亡 score2 = reset_player(player2, segments2, 0, -100) elif len2 > len1: # 玩家2更长,玩家1死亡 score1 = reset_player(player1, segments1, 0, 100) else: # 长度相同,双方都死亡 score1 = reset_player(player1, segments1, 0, 100) score2 = reset_player(player2, segments2, 0, -100) # 检查玩家1是否撞到玩家2的身体 for seg in segments2: if player1.distance(seg) < 15: score1 = reset_player(player1, segments1, 0, 100) # 检查玩家2是否撞到玩家1的身体 for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?
?
?
?
?
?
?
?
?
?
?
?
?1周前 来自 浙江
0???????
?????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1周前 来自 浙江
0干嘛
1周前 来自 浙江
0
我要进G.T.I
2026-04-12 来自 江苏
0ok
2026-04-12 来自 浙江
0细节你不在我团队里
2026-04-12 来自 浙江
0
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> s(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
vector<long long> a(n);
a[0] = s[0]; // A1 = S1
for (int i = 1; i < n; ++i) {
a[i] = s[i] - s[i-1];
}
for (int i = 0; i < n; ++i) {
cout << a[i] << " ";
}
cout << endl;
return 0;
}2026-04-07 来自 浙江
0#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K, X;
cin >> N >> K >> X;
vector<int> a(N);
for (int i = 0; i < N; ++i) {
cin >> a[i];
}
a.insert(a.begin() + K, X);
for (int num : a) {
cout << num << " ";
}
cout << endl;
return 0;
}2026-04-07 来自 浙江
0第一题:判断判断在判断
2026-04-07 来自 浙江
0#include <bits/stdc++.h>
using namespace std;
int main() {
string key[] = {"and", "not", "that", "the", "you"};
int n;
cin >> n;
bool found = false;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (string k : key) {
if (s == k) {
found = true;
break;
}
}
if (found) break;
}
if (found) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}2026-04-07 来自 浙江
02026-03-26 来自 浙江
0
2026-03-26 来自 浙江
0666
2026-03-26 来自 浙江
0
噔
2026-03-26 来自 浙江
0
2026-03-26 来自 浙江
0万事开头难,中间难,结尾难。
三百六十行,行行干破防。
别人:一支笔一盏灯一个夜晚成就一个奇迹。
我:一部手机一个被窝一个夜晚成就一只熊猫。
不听老人言,哈哈笑百天。
放假前:轻舟已过万重山 放假后:轻舟已撞大冰山。
子曰:打架用砖呼,不亦乱乎!照头乎!乎不死再乎!
佛说:胡扯!我佛慈悲!不亦多乎!一砖乎死!
1+1=3的过程是:
已知aa-bb=(a+b)(a-b);所以aa-bb/a-b=a+b。
假设当a=1,b=1,所以11-11/1-1=1+1。
又因为当“分子等于分母时,此分数等于1”。
所以,“11-11/1-1=1+1”。
化简,即1=2,则1+1=32026-03-26 来自 浙江
0https://attach.acgo.cn/picture/159f2027608f4646be55ff1f6e064d81.jpg?w=237&h=240
2026-03-26 来自 浙江
0
2026-03-26 来自 浙江
0
2026-03-26 来自 浙江
0
2026-03-26 来自 浙江
0
































有帮助,赞一个