def create_new(self, maps, clock, font): flag = True while flag: mouse = User_Input.mouse() self.window.fill((0, 0, 0)) back_x = self.W * 0.6 back_y = self.H * 0.8 num_x = self.W * 0.3 num_y = self.H * 0.45 if Menu_And_Options.text_box(mouse, back_x, back_y, 'Apply', font): flag = False while mouse[2] == 1: mouse = User_Input.mouse() clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() self.rows = number_of_rows(self.window, self.H, self.W, mouse, self.rows) self.columns = round((self.rows + 1) * 16.0 / 9.0 - 1) self.row_width = (self.H - self.tools_row_width) // (self.rows) self.column_width = (self.W - self.tools_col_width) // (self.columns) self.rotate = [[0 for x in range(self.columns)] for y in range(self.rows)] self.type = [[0 for x in range(self.columns)] for y in range(self.rows)] Menu_And_Options.text(font, str(self.rows), num_x, num_y) Draw.update_window() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() clock.tick(60) self.type = [[0 for x in range(self.columns)] for y in range(self.rows)] self.line = Save_and_Load.search(maps) Save_and_Load.read_data(self.line + 2)
def start_map_selection(clock): global window, W, H flag = True map_choice = 0 Map = 'MAP1' back = 0 font = pygame.font.SysFont(None, W // 18) mousei = User_Input.Mouse() while flag: mouse = mousei.mouser() window.fill((0, 0, 0)) name = ['a' for x in range(5)] for i in range(5): line = Save_and_Load.search('MAP' + str(i + 1)) name[i] = Save_and_Load.read_name(line + 1) map1_x = W * 0.1 map1_y = H * 0.35 menu_box(W * 0.11, H * (0.35 + map_choice * 0.1) - H * 0.014, name[map_choice]) clock.tick(60) if text_box(mouse, map1_x, map1_y, name[0], font): map_choice = 0 Map = 'MAP1' if text_box(mouse, map1_x, map1_y + 0.1 * H, name[1], font): map_choice = 1 Map = 'MAP2' if text_box(mouse, map1_x, map1_y + 0.2 * H, name[2], font): map_choice = 2 Map = 'MAP3' if text_box(mouse, map1_x, map1_y + 0.3 * H, name[3], font): map_choice = 3 Map = 'MAP4' if text_box(mouse, map1_x, map1_y + 0.4 * H, name[4], font): map_choice = 4 Map = 'MAP5' if text_box(mouse, map1_x + 0.6 * W, map1_y + 0.4 * H, 'Go', font): flag = False if text_box(mouse, map1_x + 0.7 * W, map1_y + 0.4 * H, 'Back', font): back = 1 flag = False Draw.update_window() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() return map_choice, back, Map
def statistics(): while True: city, month, day = ui.get_filters() load_data(city, month, day) df = load_data(city, month, day) time_stats(df, month, day) station_stats(df) trip_duration_stats(df) user_stats(df, city) check = 'y' start = 0 end = 10 check = input( '\nWould you like to have a look on each trip details? \nType y or n \ny:yes\nn:no\n' ) while ((check != 'y') and (check != 'n')): check = input('\nPlease enter y or n: ') if check == 'y': print(df.iloc[start:end]) start += 10 end += 10 while (check == 'y'): check = input( '\nWould you like look next 10 records? \nType y or n \ny:yes\nn:no\n' ) while ((check != 'y') and (check != 'n')): check = input('\nPlease enter y or n: ') if check == 'y': print(df.iloc[start:end]) start += 10 end += 10 restart = input('\nWould you like to restart? Enter y or n.\n') restart = restart.lower() restart = restart[:1] while ((restart != 'y') and (restart != 'n')): restart = input('\nPlease enter y or n: ') if restart == 'n': break elif restart == 'y': continue
def menu(clock): global window, W, H, menu_opt menu_flag = True resolution_set = True menu_opt = Options() pygame.font.init() while menu_flag: if resolution_set: W, H = menu_opt.resolution() # screen resolution window = pygame.display.set_mode((W, H)) # sets the resolution Map_Makeing.load_im() font = pygame.font.SysFont(None, W // 18) Map = Map_Makeing.MapBuild(window, W, H, 5) start_x = W * 0.6 start_y = H * 0.35 mapmake_x = W * 0.6 mapmake_y = H * 0.5 options_x = W * 0.6 options_y = H * 0.65 quit_x = W * 0.6 quit_y = H * 0.8 resolution_set = False window.fill((0, 0, 0)) line = Save_and_Load.search("BACKGROUND:") types, rotate = Save_and_Load.read_data(line + 1) types = ast.literal_eval(types) rotate = ast.literal_eval(rotate) Map.scale_image_menu() Map_Makeing.draw_map(types, rotate, window, 5, 10, H // 5, W // 10, 0) mouse = User_Input.mouse() if text_box(mouse, start_x, start_y, 'Start', font): menu_flag = False if text_box(mouse, mapmake_x, mapmake_y, 'Create Map', font): while mouse[2] == 1: mouse = User_Input.mouse() clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() Map_Makeing.menu(clock, font, window, W, H) if text_box(mouse, options_x, options_y, 'Options', font): menu_opt.options(clock, font, window) resolution_set = True if text_box(mouse, quit_x, quit_y, 'Quit', font): pygame.quit() #text(font, 'Start', start_x, start_y) #text(font, 'Create Map', mapmake_x, mapmake_y) #text(font, 'Options', options_x, options_y) #text(font, 'Quit', quit_x, quit_y) Draw.update_window() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() clock.tick(60)
def options(self, clock, font, window): flag = True while flag: mouse = User_Input.mouse() window.fill((0, 0, 0)) resolution_x = W * 0.1 resolution_y = H * 0.3 res_480_x = W * 0.4 res_480_y = H * 0.3 res_720_x = W * 0.55 res_720_y = H * 0.3 res_1080_x = W * 0.7 res_1080_y = H * 0.3 sound_x = W * 0.1 sound_y = H * 0.45 back_x = W * 0.1 back_y = H * 0.6 if text_box(mouse, back_x, back_y, 'Back and Apply', font): flag = False if text_box(mouse, res_480_x, res_480_y, '480', font): self.height = 480 self.width = 848 if text_box(mouse, res_720_x, res_720_y, '720', font): self.height = 720 self.width = 1280 if text_box(mouse, res_1080_x, res_1080_y, '1080', font): self.height = 1080 self.width = 1920 text(font, 'Resolution', resolution_x, resolution_y) text(font, 'Sound', sound_x, sound_y) if self.height == 480: menu_box(res_480_x - W * 0.01, res_480_y - H * 0.014, '480') elif self.height == 720: menu_box(res_720_x - W * 0.01, res_720_y - H * 0.014, '720') elif self.height == 1080: menu_box(res_1080_x - W * 0.01, res_1080_y - H * 0.014, '1080') pygame.draw.rect(window, (255, 255, 255), (W * 0.4, H * 0.48, W * 0.4, H * 0.01)) if W * 0.4 <= mouse[0] <= W * 0.4 + W * 0.4 and H * 0.45 <= mouse[ 1] <= H * 0.45 + H * 0.07: if mouse[2] == 1: self.volume = int((mouse[0] / W - 0.4) * 100 / 0.4) pygame.draw.rect(window, (255, 127, 10), (W * 0.4 * self.volume // 100 + W * 0.4, H * 0.45, W * 0.01, H * 0.07)) Draw.update_window() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() clock.tick(60)
def create_map(self, clock, font, W, H): image = None flag = True while flag: mouse = User_Input.mouse() self.window.fill((0, 0, 0)) pos = detect_box(mouse, self.row_width, self.column_width, self.rows, self.columns, self.tools_row_width, self.tools_col_width, self.H, self.W) Menu_And_Options.text( font, "Exit", self.column_width * 0.01 + self.column_width * self.columns, self.tools_row_width * 0.4 + self.tools_row_width * 5) Menu_And_Options.text( font, "Save", self.column_width * 0.01 + self.column_width * self.columns, self.tools_row_width * 0.4 + self.tools_row_width * 4) if mouse[2] == 1: if pos[1] == 0: if pos[0] == 9: self.rotation -= 90 if pos[0] == 8: self.rotation += 90 while mouse[2] == 1: clock.tick(60) mouse = User_Input.mouse() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() if pos[0] >= self.columns and pos[0] >= 10: self.choice = pos[1] + 1 if self.choice == 6: flag = False if self.choice == 5: Save_and_Load.write_data(self.line, str(self.type), str(self.rotate)) elif pos[1] == 0: pass else: self.type[pos[1] - 1][pos[0]] = self.choice self.rotate[pos[1] - 1][pos[0]] = self.rotation if self.choice == 1: if self.rotation % 180 == 0: image = turn_1_tool else: image = turn_1_tool_r elif self.choice == 2: if self.rotation % 180 == 0: image = road_1_tool else: image = road_1_tool_r elif self.choice == 3: if self.rotation % 180 == 0: image = grass_1_tool else: image = grass_1_tool_r if image: image_rot = pygame.transform.rotate(image, self.rotation) self.window.blit(image_rot, (0, 0)) if self.type: draw_map(self.type, self.rotate, self.window, self.rows, self.columns, self.row_width, self.column_width, self.tools_row_width) self.window.blit( grass_1_tool, (self.column_width * self.columns, self.tools_row_width * 2)) self.window.blit( road_1_tool, (self.column_width * self.columns, self.tools_row_width * 1)) self.window.blit( turn_1_tool, (self.column_width * self.columns, self.tools_row_width * 0)) self.window.blit(arrow_right_im, (self.tools_col_width * 9, self.row_width * 0)) self.window.blit(arrow_left_im, (self.tools_col_width * 8, self.row_width * 0)) draw_grid(self.W, self.H, self.rows, self.columns, self.row_width, self.column_width, self.window, self.tools_row_width, self.tools_col_width) pygame.draw.line(self.window, (255, 255, 255), (self.column_width * self.columns, 0), (self.column_width * self.columns, H), 5) Draw.update_window() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() clock.tick(60)
def menu(clock, font, window, W, H): flag = True pygame.display.set_mode((W, H)) # sets the resolution map_build = MapBuild(window, W, H, 5) name = ['a' for x in range(5)] Map = 'MAP1' save_num = 0 while flag: mouse = User_Input.mouse() window.fill((0, 0, 0)) for i in range(5): line = Save_and_Load.search('MAP' + str(i + 1)) name[i] = Save_and_Load.read_name(line + 1) new_x = W * 0.6 new_y = H * 0.35 edit_x = W * 0.6 edit_y = H * 0.5 back_x = W * 0.6 back_y = H * 0.8 map1_x = W * 0.1 map1_y = H * 0.35 Menu_And_Options.menu_box(W * 0.11, H * (0.35 + save_num * 0.1) - H * 0.014, name[save_num]) if Menu_And_Options.text_box(mouse, map1_x, map1_y, name[0], font): Map = 'MAP1' save_num = 0 if Menu_And_Options.text_box(mouse, map1_x, map1_y + 0.1 * H, name[1], font): Map = 'MAP2' save_num = 1 if Menu_And_Options.text_box(mouse, map1_x, map1_y + 0.2 * H, name[2], font): Map = 'MAP3' save_num = 2 if Menu_And_Options.text_box(mouse, map1_x, map1_y + 0.3 * H, name[3], font): Map = 'MAP4' save_num = 3 if Menu_And_Options.text_box(mouse, map1_x, map1_y + 0.4 * H, name[4], font): Map = 'MAP5' save_num = 4 if Menu_And_Options.text_box(mouse, new_x, new_y, 'Create New Map', font): map_build.create_new(Map, clock, font) map_build.scale_image() map_build.create_map(clock, font, W, H) if Menu_And_Options.text_box(mouse, edit_x, edit_y, 'Edit Map', font): map_build.edit(Map) map_build.scale_image() while True: #just a delay for mouse click mouse = User_Input.mouse() clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() if mouse[2] == 0: break map_build.create_map(clock, font, W, H) if Menu_And_Options.text_box(mouse, back_x, back_y, 'Back', font): flag = False while mouse[2] == 1: mouse = User_Input.mouse() clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() Draw.update_window() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() clock.tick(60)
def main(): clock = pygame.time.Clock() # creates a instance that keeps track of time pygame.font.init() # enables text in pygame game = True # keeps the gameloop going menu_flag = True select_flag = False calc_path_flag = False game_running = False Tower = Towers.Tower() aim = Aim.TowerRotation() collison = Colission.Collision() game_speed = 30 path = Map_And_Path.Path() mouse_obj = User_Input.Mouse() while game: if menu_flag: Menu_And_Options.menu(clock) select_flag = True menu_flag = False # chose map if select_flag: map_choice, back, map_name = Menu_And_Options.start_map_selection( clock) select_flag = False if back == 1: menu_flag = True else: calc_path_flag = True W, H = Menu_And_Options.resolution() window = pygame.display.set_mode((W, H)) # sets the resolution # window.fill((0, 0, 0)) # calculate path if calc_path_flag: type_, rotate, rows, columns, row_width, column_width, menu_height, menu_width = path.setup( map_name) bloon = Bloons.Bloons(path) calc_path_flag = False Map = Map_Makeing.MapBuild(window, W, H, rows) game_running = True Map_Makeing.load_im() Map.edit(map_name) Map.scale_image() Draw.load_im() Draw.scale_image_menu(W, H) Draw.scale_image(row_width, column_width) Tower.update(rows, columns, row_width, column_width) aim.update(rows, columns) bloon_type = [] bloon_time = [] score = 0 money = 150 life = 3 level_score = 20 levels = 0 level_hold = True level = 0 levelq = 0 font = pygame.font.SysFont(None, int(W / 25)) tower_selected = 0 if game_running: Draw.draw_background() levelq = (score + levelq * level_score) // level_score if levelq > levels: if level_score < 260: level_score += int(level_score * 0.9) else: level_score += 200 levels = levelq level_hold = False #print('levelscore', level_score) if len(bloon_type) == 0: level_hold = True level = levelq life = 3 # if level > current_level: if life <= 0: game_running = False menu_flag = True mouse = mouse_obj.mouser() mouse_x, mouse_y = Map_Makeing.detect_box(mouse, row_width, column_width, rows, columns, menu_height, menu_width, H, W) Map_Makeing.draw_map(type_, rotate, window, rows, columns, row_width, column_width, menu_height) # game life = bloon.update(bloon_type, bloon_time, life, level, level_hold) pos_x, pos_y, bloon_type, bloon_time = bloon.bloon_return() bloon_type, bloon_time, pos_x, pos_y = remove_bloon( bloon_type, bloon_time, pos_x, pos_y, -1) if mouse[2] == 1: money, tower_selected = Tower.tower_selection( mouse_x, mouse_y, type_, money) Draw.towers_menu(column_width, columns, menu_height, tower_selected) aim.aim(row_width, column_width, pos_x, pos_y, collison) Draw.draw_towers(rows, row_width, column_width, menu_height) collison.update_position(column_width, menu_height, menu_width, W, H, window) bloon_type, bloon_time, pos_x, pos_y, score, money = collison.check_collision( bloon_type, bloon_time, pos_x, pos_y, column_width, score, money) bloon_type, bloon_time, pos_x, pos_y = remove_bloon( bloon_type, bloon_time, pos_x, pos_y, -2) #print(clock.get_fps()) Draw.draw_bloons(bloon_type, pos_x, pos_y, menu_height, column_width) #for t in range(len(pos_x)): #pygame.draw.rect(window, (255, 255, 255), (pos_x[t]-W*0.025, pos_y[t]+menu_height-H*0.025, W * 0.05, H * 0.05)) Draw.text(font, 'Money ' + str(money), W * 0.7, H * 0.09) Draw.text(font, 'Score ' + str(score), W * 0.7, H * 0.02) Draw.text(font, 'Level ' + str(level), W * 0.5, H * 0.02) Draw.text(font, 'Life ' + str(life), W * 0.5, H * 0.09) Draw.text(font, '50', W * 0.92, H * 0.15) Draw.text(font, '450', W * 0.92, H * 0.3) Draw.text(font, '1250', W * 0.92, H * 0.5) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() Draw.update_window() clock.tick(game_speed) # sets the fps