谁会啊来个给我做做谢谢了我是一点也不会学的时候光摸鱼了真的马上就要交了
要求是不少于150行 带有程序流程图和功能结构图
download.csdn.net 里面随便搜索一个吧,什么贪吃蛇、扫雷、五子棋、俄罗斯方块都可以
简单的贪吃蛇,拿走不谢
import pygame
import random
# 初始化 Pygame 库
pygame.init()
# 定义颜色常量
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
# 设置游戏窗口大小
WINDOW_SIZE = (600, 600)
# 创建游戏窗口
screen = pygame.display.set_mode(WINDOW_SIZE)
# 设置游戏标题
pygame.display.set_caption("Snake Game")
# 设置屏幕更新速度
clock = pygame.time.Clock()
# 定义贪吃蛇类
class Snake:
def __init__(self):
self.positions = [(300, 300), (280, 300), (260, 300)]
self.direction = "RIGHT"
self.score = 0
def move(self):
if self.direction == "RIGHT":
new_head = (self.positions[0][0] + 20, self.positions[0][1])
elif self.direction == "LEFT":
new_head = (self.positions[0][0] - 20, self.positions[0][1])
elif self.direction == "UP":
new_head = (self.positions[0][0], self.positions[0][1] - 20)
elif self.direction == "DOWN":
new_head = (self.positions[0][0], self.positions[0][1] + 20)
self.positions.insert(0, new_head)
if self.positions[0] == food.position:
food.randomize_position()
self.score += 10
else:
self.positions.pop()
def change_direction(self, new_direction):
if new_direction == "RIGHT" and not self.direction == "LEFT":
self.direction = "RIGHT"
elif new_direction == "LEFT" and not self.direction == "RIGHT":
self.direction = "LEFT"
elif new_direction == "UP" and not self.direction == "DOWN":
self.direction = "UP"
elif new_direction == "DOWN" and not self.direction == "UP":
self.direction = "DOWN"
def draw(self, surface):
for p in self.positions:
pygame.draw.rect(surface, GREEN, pygame.Rect(p[0], p[1], 20, 20))
# 定义食物类
class Food:
def __init__(self):
self.position = (0, 0)
self.randomize_position()
def randomize_position(self):
self.position = (random.randint(0, 29) * 20, random.randint(0, 29) * 20)
def draw(self, surface):
pygame.draw.rect(surface, RED, pygame.Rect(self.position[0], self.position[1], 20, 20))
# 创建贪吃蛇和食物对象
snake = Snake()
food = Food()
# 游戏主循环
while True:
# 处理游戏事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
snake.change_direction("RIGHT")
elif event.key == pygame.K_LEFT:
snake.change_direction("LEFT")
elif event.key == pygame.K_UP:
snake.change_direction("UP")
elif event.key == pygame.K_DOWN:
snake.change_direction("DOWN")
# 移动贪吃蛇
snake.move()
# 绘制游戏背景
screen.fill(WHITE)
# 绘制贪吃蛇和食物
snake.draw(screen)
food.draw(screen)
# 绘制得分文本
font = pygame.font.SysFont("arial", 18)
score_text = font.render("Score: " + str(snake.score), True, BLACK)
screen.blit(score_text, (10, 10))
# 更新游戏界面
pygame.display.update()
# 控制游戏帧率
clock.tick(10)
不知道你这个问题是否已经解决, 如果还没有解决的话:import random
from selenium import webdriver
import time
import schedule as schedule
def run():
url = 'https://www.wjx.cn/vm/YD3Xwc3.aspx'
# 躲避智能检测
option = webdriver.ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=option)
driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'
})
driver.get(url)
# 总共有13个题目
i = 1
while i <= 13:
base_xpath1 = '//*[@id="div{}"]'.format(i)
base_xpath3 = base_xpath1 + '/div[2]/div'
a = driver.find_elements_by_xpath(base_xpath3)
# print(len(a))
# 在选项个数范围内,随机生成一个数字 如有四个选项,随机生成数字3
b = random.randint(1, len(a))
# print(b)
# 通过随机数字,点击该数字的选项
driver.find_element_by_css_selector('#div{} > div.ui-controlgroup > div:nth-child({})'.format(i, b)).click()
time.sleep(1)
# 当第六个问题回答第四个选项(其他)时,需要填写
if i == 6 and b == 4:
time.sleep(1)
# 这里你可以每隔一段时间更改send_keys中的内容,也可以将答案写出来,然后随机选择哪个选项
driver.find_element_by_css_selector('#tqq6_4').send_keys('QQ群和微信群')
# 当第三个问题答案是是时,跳到5
if i == 3 and b == 1:
i = 5
else:
i += 1
# 点击提交按钮
time.sleep(0.5)
driver.find_element_by_xpath('//*[@id="ctlNext"]').click()
# 出现点击验证码验证
time.sleep(1)
driver.find_element_by_xpath('//*[@id="alert_box"]/div[2]/div[2]/button').click()
time.sleep(0.5)
driver.find_element_by_xpath('//*[@id="rectMask"]').click()
time.sleep(4)
# 关闭页面
handles = driver.window_handles
driver.switch_to.window(handles[0])
time.sleep(1)
# 刷新页面(可能不需要)
driver.refresh()
# 关闭当前页面,如果只有一个页面,则也关闭浏览器
driver.close()
schedule.every(5).seconds.do(run)
while True:
schedule.run_pending()
①以上代码定位元素最好copy selector,因为之前在浏览器copy xpath的时候有时候会报错。
②当第三题的答案为否时,才弹出第四题,当第三题的答案为是时,跳过第四题。
③两个if函数不能调换,否则i += 1运行时会找不到第六题其他选项的文本输入而报错。
④len(a)表示选项的个数,b表示随机选择一个数字(不会超出选项的个数)
⑤
import schedule as schedule
def run():
pass
schedule.every(5).seconds.do(run)
while True:
schedule.run_pending()
以上代码表示每隔5秒运行一次程序的模板,以后可以套用,隔的时间可以自己更改