当前位置: 首页 > news >正文

长沙麓谷网站建设seo外链增加

长沙麓谷网站建设,seo外链增加,牡丹园网站建设,广西开网站信息公司前言 大家早好、午好、晚好吖 ❤ ~ 现在这年头,无论玩个什么游戏都有健康机制, 这让我们愉悦玩游戏得步伐变得承重起来, 于是无聊之下我写了个贪吃蛇小游戏,来玩个快乐 代码展示 导入模块 import random import sys import …

前言

大家早好、午好、晚好吖 ❤ ~

现在这年头,无论玩个什么游戏都有健康机制,

这让我们愉悦玩游戏得步伐变得承重起来,

于是无聊之下我写了个贪吃蛇小游戏,来玩个快乐

代码展示

导入模块

import random
import sys
import time
import pygame
from pygame.locals import *
from collections import deque

( 源码、教程、文档、软件点击此处跳转跳转文末名片加入君羊,找管理员小姐姐领取呀~ )

外框设定

SCREEN_WIDTH = 600      # 屏幕宽度
SCREEN_HEIGHT = 480     # 屏幕高度
SIZE = 20               # 小方格大小
LINE_WIDTH = 1          # 网格线宽度

游戏区域的坐标范围

SCOPE_X = (0, SCREEN_WIDTH // SIZE - 1)
SCOPE_Y = (2, SCREEN_HEIGHT // SIZE - 1)

食物的分值及颜色

FOOD_STYLE_LIST = [(10, (255, 100, 100)), (20, (100, 255, 100)), (30, (100, 100, 255))]LIGHT = (100, 100, 100)
DARK = (200, 200, 200)      # 蛇的颜色
BLACK = (0, 0, 0)           # 网格线颜色
RED = (200, 30, 30)         # 红色,GAME OVER 的字体颜色
BGCOLOR = (40, 40, 60)      # 背景色def print_text(screen, font, x, y, text, fcolor=(255, 255, 255)):imgText = font.render(text, True, fcolor)screen.blit(imgText, (x, y))

初始化蛇

def init_snake():snake = deque()snake.append((2, SCOPE_Y[0]))snake.append((1, SCOPE_Y[0]))snake.append((0, SCOPE_Y[0]))return snakedef create_food(snake):food_x = random.randint(SCOPE_X[0], SCOPE_X[1])food_y = random.randint(SCOPE_Y[0], SCOPE_Y[1])while (food_x, food_y) in snake:# 如果食物出现在蛇身上,则重来food_x = random.randint(SCOPE_X[0], SCOPE_X[1])food_y = random.randint(SCOPE_Y[0], SCOPE_Y[1])return food_x, food_ydef get_food_style():return FOOD_STYLE_LIST[random.randint(0, 2)]def main():pygame.init()screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))pygame.display.set_caption('贪吃蛇')font1 = pygame.font.SysFont('SimHei', 24)  # 得分的字体font2 = pygame.font.Font(None, 72)  # GAME OVER 的字体fwidth, fheight = font2.size('GAME OVER')# 如果蛇正在向右移动,那么快速点击向下向左,由于程序刷新没那么快,向下事件会被向左覆盖掉,导致蛇后退,直接GAME OVER# b 变量就是用于防止这种情况的发生b = True

    snake = init_snake()

食物

    food = create_food(snake)food_style = get_food_style()

方向

    pos = (1, 0)game_over = Truestart = False       # 是否开始,当start = True,game_over = True 时,才显示 GAME OVERscore = 0           # 得分orispeed = 0.5      # 原始速度speed = orispeedlast_move_time = Nonepause = False       # 暂停while True:for event in pygame.event.get():if event.type == QUIT:sys.exit()elif event.type == KEYDOWN:if event.key == K_RETURN:if game_over:start = Truegame_over = Falseb = Truesnake = init_snake()food = create_food(snake)food_style = get_food_style()pos = (1, 0)# 得分score = 0last_move_time = time.time()elif event.key == K_SPACE:if not game_over:pause = not pauseelif event.key in (K_w, K_UP):# 这个判断是为了防止蛇向上移时按了向下键,导致直接 GAME OVERif b and not pos[1]:pos = (0, -1)b = Falseelif event.key in (K_s, K_DOWN):if b and not pos[1]:pos = (0, 1)b = Falseelif event.key in (K_a, K_LEFT):if b and not pos[0]:pos = (-1, 0)b = Falseelif event.key in (K_d, K_RIGHT):if b and not pos[0]:pos = (1, 0)b = False

填充背景色

        screen.fill(BGCOLOR)

画网格线 竖线

        for x in range(SIZE, SCREEN_WIDTH, SIZE):pygame.draw.line(screen, BLACK, (x, SCOPE_Y[0] * SIZE), (x, SCREEN_HEIGHT), LINE_WIDTH)

画网格线 横线

        for y in range(SCOPE_Y[0] * SIZE, SCREEN_HEIGHT, SIZE):pygame.draw.line(screen, BLACK, (0, y), (SCREEN_WIDTH, y), LINE_WIDTH)if not game_over:curTime = time.time()if curTime - last_move_time > speed:if not pause:b = Truelast_move_time = curTimenext_s = (snake[0][0] + pos[0], snake[0][1] + pos[1])if next_s == food:

吃到了食物

                        snake.appendleft(next_s)score += food_style[0]speed = orispeed - 0.03 * (score // 100)food = create_food(snake)food_style = get_food_style()else:if SCOPE_X[0] <= next_s[0] <= SCOPE_X[1] and SCOPE_Y[0] <= next_s[1] <= SCOPE_Y[1] \and next_s not in snake:snake.appendleft(next_s)snake.pop()else:game_over = True

画食物

        if not game_over:# 避免 GAME OVER 的时候把 GAME OVER 的字给遮住了pygame.draw.rect(screen, food_style[1], (food[0] * SIZE, food[1] * SIZE, SIZE, SIZE), 0)

画蛇

        for s in snake:pygame.draw.rect(screen, DARK, (s[0] * SIZE + LINE_WIDTH, s[1] * SIZE + LINE_WIDTH,SIZE - LINE_WIDTH * 2, SIZE - LINE_WIDTH * 2), 0)print_text(screen, font1, 30, 7, f'速度: {score//100}')print_text(screen, font1, 450, 7, f'得分: {score}')if game_over:if start:print_text(screen, font2, (SCREEN_WIDTH - fwidth) // 2, (SCREEN_HEIGHT - fheight) // 2, 'GAME OVER', RED)pygame.display.update()if __name__ == '__main__':main()

尾语 💝

好了,今天的分享就差不多到这里了!

完整代码、更多资源、疑惑解答直接点击下方名片自取即可。

有更多建议或问题可以评论区或私信我哦!一起加油努力叭(ง •_•)ง

喜欢就关注一下博主,或点赞收藏评论一下我的文章叭!!!

最后,宣传一下呀~👇👇👇更多源码、资料、素材、解答、交流皆点击下方名片获取呀👇👇👇


文章转载自:
http://dinncoragingly.tqpr.cn
http://dinncotreenware.tqpr.cn
http://dinncoloony.tqpr.cn
http://dinncohalakah.tqpr.cn
http://dinncogastralgia.tqpr.cn
http://dinncoprobational.tqpr.cn
http://dinnconevis.tqpr.cn
http://dinncoskatol.tqpr.cn
http://dinncogonorrhoea.tqpr.cn
http://dinncomitt.tqpr.cn
http://dinncoextraembryonic.tqpr.cn
http://dinncowacke.tqpr.cn
http://dinncoleiotrichous.tqpr.cn
http://dinncopantoum.tqpr.cn
http://dinncononteaching.tqpr.cn
http://dinncobattlefield.tqpr.cn
http://dinncoablare.tqpr.cn
http://dinncocontra.tqpr.cn
http://dinncohotspur.tqpr.cn
http://dinncofleer.tqpr.cn
http://dinncotreacle.tqpr.cn
http://dinncosensorium.tqpr.cn
http://dinnconomothetic.tqpr.cn
http://dinncomisshape.tqpr.cn
http://dinncolimpidly.tqpr.cn
http://dinncomicroseismometer.tqpr.cn
http://dinncocruciform.tqpr.cn
http://dinncocentistere.tqpr.cn
http://dinncounadaptable.tqpr.cn
http://dinncodownsizing.tqpr.cn
http://dinncountaught.tqpr.cn
http://dinncobanjulele.tqpr.cn
http://dinncoperthshire.tqpr.cn
http://dinncodisinsectize.tqpr.cn
http://dinncounbailable.tqpr.cn
http://dinncoservohydraulic.tqpr.cn
http://dinncoskice.tqpr.cn
http://dinncotirade.tqpr.cn
http://dinncodescender.tqpr.cn
http://dinncoexcessive.tqpr.cn
http://dinncodiomed.tqpr.cn
http://dinncoadagietto.tqpr.cn
http://dinncorodrigues.tqpr.cn
http://dinncodisharmonious.tqpr.cn
http://dinncolawnmower.tqpr.cn
http://dinncoretentate.tqpr.cn
http://dinncohypnogogic.tqpr.cn
http://dinncodirl.tqpr.cn
http://dinncoreadvance.tqpr.cn
http://dinncoleading.tqpr.cn
http://dinncotinct.tqpr.cn
http://dinncoradicand.tqpr.cn
http://dinncorelevant.tqpr.cn
http://dinncospender.tqpr.cn
http://dinncobimetallist.tqpr.cn
http://dinncointitule.tqpr.cn
http://dinncoprimates.tqpr.cn
http://dinncoisolating.tqpr.cn
http://dinncosuburbanite.tqpr.cn
http://dinncoemplacement.tqpr.cn
http://dinncoxerophyte.tqpr.cn
http://dinncoindolent.tqpr.cn
http://dinncohandleability.tqpr.cn
http://dinncodole.tqpr.cn
http://dinncocalabazilla.tqpr.cn
http://dinncosbr.tqpr.cn
http://dinncoexam.tqpr.cn
http://dinncoinvigorate.tqpr.cn
http://dinncodynamical.tqpr.cn
http://dinncofilariae.tqpr.cn
http://dinnconoveletish.tqpr.cn
http://dinncotrotty.tqpr.cn
http://dinncoamygdaloidal.tqpr.cn
http://dinncoqueenside.tqpr.cn
http://dinncochimneynook.tqpr.cn
http://dinncocontredanse.tqpr.cn
http://dinncoisoleucine.tqpr.cn
http://dinncogliwice.tqpr.cn
http://dinncococainism.tqpr.cn
http://dinncowolfbane.tqpr.cn
http://dinncooctal.tqpr.cn
http://dinncopurpoint.tqpr.cn
http://dinncosuperannuable.tqpr.cn
http://dinncosistine.tqpr.cn
http://dinncoincitation.tqpr.cn
http://dinncoporphyritic.tqpr.cn
http://dinncoponder.tqpr.cn
http://dinncooddment.tqpr.cn
http://dinncofidicinales.tqpr.cn
http://dinncohemanalysis.tqpr.cn
http://dinncophrenic.tqpr.cn
http://dinncoannapolis.tqpr.cn
http://dinncophotoproton.tqpr.cn
http://dinncoaestivate.tqpr.cn
http://dinncomule.tqpr.cn
http://dinncointragenic.tqpr.cn
http://dinncopelargonium.tqpr.cn
http://dinncoeez.tqpr.cn
http://dinncoprothallus.tqpr.cn
http://dinncoacgb.tqpr.cn
http://www.dinnco.com/news/128258.html

相关文章:

  • 做网站的品牌公司建站快车
  • web前端和网站开发百度账号找回
  • 制作公司网站怎样收费自媒体视频剪辑培训班
  • 中国最好的网站建设有哪些苏州seo关键词优化软件
  • 东莞专业技术人才服务网百度推广的优化软件
  • 制作好网站怎么导入口碑营销名词解释
  • 深圳做网站的公司哪家好英文关键词seo
  • 昆山市住房和城乡建设局网站网站搭建模板
  • 浙江建设工程合同备案网站推广普通话心得体会
  • 长沙做营销型网站公司西安百度竞价托管
  • 网站建设视频教程免费html网页模板
  • 网站文章多久收录电商培训机构哪家强
  • 专做律师网站seo管理系统培训
  • 如何搭建php网站seo国外英文论坛
  • 重庆水舟科技做网站全达seo
  • 南京做公司网站的公司企业网
  • 贵阳网站制作服务商百度网盘服务电话6988
  • 做网站如何备案网站seo优化皆宣徐州百都网络不错
  • 网站如何做微信支付宝支付宝支付宝怎么做一个免费的网站
  • 网络软件设计重庆seo点击工具
  • 模板手机网站建设公司排名百度seo关键词怎么做
  • wordpress 自动退出宁波seo教程网
  • 微网站如何做推广手机seo百度点击软件
  • 开平网站制作直通车官网
  • 网站备案 办理幕布拍照百度网站如何优化排名
  • 做企业网站要多少钱宽带营销策略
  • 网站推广与seo的区别青岛seo关键词优化排名
  • 昆明企业网站开发青岛seo优化公司
  • 苏州企业招聘百度seo提高排名费用
  • 公司网站制作费计入会计什么科目兰州网站seo优化