def __init__(self): self.clock = cl.Clock(self) self.week = cl.Week(self) self.calendar = cl.SecularCalendar() self.productionAI = ai.ProductionAI(self) self.jobPoster = ai.JobPoster(self) self.hirer = ai.Hirer(self) self.firer = ai.Firer(self) self.startupAI = ai.StartupAI() self.builder = ai.Builder(self) self.salaryPayer = ai.SalaryPayer(self) ourGen = generator.generator(self) self.ourWorld = ourGen.generateWorld(10000, 10, 10) Jonestown = d.getLocality()[0] #char address = Jonestown.find_property() yourHome = u.House(Jonestown, address) Jonestown.claim_node(address, yourHome) self.char = ai.Character(self, "Markemus", "Williamson", 0, Jonestown, yourHome, d.getReligions()[0]) yourHome.addTenant(self.char) spouse = p.People(self, "Susan", "Spinster", 1, Jonestown, yourHome, d.getReligions()[0]) yourHome.addTenant(spouse) self.char.addCapital(10000) #makes ourGen.makeSpouses() ourGen.makeFriends() ourGen.makeBosses() ourGen.makeChurches(Jonestown) ourGen.assignChurches() self.gui = gui.gui(self.char)
def main(argv=sys.argv): user1 = people.People('쟁반통닭') user1.print_info() user2 = student.Student('Hyunsu', '201550320') user2.print_info() user3 = teacher.Teacher('정화', '133442') user3.print_info() user3.set_lecture('영어') user3.print_lecture()
def get_html(self, position): mod = self.get_module() if mod == "PER": p = people.People(self.tags, self.description) return p.get_html(False) elif mod == "GEO": return rome_rio.get_rome_rio(position, self.tags) elif mod == "BUY": return amazon_search.get_amazon_items(self.tags, False) elif mod == "MOV": f = film.Film(self.tags, self.description) f.get_info() return f.get_html()
def generatePeople(self, p_quantity, locality, houseList, religionList): lastNameList = d.getLastNameList() for count in range(p_quantity): #gender if (count % 2 == 0): gender = 0 else: gender = 1 #name firstNameList = d.getFirstNameList(gender) i = random.randrange(len(firstNameList)) firstname = firstNameList[i] j = random.randrange(len(lastNameList)) lastname = lastNameList[j] #home k = (count // 2) home = houseList[k] #religion if count < (p_quantity / 2): religion = religionList[0] else: religion = religionList[1] #gen gennedPerson = p.People(self.model, firstname, lastname, gender, locality, home, religion) gennedPerson.addCapital(100) gennedPerson.home.addTenant(gennedPerson)
def peoplelist(): d = {} d['name'] = 'Matthieu Labousse' d['aff'] = 'ESPCI' d['email'] = '*****@*****.**' ex = p.People(d) ex.display() d = {} d['name'] = 'Vincent Bacot' d['aff'] = 'University Paris-Diderot' d['email'] = '*****@*****.**' d['dates'] = '' ex = i.Intern(d) ex.display() print('Students') filename = '/Users/stephane/Documents/Etudiants/Recherche/internships.csv' with open(filename) as csvfile: reader = list(csv.DictReader(csvfile, delimiter=';')) reader.sort(key=lambda x: x['Year'], reverse=True) for row in reader: student = i.Intern(row) student.display_fancy() print('') print('Collaborators') filename = '/Users/stephane/Documents/Etudiants/Recherche/collaborators.csv' with open(filename) as csvfile: reader = list(csv.DictReader(csvfile, delimiter=';')) reader.sort(key=lambda x: x['Name']) for row in reader: student = collab.Collab(row) print(student.display_fancy())
import people zhangs = people.People('zhang san') zhangs.run() zhangs.sleep() people.People('lis ').run() people.People('wangw').run() people.People('zhaol').run()
POINT_RADIUS = 5 BLACK = (0,0,0) WHITE = (255,255,255) PINK = (255,192,203) RED = (255,0,0) # 初始化pygame pygame.init() # 设置窗口与窗口标题 windowSurface = pygame.display.set_mode((WIDTH,HEIGHT),0,8) pygame.display.set_caption('疫情模拟') # 初始化人群 p = people.People(600, 1) COLORS = [BLACK, PINK, RED] # 事件循环 while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() windowSurface.fill(WHITE) # 设置画布背景 起到擦除的作用 for i in range(len(p._status)): # 健康 x_point = p._people[i][0] y_point = p._people[i][1]
for index, info in roles.items(): print(f'*****{index}:{info["name"]}, [性别:{info["gender"]},' f'式神:{info["god"]}, 主人:{info["master"]}, ' f'攻击力:{info["aggressivity"]}, 生命值:{info["life"]}]') flag = True while flag: role_id = input('请选择角色:') if role_id not in roles.keys(): print('请选择正确的角色') continue #实例化角色,打印选中角色详细信息 user = people.People(roles[role_id]) user.get_info() print('-----您将进入游戏场景选择-----------------------') for scene_id, scene_info in scene_dict.items(): print(f'*****{scene_id}:{scene_info}') chose_scene = input('请选择场景:') if chose_scene not in scene_dict.keys(): print('请选择正确的场景') continue # 实例化场景 game_scene = scene.Scene(user) if chose_scene == '4': status = game_scene.yin_jie_lie_feng()
def main(argv=sys.argv): name = argv[1] user = people.People(name) user.print_name()
#!/usr/bin/python # -*- coding: UTF-8 -*- import math import people def sum(a, b): total = a + b print total return total perople = people.People("zangah") perople.disPlayName() perople.disPlaySend()
def main(): clock = pygame.time.Clock() Gamestate = 0 text_font = pygame.font.Font('font/avqest.ttf', 64) text_startmenu = text_font.render(u'Caveman and treasure', True, (255, 255, 255)) text_startmenu_rect = text_startmenu.get_rect() text_startmenu_rect.center = (width / 2, height / 2) text_nextlevel = text_font.render(u'Next level', True, (255, 255, 255), (0, 0, 0)) text_nextlevel_rect = text_nextlevel.get_rect() text_nextlevel_rect.center = (width / 2, height / 2 + 200) text_congratulation = text_font.render(u'Congratulation!', True, (255, 255, 255), (0, 0, 0)) text_congratulation_rect = text_congratulation.get_rect() text_congratulation_rect.center = (width / 2, height / 2 - 200) text_font1 = pygame.font.SysFont("times new roman", 20) text_dfs = text_font1.render(u'View DFS searching', True, (255, 255, 255)) text_dfs_rect = text_dfs.get_rect() text_dfs_rect.center = (width - 130, 100) text_bfs = text_font1.render(u'View BFS searching', True, (255, 255, 255)) text_bfs_rect = text_bfs.get_rect() text_bfs_rect.center = (width - 130, 140) text_ucs = text_font1.render(u'View uniform cost searching', True, (255, 255, 255)) text_ucs_rect = text_ucs.get_rect() text_ucs_rect.center = (width - 130, 180) text_As = text_font1.render(u'View Astar searching ', True, (255, 255, 255)) text_As_rect = text_As.get_rect() text_As_rect.center = (width - 130, 220) text_path = text_font1.render(u'View path ', True, (255, 255, 255)) text_path_rect = text_path.get_rect() text_path_rect.center = (width - 130, 260) text_skip = text_font1.render(u'Skip to Next Level', True, (255, 255, 255)) text_skip_rect = text_skip.get_rect() text_skip_rect.center = (width - 130, 600) image_startmenu = pygame.image.load('images/background/startmenu.png') image_background = pygame.image.load('images/background/background.png') image_path = pygame.image.load("images/wall/path.png").convert_alpha() image_victory = pygame.image.load( "images/background/victory.png").convert_alpha() text1 = pygame.image.load('images/background/startgame.png').convert() text1_rect = text1.get_rect() text1_rect.center = (width / 2, height / 2 + 100) maze_size = 2 Maze = maze.createmaze(maze_size) while solution.solution_maze(Maze, 'DFS') == False: Maze = maze.createmaze(maze_size) wall_location = [] ice_location = [] for i in range(2 * maze_size + 1): for j in range(2 * maze_size + 1): if Maze[i][j] == 0: wall_location.append((i, j)) elif Maze[i][j] == 10: position_people = i * 32, j * 32 elif Maze[i][j] == 1: position_treasure = i * 32, j * 32 elif Maze[i][j] == 4: ice_location.append((i, j)) me = people.People(position_people) walls = [] ices = [] for each in wall_location: position = each[0] * 32, each[1] * 32 wa = wall.Wall(position, 0) walls.append(wa) for each in ice_location: position = each[0] * 32, each[1] * 32 wa = wall.Wall(position, 1) ices.append(wa) treasure = pygame.image.load('images/wall/treasure.png') treasure_rect = treasure.get_rect() treasure_rect.left = position_treasure[0] treasure_rect.top = position_treasure[1] while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if Gamestate == 0: if event.type == MOUSEBUTTONDOWN: if event.button == 1 and text1_rect.collidepoint(event.pos): Gamestate = 11 screen.blit(image_startmenu, (0, 0)) screen.blit(text_startmenu, text_startmenu_rect) screen.blit(text1, text1_rect) if Gamestate == 11: if event.type == MOUSEBUTTONDOWN: if event.button == 1 and text_dfs_rect.collidepoint(event.pos): Gamestate = 12 if event.button == 1 and text_bfs_rect.collidepoint(event.pos): Gamestate = 13 if event.button == 1 and text_As_rect.collidepoint(event.pos): Gamestate = 14 if event.button == 1 and text_ucs_rect.collidepoint(event.pos): Gamestate = 15 if event.button == 1 and text_path_rect.collidepoint( event.pos): Gamestate = 16 if event.button == 1 and text_skip_rect.collidepoint( event.pos): Gamestate = 100 key_pressed = pygame.key.get_pressed() if 1 not in key_pressed: key_state = 1 if key_pressed[K_w] and key_state == 1: me.moveUp() key_state = 0 if key_pressed[K_s] and key_state == 1: me.moveDown() key_state = 0 if key_pressed[K_a] and key_state == 1: me.moveLeft() key_state = 0 if key_pressed[K_d] and key_state == 1: me.moveRight() key_state = 0 location_temp = (int(me.rect.left / 32), int(me.rect.top / 32)) if Maze[location_temp[0]][location_temp[1]] == 0: if key_pressed[K_w]: me.rect.top += me.speed if key_pressed[K_s]: me.rect.top -= me.speed if key_pressed[K_a]: me.rect.left += me.speed if key_pressed[K_d]: me.rect.left -= me.speed elif Maze[location_temp[0]][location_temp[1]] == 1: Gamestate = 100 screen.fill(bg) screen.blit(image_background, (0, 0)) screen.blit(treasure, treasure_rect) for each in walls: screen.blit(each.image1, each.rect) for each in ices: screen.blit(each.image1, each.rect) solution1, open1, close1, path_cost1 = solution.solution_maze( Maze, 'DFS') solution2, open2, close2, path_cost2 = solution.solution_maze( Maze, 'BFS') solution3, open3, close3, path_cost3 = solution.solution_maze( Maze, 'uniform') solution4, open4, close4, path_cost4 = solution.solution_maze( Maze, 'A*') text_type = text_font1.render('openlist closelist pathcost', True, (255, 255, 255)) text_result1 = text_font1.render( 'DFS ' + str(open1).zfill(3) + ' ' + str(close1).zfill(3) + ' ' + str(path_cost1).zfill(3), True, (255, 255, 255)) text_result2 = text_font1.render( 'BFS ' + str(open2).zfill(3) + ' ' + str(close2).zfill(3) + ' ' + str(path_cost2).zfill(3), True, (255, 255, 255)) text_result3 = text_font1.render( 'UCS ' + str(open3).zfill(3) + ' ' + str(close3).zfill(3) + ' ' + str(path_cost3).zfill(3), True, (255, 255, 255)) text_result4 = text_font1.render( 'A*S ' + str(open4).zfill(3) + ' ' + str(close4).zfill(3) + ' ' + str(path_cost4).zfill(3), True, (255, 255, 255)) screen.blit(text_type, (740, 340)) screen.blit(text_result1, (680, 380)) screen.blit(text_result2, (680, 420)) screen.blit(text_result3, (680, 460)) screen.blit(text_result4, (680, 500)) screen.blit(me.people, me.rect) screen.blit(text_dfs, text_dfs_rect) screen.blit(text_bfs, text_bfs_rect) screen.blit(text_As, text_As_rect) screen.blit(text_path, text_path_rect) screen.blit(text_ucs, text_ucs_rect) screen.blit(text_skip, text_skip_rect) if Gamestate == 12: searching_process, a, b, c = solution.solution_maze(Maze, 'DFS') visited = [] for point in searching_process: visited.append([point[0], point[1]]) screen.fill(bg) screen.blit(image_background, (0, 0)) screen.blit(treasure, treasure_rect) for each in walls: screen.blit(each.image1, each.rect) for each in ices: screen.blit(each.image1, each.rect) for path in visited: screen.blit(image_path, (path[0] * 32, path[1] * 32)) me.rect.left = 32 * point[0] me.rect.top = 32 * point[1] screen.blit(me.people, me.rect) pygame.display.flip() pygame.time.wait(200) me.rect.left = 32 * searching_process[0][0] me.rect.top = 32 * searching_process[0][1] Gamestate = 11 if Gamestate == 13: searching_process, a, b, c = solution.solution_maze(Maze, 'BFS') visited = [] for point in searching_process: visited.append([point[0], point[1]]) screen.fill(bg) screen.blit(image_background, (0, 0)) screen.blit(treasure, treasure_rect) for each in walls: screen.blit(each.image1, each.rect) for each in ices: screen.blit(each.image1, each.rect) for path in visited: screen.blit(image_path, (path[0] * 32, path[1] * 32)) me.rect.left = 32 * point[0] me.rect.top = 32 * point[1] screen.blit(me.people, me.rect) pygame.display.flip() pygame.time.wait(200) me.rect.left = 32 * searching_process[0][0] me.rect.top = 32 * searching_process[0][1] Gamestate = 11 if Gamestate == 14: searching_process, a, b, c = solution.solution_maze(Maze, 'A*') visited = [] for point in searching_process: visited.append([point[0], point[1]]) screen.fill(bg) screen.blit(image_background, (0, 0)) screen.blit(treasure, treasure_rect) for each in walls: screen.blit(each.image1, each.rect) for each in ices: screen.blit(each.image1, each.rect) for path in visited: screen.blit(image_path, (path[0] * 32, path[1] * 32)) me.rect.left = 32 * point[0] me.rect.top = 32 * point[1] screen.blit(me.people, me.rect) pygame.display.flip() pygame.time.wait(200) me.rect.left = 32 * searching_process[0][0] me.rect.top = 32 * searching_process[0][1] Gamestate = 11 if Gamestate == 15: searching_process, a, b, c = solution.solution_maze( Maze, 'uniform') visited = [] for point in searching_process: visited.append([point[0], point[1]]) screen.fill(bg) screen.blit(image_background, (0, 0)) screen.blit(treasure, treasure_rect) for each in walls: screen.blit(each.image1, each.rect) for each in ices: screen.blit(each.image1, each.rect) for path in visited: screen.blit(image_path, (path[0] * 32, path[1] * 32)) me.rect.left = 32 * point[0] me.rect.top = 32 * point[1] screen.blit(me.people, me.rect) pygame.display.flip() pygame.time.wait(200) me.rect.left = 32 * searching_process[0][0] me.rect.top = 32 * searching_process[0][1] Gamestate = 11 if Gamestate == 16: searching_process, a, b, c = solution.solution_maze(Maze, 'A*') path = solution.solution_to_path(searching_process) screen.blit(image_background, (0, 0)) for each in ices: screen.blit(each.image1, each.rect) for points in path: screen.blit(image_path, (points[0] * 32, points[1] * 32)) for each in walls: screen.blit(each.image1, each.rect) pygame.display.flip() pygame.time.wait(1000) Gamestate = 11 if Gamestate == 100: screen.blit(image_victory, (0, 0)) screen.blit(text_nextlevel, text_nextlevel_rect) screen.blit(text_congratulation, text_congratulation_rect) pygame.display.flip() if event.type == MOUSEBUTTONDOWN: if event.button == 1 and text_nextlevel_rect.collidepoint( event.pos): Gamestate = 11 maze_size = min(maze_size + 1, 10) Maze = maze.createmaze(maze_size) while solution.solution_maze(Maze, 'DFS') == False: Maze = maze.createmaze(maze_size) wall_location = [] ice_location = [] for i in range(2 * maze_size + 1): for j in range(2 * maze_size + 1): if Maze[i][j] == 0: wall_location.append((i, j)) elif Maze[i][j] == 10: position_people = i * 32, j * 32 elif Maze[i][j] == 1: position_treasure = i * 32, j * 32 elif Maze[i][j] == 4: ice_location.append((i, j)) me = people.People(position_people) walls = [] ices = [] for each in wall_location: position = each[0] * 32, each[1] * 32 wa = wall.Wall(position, 0) walls.append(wa) for each in ice_location: position = each[0] * 32, each[1] * 32 wa = wall.Wall(position, 1) ices.append(wa) treasure = pygame.image.load('images/wall/treasure.png') treasure_rect = treasure.get_rect() treasure_rect.left = position_treasure[0] treasure_rect.top = position_treasure[1] pygame.display.flip() clock.tick(60)
def main(): clock = pygame.time.Clock() # i = 0 开始画面 i = 0 # 字体 text_font = pygame.font.Font("AdobeHeitiStd-Regular.otf", 35) # text1 = pygame.image.load('images\kaishi.png').convert_alpha() text1_rect = text1.get_rect() text1_rect.left, text1_rect.top = width / 2 - 100, height / 2 - 50 # text2 = text_font.render("Game over", True, back) text2_rect = text2.get_rect() text2_rect.left, text2_rect.top = width / 2 - 50, height / 2 - 50 text3 = text_font.render("重生", True, back) text3_rect = text3.get_rect() text3_rect.left, text3_rect.top = width / 2 - 50, height / 2 + 100 text4 = text_font.render("victory", True, back) text4_rect = text4.get_rect() text4_rect.left, text4_rect.top = width / 2 - 50, height / 2 - 50 # 生成小人 position1 = 0 * 66, 4 * 66 position2 = 3 * 66, 9 * 66 position3 = 5 * 66, 0 * 66 position4 = 7 * 66, 0 * 66 position5 = 10 * 66, 0 * 66 position6 = 10 * 66, 9 * 66 position7 = 14 * 66, 8 * 66 position8 = 1 * 66, 0 * 66 position9 = 1 * 66, 9 * 66 position10 = 3 * 66, 9 * 66 position11 = 7 * 66, 9 * 66 position12 = 10 * 66, 0 * 66 position13 = 12 * 66, 9 * 66 position14 = 14 * 66, 4 * 66 position15 = 7 * 66, 0 * 66 position16 = 7 * 66, 9 * 66 position = position1 me = people.People(position) #墙 wall1_positions = [(0,0),(0,1),(0,2),(0,3),(0,5),(0,6),(0,7),(0,8),(0,9),(1,0),\ (1,9),(2,0),(2,1),(2,2),(2,3),(2,4),(2,5),(2,6),\ (2,8),(2,9),(3,0),(4,0),(4,1),(4,3),(4,4),(4,5),(4,6),\ (4,7),(4,8),(4,9),(5,9),(6,0),(6,1),(6,2),(6,3),(6,4),(6,5),\ (6,6),(6,7),(6,9),(7,7),(7,9),(8,0),(8,1),(8,2),(8,4),(8,5),(8,6),\ (8,7),(8,9),(9,0),(9,7),(9,9),(10,1),(10,2),(10,3),(10,4),\ (10,5),(10,7),(11,7),(11,0),(11,9),(12,0),(12,2),(12,3),\ (12,4),(12,5),(12,6),(12,7),(12,8),(12,9),(13,0),(13,9),(14,0),\ (14,1),(14,2),(14,3),(14,4),(14,5),(14,6),(14,7),(14,9)] walls1 = [] for each in wall1_positions: #真实坐标 position = each[0] * 66, each[1] * 66 wa = wall.Wall(position) walls1.append(wa) wall2_positions = [(0,0),(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),(0,7),(0,8),(0,9),\ (1,7),\ (2,0),(2,1),(2,2),(2,3),(2,4),(2,5),(2,7),(2,9),\ (3,0),(3,1),(3,2),(3,4),(3,5),(3,7),\ (4,0),(4,7),(4,9),\ (5,0),(5,2),(5,3),(5,4),(5,5),(5,7),(5,9),\ (6,0),(6,5),(6,7),(6,8),(6,9),\ (7,0),(7,2),(7,3),(7,5),\ (8,0),(8,1),(8,2),(8,3),(8,5),(8,6),(8,7),(8,8),(8,9),\ (9,0),(9,1),(9,2),(9,3),(9,7),(9,8),(9,9),\ (10,5),(10,8),(10,9),\ (11,0),(11,2),(11,3),(11,5),(11,6),(11,9),\ (12,0),(12,2),(12,3),(12,5),(12,6),(12,7),\ (13,0),(13,5),(13,6),(13,7),(13,8),(13,9),\ (14,0),(14,1),(14,2),(14,3),(14,5),(14,6),(14,7),(14,8),(14,9),] walls2 = [] for each in wall2_positions: #真实坐标 position = each[0] * 66, each[1] * 66 wa = wall.Wall(position) walls2.append(wa) wall3_positions = [(0,0),(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),(0,7),(0,8),(0,9),\ (1,0),(1,9),\ (2,0),(2,9),\ (3,0),(3,9),\ (4,0),(4,9),\ (5,0),(5,9),\ (6,0),(6,9),\ (8,0),(8,9),\ (9,0),(9,9),\ (10,0),(10,9),\ (11,0),(11,9),\ (12,0),(12,9),\ (13,0),(13,9),\ (14,0),(14,1),(14,2),(14,3),(14,4),(14,5),(14,6),(14,7),(14,8),(14,9),] walls3 = [] for each in wall3_positions: #真实坐标 position = each[0] * 66, each[1] * 66 wa = wall.Wall(position) walls3.append(wa) # 生成敌人 enemys1 = [] position = 3 * 66, 1 * 66 direction = 1 up = 1 * 66 down = 8 * 66 left = 0 right = 0 en = enemy.Enemy((1 * 66, 2 * 66), 1 * 66, 8 * 66, 0, 0, 1) enemys1.append(en) en = enemy.Enemy((3 * 66, 4 * 66), 1 * 66, 8 * 66, 0, 0, 1) en.enemy = en.image2 enemys1.append(en) en = enemy.Enemy((5 * 66, 6 * 66), 1 * 66, 8 * 66, 0, 0, 2) en.enemy = en.image2 enemys1.append(en) en = enemy.Enemy((7 * 66, 3 * 66), 1 * 66, 6 * 66, 0, 0, 2) en.enemy = en.image3 enemys1.append(en) en = enemy.Enemy((9 * 66, 3 * 66), 1 * 66, 6 * 66, 0, 0, 1) en.enemy = en.image3 enemys1.append(en) enemys2 = [] en = enemy.Enemy((4 * 66, 6 * 66), 0, 0, 1 * 66, 7 * 66, 3) en.enemy = en.image2 enemys2.append(en) en = enemy.Enemy((4 * 66, 3 * 66), 1 * 66, 5 * 66, 0, 0, 1) en.enemy = en.image1 enemys2.append(en) en = enemy.Enemy((10 * 66, 4 * 66), 0, 0, 6 * 66, 13 * 66, 4) en.enemy = en.image1 enemys2.append(en) en = enemy.Enemy((10 * 66, 1 * 66), 0, 0, 10 * 66, 13 * 66, 3) en.enemy = en.image1 enemys2.append(en) en = enemy.Enemy((3 * 66, 8 * 66), 0, 0, 1 * 66, 5 * 66, 3) en.enemy = en.image3 enemys2.append(en) enemys3 = [] en = enemy.Enemy((1 * 66, 1 * 66), 0, 0, 1 * 66, 13 * 66, 3) en.enemy = en.image2 enemys3.append(en) en = enemy.Enemy((2 * 66, 2 * 66), 0, 0, 1 * 66, 13 * 66, 4) en.enemy = en.image3 en.speed = 2 enemys3.append(en) en = enemy.Enemy((3 * 66, 3 * 66), 0, 0, 1 * 66, 13 * 66, 3) en.enemy = en.image1 en.speed = 4 enemys3.append(en) en = enemy.Enemy((1 * 66, 4 * 66), 0, 0, 1 * 66, 13 * 66, 4) en.enemy = en.image3 en.speed = 6 enemys3.append(en) en = enemy.Enemy((6 * 66, 5 * 66), 0, 0, 1 * 66, 13 * 66, 4) en.enemy = en.image3 en.speed = 8 enemys3.append(en) en = enemy.Enemy((13 * 66, 6 * 66), 0, 0, 1 * 66, 13 * 66, 3) en.enemy = en.image2 en.speed = 6 enemys3.append(en) en = enemy.Enemy((9 * 66, 7 * 66), 0, 0, 1 * 66, 13 * 66, 4) en.enemy = en.image3 en.speed = 4 enemys3.append(en) en = enemy.Enemy((7 * 66, 8 * 66), 0, 0, 1 * 66, 13 * 66, 3) en.enemy = en.image1 en.speed = 2 enemys3.append(en) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() #场景1 if i == 11: #人的移动 限制 key_pressed = pygame.key.get_pressed() if key_pressed[K_w]: me.moveUp() if key_pressed[K_s]: me.moveDown() if key_pressed[K_a]: me.moveLeft() if key_pressed[K_d]: me.moveRight() if pygame.sprite.spritecollide(me, walls1, False, pygame.sprite.collide_mask): if key_pressed[K_w]: me.rect.top += me.speed if key_pressed[K_s]: me.rect.top -= me.speed if key_pressed[K_a]: me.rect.left += me.speed if key_pressed[K_d]: me.rect.left -= me.speed # 敌人的移动 此处为错误语法 direction会重复赋值 #en.move_up(up,down,direction) for each in enemys1: each.move() # 人和鬼的碰撞检测 if pygame.sprite.spritecollide(me, enemys1, False, pygame.sprite.collide_mask): i = 1 # 人的位置的转换 if me.rect.left > 3 * 66 and me.rect.left < 4 * 66 and me.rect.top > 10 * 66: # me.position = position13 对象里已不再引用初始参数position me.rect.left, me.rect.top = position13 i = 12 if me.rect.left > 5 * 66 and me.rect.left < 6 * 66 and me.rect.top < -1 * 66: me.rect.left, me.rect.top = position11 i = 12 if me.rect.left > 7 * 66 and me.rect.left < 8 * 66 and me.rect.top < -1 * 66: me.rect.left, me.rect.top = position8 i = 12 if me.rect.left > 10 * 66 and me.rect.left < 11 * 66 and me.rect.top < -1 * 66: me.rect.left, me.rect.top = position12 i = 12 if me.rect.left > 10 * 66 and me.rect.left < 11 * 66 and me.rect.top > 10 * 66: me.rect.left, me.rect.top = position14 i = 12 if me.rect.left > 15 * 66 and me.rect.top < 9 * 66 and me.rect.top > 8 * 66: me.rect.left, me.rect.top = position10 i = 12 screen.fill(bg) for each in walls1: screen.blit(each.image2, each.rect) screen.blit(me.people, me.rect) for each in enemys1: screen.blit(each.enemy, each.rect) #场景2 if i == 12: #人的移动 限制 key_pressed = pygame.key.get_pressed() if key_pressed[K_w]: me.moveUp() if key_pressed[K_s]: me.moveDown() if key_pressed[K_a]: me.moveLeft() if key_pressed[K_d]: me.moveRight() if pygame.sprite.spritecollide(me, walls2, False, pygame.sprite.collide_mask): if key_pressed[K_w]: me.rect.top += me.speed if key_pressed[K_s]: me.rect.top -= me.speed if key_pressed[K_a]: me.rect.left += me.speed if key_pressed[K_d]: me.rect.left -= me.speed for each in enemys2: each.move() # 人和鬼的碰撞检测 if pygame.sprite.spritecollide(me, enemys2, False, pygame.sprite.collide_mask): i = 1 # people 的转换 if me.rect.left > 1 * 66 and me.rect.left < 2 * 66 and me.rect.top < -1 * 66: me.rect.left, me.rect.top = position4 i = 11 if me.rect.left > 3 * 66 and me.rect.left < 4 * 66 and me.rect.top > 10 * 66: me.rect.left, me.rect.top = position7 i = 11 if me.rect.left > 7 * 66 and me.rect.left < 8 * 66 and me.rect.top > 10 * 66: me.rect.left, me.rect.top = position3 i = 11 if me.rect.left > 10 * 66 and me.rect.left < 11 * 66 and me.rect.top < -1 * 66: me.rect.left, me.rect.top = position5 i = 11 if me.rect.left > 12 * 66 and me.rect.left < 13 * 66 and me.rect.top > 10 * 66: me.rect.left, me.rect.top = position2 i = 11 if me.rect.left > 15 * 66 and me.rect.top < 5 * 66 and me.rect.top > 4 * 66: me.rect.left, me.rect.top = position6 i = 11 if me.rect.left > 1 * 66 and me.rect.left < 2 * 66 and me.rect.top > 10 * 66: me.rect.left, me.rect.top = position15 i = 13 screen.fill(bg) for each in walls2: screen.blit(each.image2, each.rect) screen.blit(me.people, me.rect) for each in enemys2: screen.blit(each.enemy, each.rect) if i == 13: #人的移动 限制 key_pressed = pygame.key.get_pressed() if key_pressed[K_w]: me.moveUp() if key_pressed[K_s]: me.moveDown() if key_pressed[K_a]: me.moveLeft() if key_pressed[K_d]: me.moveRight() if pygame.sprite.spritecollide(me, walls3, False, pygame.sprite.collide_mask): if key_pressed[K_w]: me.rect.top += me.speed if key_pressed[K_s]: me.rect.top -= me.speed if key_pressed[K_a]: me.rect.left += me.speed if key_pressed[K_d]: me.rect.left -= me.speed # 敌人的移动 此处为错误语法 direction会重复赋值 #en.move_up(up,down,direction) for each in enemys3: each.move() # 人和鬼的碰撞检测 if pygame.sprite.spritecollide(me, enemys3, False, pygame.sprite.collide_mask): i = 1 if me.rect.left > 7 * 66 and me.rect.left < 8 * 66 and me.rect.top < -1 * 66: me.rect.left, me.rect.top = position9 i = 12 if me.rect.left > 7 * 66 and me.rect.left < 8 * 66 and me.rect.top > 9 * 66: i = 2 screen.fill(bg) for each in walls3: screen.blit(each.image2, each.rect) screen.blit(me.people, me.rect) for each in enemys3: screen.blit(each.enemy, each.rect) if i == 0: if event.type == MOUSEBUTTONDOWN: if event.button == 1 and text1_rect.collidepoint(event.pos): i = 11 screen.fill(bg) screen.blit(text1, text1_rect) if i == 1: if event.type == MOUSEBUTTONDOWN: if event.button == 1 and text3_rect.collidepoint(event.pos): i = 11 me.rect.left, me.rect.top = position1 screen.fill(bg) screen.blit(text2, text2_rect) screen.blit(text3, text3_rect) if i == 2: screen.fill(bg) screen.blit(text4, text4_rect) pygame.display.flip() clock.tick(60)