def main(): pygame.mixer.pre_init(44100, -16, 2, 4096) pygame.init() screen = pygame.display.set_mode(windowSize) max_frame_rate = 60 dashboard = Dashboard("./img/font.png", 8, screen) sound = Sound() level = Level(screen, sound, dashboard) menu = Menu(screen, dashboard, level, sound) while not menu.start: menu.update() mario = Mario(0, 0, level, screen, dashboard, sound) clock = pygame.time.Clock() while not mario.restart: pygame.display.set_caption("Super Mario running with {:d} FPS".format(int(clock.get_fps()))) if mario.pause: mario.pauseObj.update() else: level.drawLevel(mario.camera) dashboard.update() mario.update() pygame.display.update() clock.tick(max_frame_rate) return 'restart'
def main(): # instantiate menu class mainMenu = Menu("Choice: ", [ "Input Project Details", "View Projects", "Schedule Projects", "Get A Project", "Exit" ]) # program loop while True: Common.cls() print("--- COPY TYPING SCHEDULER ---") choice, errorMsg = mainMenu.show() if errorMsg: print(errorMsg) Common.pause() continue # main menu if choice == 1: # Input Project Details inputProjectDetails() elif choice == 2: # View Projects viewProjects() elif choice == 3: # Schedule Project scheduleProjects() elif choice == 4: # Get A Project getProject() elif choice == 5: # Exit exit()
def main(): pygame.mixer.pre_init(44100, -16, 2, 4096) pygame.init() screen = pygame.display.set_mode((640, 480)) max_frame_rate = 60 dashboard = Dashboard("./img/font.png", 8, screen) sound = Sound() level = Level(screen, sound, dashboard) menu = Menu(screen, dashboard, level, sound) while not menu.start: menu.update() mario = Mario(0, 0, level, screen, dashboard, sound) clock = pygame.time.Clock() while not mario.restart: pygame.display.set_caption( str( round(float("{:.2f} FPS".format(clock.get_fps()).split(" ") [0]))) + " FPS") level.drawLevel(mario.camera) dashboard.update() mario.update() pygame.display.update() clock.tick(max_frame_rate) main()
def viewProjects(): # view project sub menu viewProjectsMenu = Menu( "Choice: ", ["One Project", "Completed", "All Projects", "Back"]) while True: Common.cls() print("--- VIEW PROJECTS ---") choice, errorMsg = viewProjectsMenu.show() if errorMsg: print(errorMsg) Common.pause() continue if choice == 1: # One project viewProjectsOneProject() elif choice == 2: viewProjectsCompletedProjects() elif choice == 3: viewProjectsAllProjects() elif choice == 4: break
def __init__(this): this.file_dealer = FileDealer() this.menu = Menu(this.file_dealer.load_menu()) this.orders = [] this.load_orders() this.types = this.file_dealer.load_types() this.deliveries = {} this.load_foodora() this.load_uber()
def scheduleProjects(): # schedule projects sub menu scheduleProjectsMenu = Menu( "Choice: ", ["Create Schedule", "View Updated Schedule", "Back"]) while True: Common.cls() print("---SCHEDULE PROJECTS ---") choice, errorMsg = scheduleProjectsMenu.show() if errorMsg: print(errorMsg) Common.pause() continue if choice == 1: scheduleProjectsCreateSchedule() elif choice == 2: scheduleProjectsViewSchedule() elif choice == 3: break
def init_game(self, y_position=0, coins=0, points=0, time=0, clock=0): if not self.headless: pygame.mixer.pre_init(44100, -16, 2, 4096) pygame.init() self.screen = pygame.display.set_mode((640, 480)) self.dashboard = Dashboard("./img/font.png", 8, self.screen, coins=0, points=0, time=0) self.sound = Sound() self.level = Level(self.screen, self.sound, self.dashboard, self.levelname) self.menu = Menu(self.screen, self.dashboard, self.level, self.sound) self.menu.update() self.mario = Mario(0, y_position / 32, self.level, self.screen, self.dashboard, self.sound) if self.experiment == 'FD': self.mario2 = Mario(0, 2, self.level, self.screen, self.dashboard, self.sound) self.clock = pygame.time.Clock() self.menu.dashboard.state = "play" self.menu.dashboard.time = 0 self.menu.start = True pygame.display.update() else: self.level = LevelHeadless(self.levelname) if self.experiment == 'FD': self.mario2 = MarioHeadless(0, 2, self.level) self.mario = MarioHeadless(0, 0, self.level) self.clock = clock
"pepperoni": 2.5 } }, "drink": { "Coke": 2, "Diet Coke": 3, "Coke Zero": 4, "Pepsi": 2, "Diet Pepsi": 1, "Dr. Pepper": 3, "Water": 4, "Juice": 2 } } menu = Menu(data) def test_new_foodora(): new_order = Order(sample_order) foodora = Foodora(new_order) assert foodora.order_details == new_order # def test_toCSV(): # new_order = Order(sample_order, menu) # foodora = Foodora(new_order) # result = foodora.toCSV() # expected = '1-1-L-pepperoni-mushrooms-1-olives-4-tomatoes-1,1-Pepsi-2,100 Street,26.5,1' # print(result) # assert result == expected
mc.read() print_msg('Résultat : {}'.format(len(mc.mails)) + ' mail(s).') def clean(): print('Nettoyer mails..') mc.delete() def connect_server(): global mc login = input('login : '******'password : '******'tests..') if __name__ == '__main__': print_msg('Ma Boite Mail') connect_server() menu = Menu([ Option('Boite Mail : Lire!', read), Option('Boite Mail : Nettoyer!', clean) # , Option('Tests', test) ]) while not menu.want_exit: menu.show()
return "How many players will be in this game?" def get_game_intro_dialog(game): dialog = "You have started a new game!\r\n" dialog += "PLAYERS:\r\n" #for player in game.players: # dialog+= player.get_name(), '\r\n' dialog += '\r\n A player has been randomly chosen to be the first player!\r\n' dialog += 'A player, start your turn...' return dialog #init console and menus console = ConsoleMenu() main_menu = Menu() player_count_menu = Menu() #menu functions def kill_script(): sys.exit("kill_script called... game over.") def show_player_count_menu(): console.prompt_user(get_player_count_prompt(), player_count_menu) def set_player_names(): player_names = [] player_count = int(player_count_menu.list[int(console.last_command) - 1])
break else: print('Ошибка\nВведите да или нет!') check = input('Вы уверены?: ') else: print('Нет студентов') functions = StudentReg() menu = Menu( '', [ SimpleMenuItem('Список студентом', functions.list_student), SimpleMenuItem('Добавить студента', add_student) ], ) Submenu = menu.AddSubmenu('Редактировать студента', [ SimpleMenuItem('Изменить фамилию', change_family_name), SimpleMenuItem('Изменить имя', change_name), SimpleMenuItem('Изменить отчество', change_patronymic), SimpleMenuItem('Изменить группу', change_group) ]) Submenu.AddSubmenu('Изменить оценки', [ SimpleMenuItem('Добавить оценку', add_value), SimpleMenuItem('Изменить оценку', change_value), SimpleMenuItem('Удалить оценку', del_value)
3000, 2048)) MEMORY.append( Memory("Ballistix DDR 3000 RAM", "1x4GB Kit - Performance RAM", 600, 1, 3000, 4096)) MEMORY.append( Memory("Ballistix DDR 3000 RAM", "2x4GB Kit - Performance RAM", 1500, 2, 3000, 8192)) MEMORY.append( Memory("Ballistix DDR 3000 RAM", "2x8GB Kit - Performance RAM", 3500, 2, 3000, 16384)) # Menus List MENUS.append( Menu( "Main Menu", "Welcome to Blackhat.NULL! Here's your opportunity to get a piece of the black market " "profits as a security consultant. Please see the options below and let the games begin!", [[1, "Log-in to Console", "login"], [2, "Settings", "settings"], [3, "Exit", "exit"]])) MENUS.append( Menu("Settings", "Customize your game settings below", [[1, "Enable Debug", "debug"], [2, "Show Help", "help"], [3, "Back", "back"]])) MENUS.append( Menu( "Play", "Welcome to your terminal. Select from the options below to get started", [[1, "Jobs Board", "jobs"], [2, "Banking", "bank"], [ 3, "Shop", "shop" ], [4, "Terminal", "terminal"], [5, "Logout", "logout"]])) # Network List
class MarioGym(gym.Env): def __init__(self, headless=True, level_name='Level-basic-one-goomba.json', no_coins=5, step_size=5, partial_observation=False, distance_reward=False, experiment='SE'): self.action_space = spaces.Discrete(6) self.observation_space = spaces.Box(low=-10000000, high=100000000, dtype=np.float, shape=(40, 80, 4)) self.levelname = level_name self.headless = headless self.score = 0 self.step_size = step_size self.max_frame_rate = 60 self.steps = 0 self.observation = None self.experiment = experiment self.level = None self.mario = None self.mario2 = None self.screen = None self.dashboard = None self.sound = None self.menu = None self.partial_observation = partial_observation self.no_coins = no_coins self.coins_start = self.no_coins self.distance_reward = distance_reward self.init_game() self.reset(levelname=self.levelname) self.coin_name = 'Coin' if not self.headless else 'CoinHeadless' def reset(self, levelname=None): if not levelname: self.no_coins = 5 self.levelname = 'Level-{}-coins.json'.format(self.no_coins) else: self.levelname = levelname self.init_game() self.steps = 0 self.observation = self.level_to_numpy() self.max_dist = 0 return self.observation def reset_clean(self, y_pos): self.count_entities() self.coins_taken = self.coins_start - self.no_coins self.coins_end = self.no_coins self.no_coins = min(5, self.no_coins * 2) self.coins_start = self.no_coins self.levelname = 'Level-{}-coins.json'.format(self.no_coins) self.init_game(y_position=y_pos, coins=self.coins_end, clock=self.clock) self.observation = self.level_to_numpy() return self.observation def step( self, action_num, ): self.steps += 1 action = MOVES[action_num] # action = 'doNothing' num_goombas = len([ x for x in self.level.entityList if ((x.__class__.__name__ == 'Goomba' or x.__class__.__name__ == 'GoombaHeadless') and x.alive) ]) coins = len([ x for x in self.level.entityList if ((x.__class__.__name__ == self.coin_name)) ]) old_x_pos = self.mario.rect.x / (10 * MAP_MULTIPLIER) reward = self.do_game_step(action) if self.distance_reward: reward += old_x_pos / 1.7 goombas_died = num_goombas - len([ x for x in self.level.entityList if ( (x.__class__.__name__ == 'Goomba' or x.__class__.__name__ == 'GoombaHeadless') and x.alive) ]) coins_taken = coins - len([ x for x in self.level.entityList if ( (x.__class__.__name__ == self.coin_name)) ]) coins_left = len([ x for x in self.level.entityList if ((x.__class__.__name__ == self.coin_name)) ]) self.observation = self.level_to_numpy() # print(coins_taken) info = { 'num_killed': goombas_died, 'coins_taken': coins_taken, 'death': self.mario.restart } if self.mario.restart: reward -= HOLE_REWARD if coins_left == 0 and coins_taken > 0: self.mario.restart = True restart = self.mario.restart or self.steps >= EPISODE_LENGTH return self.observation, reward, restart, info def render(self, mode='human', close=False): pass def get_screen(self): return self.screen def init_game(self, y_position=0, coins=0, points=0, time=0, clock=0): if not self.headless: pygame.mixer.pre_init(44100, -16, 2, 4096) pygame.init() self.screen = pygame.display.set_mode((640, 480)) self.dashboard = Dashboard("./img/font.png", 8, self.screen, coins=0, points=0, time=0) self.sound = Sound() self.level = Level(self.screen, self.sound, self.dashboard, self.levelname) self.menu = Menu(self.screen, self.dashboard, self.level, self.sound) self.menu.update() self.mario = Mario(0, y_position / 32, self.level, self.screen, self.dashboard, self.sound) if self.experiment == 'FD': self.mario2 = Mario(0, 2, self.level, self.screen, self.dashboard, self.sound) self.clock = pygame.time.Clock() self.menu.dashboard.state = "play" self.menu.dashboard.time = 0 self.menu.start = True pygame.display.update() else: self.level = LevelHeadless(self.levelname) if self.experiment == 'FD': self.mario2 = MarioHeadless(0, 2, self.level) self.mario = MarioHeadless(0, 0, self.level) self.clock = clock def do_game_step(self, move): if not self.headless: start_score = self.dashboard.points else: start_score = self.level.points counter = 0 reward = 0 while counter < self.step_size: counter += 1 coins = self.return_coins() self.do_move(move) if self.experiment == 'FD': random_move = random.choice(MOVES) self.do_random_move(self.mario2, random_move) if not self.headless: pygame.display.set_caption("{:.2f} FPS".format( self.clock.get_fps())) self.level.drawLevel(self.mario.camera) self.mario.update() if self.experiment == 'FD': self.mario2.update() self.clock.tick(self.max_frame_rate) self.dashboard.update() pygame.display.update() self.score = self.dashboard.points else: self.level.updateEntities() self.mario.update() if self.experiment == 'FD': self.mario2.update() self.clock += (1.0 / 60.0) self.score = self.level.points reward += coins - self.return_coins() return COIN_REWARD * reward def level_to_numpy(self, other_agent=False): mult = 1 granularity = 8 padding = int(256 / granularity) level_size = self.level.levelLength * padding array = np.zeros((EMBEDDING_SIZE, level_size, level_size)) granx = int(level_size / MAP_HEIGHT) grany = int(level_size / MAP_WIDTH) if other_agent: mult * +-1 y_axis_1 = int(round(self.mario.rect.top / granularity)) y_axis_2 = int(round(self.mario.rect.bottom / granularity)) x_axis_1 = int(round(self.mario.rect.left / granularity)) x_axis_2 = int(round(self.mario.rect.right / granularity)) if other_agent: array[EMBEDDINGS['Other_agents'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 else: array[EMBEDDINGS['Mario'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 if self.experiment == 'FD': y_axis_1 = int(round(self.mario2.rect.top / granularity)) y_axis_2 = int(round(self.mario2.rect.bottom / granularity)) x_axis_1 = int(round(self.mario2.rect.left / granularity)) x_axis_2 = int(round(self.mario2.rect.right / granularity)) if other_agent: array[EMBEDDINGS['Mario'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 else: array[EMBEDDINGS['Other_agents'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 for entity in self.level.entityList: y_axis_1 = int(round(entity.rect.top / granularity)) y_axis_2 = int(round(entity.rect.bottom / granularity)) x_axis_1 = int(round(entity.rect.left / granularity)) x_axis_2 = int(round(entity.rect.right / granularity)) if entity.__class__.__name__ == 'Koopa' or entity.__class__.__name__ == 'Goomba' or entity.__class__.__name__ == 'GoombaHeadless': array[EMBEDDINGS['Animal'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 elif entity.__class__.__name__ == 'Coin' or entity.__class__.__name__ == 'CoinHeadless': array[EMBEDDINGS['Coin'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 elif entity.__class__.__name__ == 'RandomBox': if not entity.triggered: array[EMBEDDINGS['Random_box'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 else: array[EMBEDDINGS['Random_box_trig'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 for layer in self.level.level: for ground in layer: if ground.rect: y_axis_1 = int(round(ground.rect.top / granularity)) y_axis_2 = int(round(ground.rect.bottom / granularity)) x_axis_1 = int(round(ground.rect.left / granularity)) x_axis_2 = int(round(ground.rect.right / granularity)) array[EMBEDDINGS['Ground'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 for layer in self.level.level[13:17]: for index in range(len(layer)): if not layer[index].rect and layer[index - 1].rect: y_axis_1 = int(round(layer[0].rect.top / granularity)) y_axis_2 = int(round(layer[0].rect.bottom / granularity)) x_axis_1 = int( round(layer[index - 1].rect.right / granularity)) width = layer[index - 1].rect.right - layer[index - 1].rect.left x_axis_2 = int( round((layer[index - 1].rect.right + 2 * width) / granularity)) array[EMBEDDINGS['Hole'], y_axis_1:y_axis_2, x_axis_1:x_axis_2] = 1 if self.partial_observation: left_paddding = int(round(self.mario.rect.y / granularity)) upper_padding = int(round(self.mario.rect.x / granularity)) x1 = max( 0, int(round(self.mario.rect.y / granularity)) - min(left_paddding, padding)) x2 = max( 0, int(round(self.mario.rect.y / granularity)) + (2 * padding - min(left_paddding, padding))) x3 = int(round(self.mario.rect.x / granularity)) - min( upper_padding, padding) x4 = int(round(self.mario.rect.x / granularity)) + ( 2 * padding - min(upper_padding, padding)) numpy_frame = array[:, x1:x2, x3:x4] else: numpy_frame = array[:, 0:MAP_HEIGHT, 0:MAP_WIDTH] return numpy_frame def count_entities(self, entity='coin'): if self.headless: no_entity = len([ entity for entity in self.level.entityList if isinstance(entity, CoinHeadless) ]) else: no_entity = len([ entity for entity in self.level.entityList if isinstance(entity, Coin) ]) self.no_coins = no_entity def return_coins(self, entity='coin'): if self.headless: no_entity = len([ entity for entity in self.level.entityList if isinstance(entity, CoinHeadless) ]) else: no_entity = len([ entity for entity in self.level.entityList if isinstance(entity, Coin) ]) return no_entity def level_to_empathic_numpy(self): granularity = 8 padding = int(256 / granularity) level_size = self.level.levelLength * padding array = np.zeros((level_size, level_size)) mario_pos = [ int(round(self.mario.rect.y / granularity)), int(round(self.mario.rect.x / granularity)) ] mario_representation = 128 ground_representation = 64 array[mario_pos[0]][mario_pos[1]] = mario_representation closest_enemy = None closest_distance = np.inf for entity in self.level.entityList: if entity.__class__.__name__ == 'Koopa' or entity.__class__.__name__ == 'Goomba' or entity.__class__.__name__ == 'GoombaHeadless': enemy_pos = [ int(round(entity.rect.y / granularity)), int(round(entity.rect.x / granularity)) ] array[enemy_pos[0], enemy_pos[1]] = enemy_representation distance = np.linalg.norm( np.array(mario_pos) - np.array(enemy_pos)) if distance < closest_distance: closest_distance = distance closest_enemy = enemy_pos # elif entity.__class__.__name__ == 'Coin': # array[int(round(entity.rect.y / granularity))][int(round(entity.rect.x / granularity))] = 2 # elif entity.__class__.__name__ == 'RandomBox': # if not entity.triggered: # array[int(round(entity.rect.y / granularity))][int(round(entity.rect.x / granularity))] = 3 # else: # array[int(round(entity.rect.y / granularity))][int(round(entity.rect.x / granularity))] = 4 for ground in self.level.groundList: array[int(round(32 * ground[1] / granularity))][int( round(32 * ground[0] / granularity))] = ground_representation array = np.hstack((np.zeros((level_size, padding)), array)) array = np.vstack((np.zeros((padding, level_size + padding)), array)) mario_view = array[max(0, mario_pos[0]):mario_pos[0] + 2 * padding, max(0, mario_pos[1]):mario_pos[1] + 2 * padding] if closest_enemy: enemy_view = array[max(0, closest_enemy[0]):closest_enemy[0] + 2 * padding, max(0, closest_enemy[1]):closest_enemy[1] + 2 * padding].copy() else: enemy_view = mario_view enemy_view[enemy_view == mario_representation] = enemy_representation enemy_view[padding, padding] = mario_representation if mario_view.shape == (padding * 2, padding * 2) and enemy_view.shape == (padding * 2, padding * 2): total_view = np.dstack((mario_view, enemy_view)) else: total_view = np.zeros((padding * 2, padding * 2, 2)) return total_view def level_to_supersimple_numpy(self): array = np.zeros(6) min_distance = 1000000 for entity in self.level.entityList: if entity.__class__.__name__ == 'Goomba' or entity.__class__.__name__ == 'GoombaHeadless': distance = np.absolute(self.mario.rect.x - entity.rect.x) if distance < min_distance: min_distance = distance array[0] = self.mario.rect.x - entity.rect.x array[1] = self.mario.rect.y - entity.rect.y array[5] = entity.vel.x array[2] = self.mario.vel.x array[3] = self.mario.vel.y array[4] = self.mario.rect.x return array def do_move(self, move): if move == 'moveLeft': self.mario.traits['goTrait'].direction = -1 elif move == 'moveRight': self.mario.traits['goTrait'].direction = 1 elif move == 'jump': self.mario.traits['jumpTrait'].start() elif move == 'jumpRight': self.mario.traits['goTrait'].direction = 1 self.mario.traits['jumpTrait'].start() elif move == 'jumpLeft': self.mario.traits['goTrait'].direction = -1 self.mario.traits['jumpTrait'].start() elif move == 'doNothing': self.mario.traits['goTrait'].direction = 0 def do_random_move(self, mario, move): if move == 'moveLeft': mario.traits['goTrait'].direction = -1 elif move == 'moveRight': mario.traits['goTrait'].direction = 1 elif move == 'jump': mario.traits['jumpTrait'].start() elif move == 'jumpRight': mario.traits['goTrait'].direction = 1 mario.traits['jumpTrait'].start() elif move == 'jumpLeft': mario.traits['goTrait'].direction = -1 mario.traits['jumpTrait'].start() elif move == 'doNothing': mario.traits['goTrait'].direction = 0
from classes.Constants import * from classes.Level import Level from classes.Menu import Menu from classes.SoundPlayer import SoundPlayer from entities.Mario import Mario fps_clock = pygame.time.Clock() pygame.init() window_size = (16 * tile_size * scale, 14 * tile_size * scale) # 25*14 pygame.display.set_caption('MARIO') screen = pygame.display.set_mode(window_size) bg = pygame.transform.scale(screen, (w, h)) sound_player = SoundPlayer() while True: menu = Menu(screen, sound_player) while not menu.pause: menu.update() pygame.display.update() fps_clock.tick(FPS / 6) if sound_player.allow_sound: if not sound_player.bg_sound.is_playing(): sound_player.bg_sound.play_sound(True) else: sound_player.bg_sound.stop_sound() level = Level("levels/" + menu.level_name, screen) background = Background(0, 0, screen, level) mario = Mario(0, 0, Mario.DIRECTION_RIGHT, 0, Mario.IN_AIR, screen, background, level, sound_player) background.set_character(mario)