Commit 3654d8cf by BellCodeEditor

save project

parent 2919c58f
Showing with 135 additions and 13 deletions
This source diff could not be displayed because it is too large. You can view the blob instead.
import turtle
\ No newline at end of file
#1引入需要的模块
import pygame
import random
#1配置图片地址
IMAGE_PATH = 'imgs/'
#1设置页面宽高
scrrr_width=800
scrrr_height =560
#1创建控制游戏结束的状态
GAMEOVER = False
#1主程序
class MainGame():
#1加载游戏窗口
def init_window(self):
#1调用显示模块的初始化
pygame.display.init()
#1创建窗口
MainGame.window = pygame.display.set_mode([scrrr_width,scrrr_height]) #
#1开始游戏
def start_game(self):
#1初始化窗口
self.init_window()
#1只要游戏没结束,就一直循环
while not GAMEOVER:
#1渲染白色背景
MainGame.window.fill((255, 255, 255))
#1实时更新
pygame.display.update()
#1启动主程序
if __name__ == '__main__':
game = MainGame()
game.start_game()
#2 创建关数,得分,剩余分数,钱数
shaoguan = 1
score = 0
remnant_score = 100
money = 200
#2 文本绘制
def draw_text(self, content, size, color):
pygame.font.init()
font = pygame.font.SysFont('kaiti', size)
text = font.render(content, True, color)
return text
#2 加载帮助提示
def load_help_text(self):
text1 = self.draw_text('1.按左键创建向日葵 2.按右键创建豌豆射手', 26, (255, 0, 0))
MainGame.window.blit(text1, (5, 5))
#2 渲染的文字和坐标位置
MainGame.window.blit(self.draw_text('当前钱数$: {}'.format(MainGame.money), 26, (255, 0, 0)), (500, 40))
MainGame.window.blit(self.draw_text(
'当前关数{},得分{},距离下关还差{}分'.format(MainGame.shaoguan, MainGame.score, MainGame.remnant_score), 26,
(255, 0, 0)), (5, 40))
self.load_help_text()
3.创建地图类,初始化地图和坐标
#3 创建地图类
class Map():
#3 存储两张不同颜色的图片名称
map_names_list = [IMAGE_PATH + 'map1.png', IMAGE_PATH + 'map2.png']
#3 初始化地图
def __init__(self, x, y, img_index):
self.image = pygame.image.load(Map.map_names_list[img_index])
self.position = (x, y)
# 是否能够种植
self.can_grow = True
#3 加载地图
def load_map(self):
MainGame.window.blit(self.image,self.position)
#3 存储所有地图坐标点
map_points_list = []
#3 存储所有的地图块
map_list = []
#3 初始化坐标点
def init_plant_points(self):
for y in range(1, 7):
points = []
for x in range(10):
point = (x, y)
points.append(point)
#4 图片加载报错处理
LOG = '文件:{}中的方法:{}出错'.format(__file__,__name__)
#4 植物类
class Plant(pygame.sprite.Sprite):
def __init__(self):
super(Plant, self).__init__()
self.live=True
# 加载图片
def load_image(self):
if hasattr(self, 'image') and hasattr(self, 'rect'):
MainGame.window.blit(self.image, self.rect)
else:
print(LOG)
#4 存储所有植物的列表
plants_list = []
import turtle
pen1=turtle.Pen()
pen1.left(45)
pen1.forward(100)
pen1.circle(50,180)
pen1.right(90)
pen1.circle(50,180)
pen1.forward(100)
pen1.hideturtle()
import turtle
turtle.penup()
turtle.right(90)
turtle.forward(-50)
turtle.left(90)
turtle.forward(-200)
turtle.pendown()
turtle.pensize(9)
turtle.color("blue")
turtle.circle(100)
turtle.penup()
turtle.forward(240)
turtle.pendown()
turtle.pensize(9)
turtle.color("black")
turtle.circle(100)
turtle.penup()
turtle.forward(250)
turtle.pendown()
turtle.pensize(10)
turtle.color("red")
turtle.circle(100)
turtle.penup()
turtle.forward(-275)
turtle.right(-90)
turtle.pendown()
turtle.pensize(10)
turtle.color("yellow")
turtle.circle(100)
turtle.penup()
turtle.left(-90)
turtle.forward(50)
turtle.right(90)
turtle.pendown()
turtle.pensize(10)
turtle.color("green")
turtle.circle(100)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment