1,030
社区成员
发帖
与我相关
我的任务
分享
import pygame, os,random,time pygame.init() screen = pygame.display.set_mode((1283, 1125)) map = pygame.image.load(os.path.join('图片1.png')) p = map.get_rect() secon = 5000 difang = 0 font_name = os.path.join("font.ttf") p.size = (500,400) dikuai = ['一年一班','一年二班','一年三班','一年四班','一年五班','一年六班','一年七班','一年八班','一年九班','一年十班', '二年一班','二年二班','二年三班','二年四班','二年五班','二年六班','二年七班','二年八班','二年九班','二年十班', '三年一班','三年二班','三年三班','三年四班','三年五班','三年六班','三年七班','三年八班','三年九班','三年十班', '四年一班','四年二班','四年三班','四年四班','四年五班','四年六班','四年七班','四年八班','四年九班','四年十班', '五年一班','五年二班','五年三班','五年四班','五年五班','五年六班','五年七班','五年八班','五年九班','五年十班', '六年一班','六年二班','六年三班','六年四班','六年五班','六年六班','六年七班','六年八班','六年九班','六年十班',] wofang = [] class player(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load(os.path.join('a.png')) self.image.set_colorkey((0,0,0)) self.rect = self.image.get_rect() self.rect.x = 5 self.rect.y = 5 self.speedx = 74 self.speedy = 0 self.yiyongyoudedi = [] def yidong(self): if self.rect.x < 1189 and self.rect.y == 5: self.speedy = 0 self.speedx = 74 self.rect.x += self.speedx elif self.rect.x != 5 and self.rect.y == 1041: self.speedx = -74 self.speedy = 0 self.rect.x += self.speedx elif self.rect.x == 5 and self.rect.y > 5: self.speedy = -74 self.speedx = 0 self.rect.y += self.speedy elif self.rect.x == 1189 and self.rect.y != 1041: self.speedy = 74 self.speedx = 0 self.rect.y += self.speedy def draw_text(surf,text,size,x,y,colour): font = pygame.font.Font(font_name,size) text_surface = font.render(text,True,colour) trext_rect = text_surface.get_rect() trext_rect.centerx = x trext_rect.top = y surf.blit(text_surface,trext_rect) Player = player() all_player = pygame.sprite.Group() clock = pygame.time.Clock() clock.tick(1) all_player.add(Player) while True: clock.tick(5) screen.blit(map,(0,0)) for item in range(1,9): screen.blit(map, (0, 0)) draw_text(screen, '步数:'+str(random.randint(1,6)), 60, 500, 400, (0, 0, 0)) all_player.draw(screen) draw_text(screen, 'player1所拥有钱' + str(secon) + '元', 60, 500, 500, (0, 0, 0)) pygame.display.update() time.sleep(0.1) w = random.randint(1,6) screen.blit(map, (0, 0)) draw_text(screen, '步数:' + str(w), 60, 500, 400, (0, 0, 0)) draw_text(screen, 'player1所拥有钱' + str(secon) + '元', 60, 500, 500, (0, 0, 0)) pygame.display.update() for i in range(w): Player.yidong() difang += 1 if difang >= 60: difang -= 60 secon += 2000 all_player.draw(screen) draw_text(screen,'player1所拥有钱'+str(secon)+'元',60,500,500,(0,0,0)) pygame.display.update() if secon >= 1000: draw_text(screen, f'请问您是否要买下{dikuai[difang]}这块地。是请按下1,否请按下2', 20, 500, 600, (0, 0, 0)) time.sleep(1) passed = pygame.key.get_pressed() while not passed[pygame.K_1] and not passed[pygame.K_2] and not dikuai[difang] in wofang: clock.tick(5) screen.blit(map, (0, 0)) passed = pygame.key.get_pressed() draw_text(screen, f'请问您是否要买下{dikuai[difang]}这块地。是请按下1,否请按下2', 60, 500, 600, (0, 0, 0)) draw_text(screen, '步数:' + str(w), 60, 500, 400, (0, 0, 0)) draw_text(screen, 'player1所拥有钱' + str(secon) + '元', 40, 500, 500, (0, 0, 0)) all_player.draw(screen) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() if passed[pygame.K_1] and secon >= 1000: secon -= 1000 wofang.append(dikuai[difang]) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() 以上是我copy的代码 然后我图片啥的也都下好了 出现这个报错我在想是重名了吗还是路径不太对??有懂的大佬解释一下嘛!!