def next(self): """Vykonanie nasledujúceho dňa. Zahŕňa to kvalifikáciu a samotné majstrovstvá""" #Histórií povieme, že ideme do nasledujúceho dňa self.history.next_day() #Pýtame sa, či sa ešte hrá kvalifikácia if (self.qual_is_playing): self.qual_is_playing = self.q_next() #Kvalifikacia sa skoncila, pripravime si majstrovstva. #V tento deň sa neodohrá žiadny zápas if (not self.qual_is_playing): final_list = [] #Z každej kvalifikácie si vypýtame postupujúce tímy for q in self.q_list: for l in q.get_winners(): final_list.append(l) self.world_cup = final.Final(final_list, self.simulator) else: #Hra sa finale if (self.world_cup.has_next()): self.world_cup.next() else: print('Majstrovstvá sa už skončili.', end='\n')
def main(argv): get_program_parameters(argv) read_input_file() m_lexer = lexer.Lexer(debug) m_lexer.init_lexer(source_content) m_symbol = st.Symbol(debug) m_inter = intermediate.Intermediate(debug, m_symbol) m_syntax = syntax.Syntax(m_lexer, m_symbol, m_inter) m_syntax.run_syntax() m_inter.generate_int_file(m_syntax.get_program_id()) m_inter.generate_c_code(m_syntax.get_program_id()) m_final = final.Final(debug, m_syntax.get_program_id(), m_symbol) m_final.generate_final(m_inter) m_final.generate_out_file(output_file_path) print "\n" + output_file_path + " file has been created." print "\nDone."
def draw(self, level, b): self.player.x, self.player.y = 40, 40 # self.start_ticks = py.time.get_ticks() file = open(str(level), "r").read().split('\n') x, y = 0, 0 for row in file: x = 0 for col in row: if str(col) == str(1): img = py.image.load('images/tiles/slate.png').convert() config.screen.blit(img, (x, y)) walls.append((x, y)) elif str(col) == str(2) or str(col) == str(3) or str( col) == str(4) or str(col) == str(5): img = py.image.load('images/tiles/1.png').convert() config.screen.blit(img, (x, y)) brick.append((x, y)) if str(col) == str(2): bomb_powerup.append((x, y)) elif str(col) == str(3): life_pick.append((x, y)) elif str(col) == str(4): add_bomb.append((x, y)) elif str(col) == str(5): doors.append((x, y)) else: img = py.image.load('images/tiles/ground.png').convert() config.screen.blit(img, (x, y)) x = x + 40 y = y + 40 act_level = self.actual_level() for i in range(act_level + 3): if i == 0: continue e = enemy.Enemy(i, b) enemies_alive.append(e) clock = py.time.Clock() self.seconds = 200 milliseconds = 0 config.screen.blit(self.player.image_start, (40, 40)) while self.running: if milliseconds > 1000: self.seconds -= 1 milliseconds -= 1000 milliseconds += clock.tick_busy_loop(60) if self.seconds == 0: for n in enemies_alive: n.alive = False self.door_opened = False if b.score != 0: open("highscores.txt", "a").write(str(b.score) + "\n") clear() self.door_opened = False config.flaga = False endGame.EndGame() break if config.actual_level == 5: if self.door_opened and (b.x, b.y) == doors[0]: self.door_opened = False for n in enemies_alive: n.alive = False open("highscores.txt", "a").write(str(b.score) + "\n") clear() final.Final(b) break self.gui() for i in enemies_alive: self.enemiesXY.append(i.getEXY()) if not self.moveXD: config.screen.blit(b.image_start, (40, 40)) if (b.x, b.y) in self.enemiesXY: b.lives -= 1 self.die() # jesli wejdziemy w zasieg wybuchu bomby tracimy zycie if (b.x, b.y) in bomb.explode_range: b.lives -= 1 bomb.explode_range.clear() self.die() # jestli mamy 0 zyc gra sie konczy if b.lives <= 0: for n in enemies_alive: n.alive = False self.door_opened = False if b.score != 0: open("highscores.txt", "a").write(str(b.score) + "\n") clear() self.door_opened = False config.flaga = False endGame.EndGame() break # jesli zabijemy przeciwnikow otwieraja sie drzwi if config.enemy_alive == 0: if config.flaga: config.screen.blit(self.doors_open, doors[0]) self.door_opened = True # jesli drzwi sa otwarte oraz stoimy na nich przechodzimy na nastepny poziom if self.door_opened and (b.x, b.y) == doors[0]: clear() config.actual_level += 1 self.alive = config.actual_level + 3 self.door_opened = False config.enemy_alive = config.actual_level + 2 b.currentBomb += 20 config.flaga = False self.draw(config.actual_level, b) break for event in py.event.get(): if event.type == py.KEYDOWN: if event.key == py.K_SPACE: if b.currentBomb > 0: x, y = b.getXY() bomb_xy.append(b.getXY()) bomb1 = threading.Thread(target=bomb.Bomb, args=(x, y, b.power, self.door_opened, self.player)) bomb1.start() b.currentBomb -= 1 bomb_threads.append(bomb1) # cheat kill enemies if event.key == py.K_k: for n in enemies_alive: n.alive = False enemies_alive.clear() self.door_opened = True config.flaga = True config.screen.blit(self.doors_open, doors[0]) else: self.moveXD = True b.movement(event.key) self.enemiesXY.clear() py.display.update() py.display.flip()
def __init__(self): self.screen, self.canvas, self.fps, self.clock = tools.pygame_setup( pygame, settings) self.audio = audio.Audio(pygame) self.tileset, self.tiles, self.font = tools.data_load(pygame, settings) self.alarms = alarms.Alarms(settings.system['alarms']['counters'], settings.system['alarms']['timers'], settings.system['alarms']['steps']) self.hiscores = hiscores.Hiscores(settings) game_blocks = { 'title': title.Title(settings.system['screen_width'], settings.system['screen_height'], self.hiscores, settings, pygame), 'maze': maze.Maze(settings.system['view_width_sq'], settings.system['view_height_sq'], settings), 'over': over.Over(settings.system['screen_width'], settings.system['screen_height'], self.hiscores, settings), 'final': final.Final(settings.system['screen_width'], settings.system['screen_height'], self.hiscores, settings) } game_block = game_blocks['title'] game_block.launch(self.audio, settings, None) while True: counters = self.alarms.tick() self.dynamic_palettes(counters) # Check app input events for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_m: if self.audio.mute: self.audio.mute = False pygame.mixer.music.load(self.audio.bank_music[ self.audio.music_playing]) pygame.mixer.music.play(-1) else: self.audio.mute = True pygame.mixer.music.stop() game_block.events(pygame, event) # Game modules block_response = game_block.tick(counters, self.tiles, self.audio, settings) if block_response is not None: game_block = game_blocks[block_response[0]] game_block.launch(self.audio, settings, block_response[1]) continue # print(self.clock.get_fps()) # Scene drawing game_block.stage_display(self.tiles, self.font, self.canvas, counters, pygame, settings, mirror_h=False, mirror_v=False, palette=None) # Scaling and displaying a frame pygame.transform.scale(self.canvas, (settings.system['screen_width'] * settings.system['screen_scale'], settings.system['screen_height'] * settings.system['screen_scale']), self.screen) pygame.display.flip() # self.clock.tick(settings.system['fps']) self.clock.tick_busy_loop(settings.system['fps'])
def main(): # constants throught program SCREEN_WIDTH = 800 SCREEN_HEIGHT = 500 BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) pygame.init() mainsurface = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), 0, 32) pygame.display.set_caption("Star Runner") # creates group, adds sprite to group and sets the position of the background backroundGroup = pygame.sprite.Group() mybackround = backround.Backround(mainsurface) mybackround.rect.topleft = (0, 0) mybackround.add(backroundGroup) # creates group, adds sprite to group and sets the position of the spaceship manGroup = pygame.sprite.Group() myman = man.Man(mainsurface) myman.rect.topleft = (50, 250) myman.add(manGroup) # creates group, adds sprite to group and sets the position of # the end line to delete sprites that are not on the screen endGroup = pygame.sprite.Group() myend = ground.End(mainsurface, RED) myend.rect.topleft = (-1, -4000) myend.add(endGroup) # creates group and defines mystar starGroup = pygame.sprite.Group() mystar = special.Special(mainsurface) # creates various sprite groups fireGroup = pygame.sprite.Group() finalGroup = pygame.sprite.Group() ememyGroup = pygame.sprite.Group() groundGroup = pygame.sprite.Group() thefire = fire.Fire(mainsurface, RED) # defines clock so frames per second can be set clock = pygame.time.Clock() # loads the music mixer and plays the backround music in a loop # music from http://www.thesoundarchive.com/star-wars.asp pygame.mixer.music.load("imperial_march.wav") pygame.mixer.music.play(-1) # while loop for start screen end_it = False while (end_it == False): # stes frames per second clock.tick(30) mainsurface.fill(BLACK) # defines various fonts for labels myfont = pygame.font.SysFont("Britannic Bold", 100) myfont1 = pygame.font.SysFont("Britannic Bold", 50) slabel1 = myfont.render("Star Runner", 1, (255, 0, 0)) slabel2 = myfont1.render("Click or press space to Play", 1, (0, 0, 255)) # sets and updates the x and y positions for the asteroids ypos = random.randint(0, 1200) xpos = (820) # sets up myground to be blit on screen myground = ground.Ground(mainsurface) myground.rect.topleft = (xpos, ypos) myground.add(groundGroup) # sets and updates the x and y positions for the rockets ypose = random.randint(0, 5000) xpose = (820) # sets up myenemy to be blit on screen myenemy = enemy.Enemy(mainsurface) myenemy.rect.topleft = (xpose, ypose) myenemy.add(ememyGroup) # adds backround and labels to screen mainsurface.blit(mybackround.image, mybackround.rect) mainsurface.blit(slabel1, (200, 100)) mainsurface.blit(slabel2, (150, 200)) # adds endline to screen to delete uneeded sprites for myend in endGroup: mainsurface.blit(myend.image, myend.rect) # adds rockets to screen and updates them for myenemy in ememyGroup: mainsurface.blit(myenemy.image, myenemy.rect) myenemy.update(groundGroup) myenemy.update(fireGroup) # adds asteroids to screen and updates them for myground in groundGroup: mainsurface.blit(myground.image, myground.rect) myground.update() # deletes uneeded sprites that are not on the screen myend.collide(ememyGroup) myend.collide(groundGroup) # ends start screen if mouse/spacebar is pressed for event in pygame.event.get(): if event.type == MOUSEBUTTONDOWN or pygame.key.get_pressed()[ pygame.K_SPACE]: for myenemy in ememyGroup: myenemy.remove(ememyGroup) for myground in groundGroup: myground.remove(groundGroup) end_it = True if event.type == QUIT: pygame.quit() sys.exit() # used to pause/unpause music in game if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_p): pygame.mixer.music.pause() if (event.key == pygame.K_u): pygame.mixer.music.unpause() pygame.display.update() pygame.display.flip() # main game loop while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if (event.type == pygame.KEYDOWN): # adds projectile to screen when spacebar is pressed if (event.key == pygame.K_SPACE): thefire.add(fireGroup) thefire.rect.topleft = (myman.rect.left + 5, myman.rect.top + 10) # used to pause/unpause music in game if (event.key == pygame.K_p): pygame.mixer.music.pause() if (event.key == pygame.K_u): pygame.mixer.music.unpause() # sets frames per second in game clock.tick(30) # sets and updates the x and y positions for the asteroids ypos = random.randint(0, 2400) xpos = (920) # sets up myground to be blit on screen myground = ground.Ground(mainsurface) myground.rect.topleft = (xpos, ypos) myground.add(groundGroup) # sets and updates the x and y positions for the rockets ypose = random.randint(0, 10000) xpose = (920) # sets up myenemy to be blit on screen myenemy = enemy.Enemy(mainsurface) myenemy.rect.topleft = (xpose, ypose) myenemy.add(ememyGroup) pressed = pygame.key.get_pressed() # moves spaceship when arrow keys are pressed if pressed[pygame.K_LEFT]: myman.left() if pressed[pygame.K_RIGHT]: myman.right() if pressed[pygame.K_UP]: myman.up() if pressed[pygame.K_DOWN]: myman.down() # decreases health of spaceship if it hits the asteroids of the rockets myman.collide(groundGroup) myman.collide(ememyGroup) myman.collide_final(finalGroup) # deletes uneeded sprites that are not on the screen myend.collide(ememyGroup) myend.collide(groundGroup) # adds and updates level label if player gets enough points level = 1 points = thefire.the_score if points >= 15: level += 1 if points >= 30: level += 1 if points >= 45: level += 1 if points >= 60: level += 1 if points >= 75: level += 1 if points >= 90: level += 1 if points >= 105: level += 1 if points >= 120: level += 1 if points >= 135: level += 1 if points >= 150: level = "Final" scorefont = pygame.font.SysFont("Britannic Bold", 40) scorelable = scorefont.render("Score: {0}".format(points), 1, RED) levellable = scorefont.render("Level: {}".format(level), 1, RED) # defines labels for wining and loosing in the game overlable = myfont.render("Game Over", 1, (255, 0, 0)) winlable = myfont.render("You Won!", 1, (255, 0, 0)) mainscreenlable = scorefont.render( "Press Space to return to home screen", 1, (0, 0, 255)) # defines lives and lives label lives = myman.lives liveslable = scorefont.render("Health:".format(lives), 1, RED) # adds backround image to screen mainsurface.blit(mybackround.image, mybackround.rect) # adds endline to delete uneeded sprites to screen for myend in endGroup: mainsurface.blit(myend.image, myend.rect) # adds rockets and updates them for myenemy in ememyGroup: mainsurface.blit(myenemy.image, myenemy.rect) myenemy.update(groundGroup) myenemy.update(fireGroup) # adds asteroids to screen and updates them for myground in groundGroup: mainsurface.blit(myground.image, myground.rect) myground.update() # adds projectile to screen for thefire in fireGroup: mainsurface.blit(thefire.image, thefire.rect) thefire.fire() thefire.collide_ground(groundGroup) # does needed actions if player wins the game # sound from https://www.freesound.org win = pygame.mixer.Sound("Ta_Da-SoundBible.wav") if points >= 200: myman.rect.top = 4000 myman.rect.left = 4000 mainsurface.blit(winlable, (200, 200)) mainsurface.blit(mainscreenlable, (120, 275)) pygame.mixer.music.stop() win.play() for myfinal in finalGroup: myfinal.remove(finalGroup) if pressed[pygame.K_SPACE]: main() # adds spaceship to screen mainsurface.blit(myman.image, myman.rect) # adds labels to screen mainsurface.blit(scorelable, (10, 10)) mainsurface.blit(liveslable, (10, 473)) mainsurface.blit(levellable, (630, 10)) # makes game harder ass player gains points if points >= 15: for myground in groundGroup: myground.level_up() if points >= 30: for myenemy in ememyGroup: myenemy.level_up() if points >= 45: for myground in groundGroup: myground.level_up() if points >= 60: for myenemy in ememyGroup: myenemy.level_up() if points >= 75: for myground in groundGroup: myground.level_up() if points >= 90: for myenemy in ememyGroup: myenemy.level_up() if points >= 105: for myground in groundGroup: myground.level_up() if points >= 120: for myenemy in ememyGroup: myenemy.level_up() if points >= 135: for myground in groundGroup: myground.level_up() # sets up final level for game if points >= 150: for myenemy in ememyGroup: myenemy.remove(ememyGroup) for myground in groundGroup: myground.remove(groundGroup) y = random.randint(0, 2500) x = 920 myfinal = final.Final(mainsurface) myfinal.rect.topleft = (x, y) myfinal.add(finalGroup) mainsurface.blit(myfinal.image, myfinal.rect) for myfinal in finalGroup: mainsurface.blit(myfinal.image, myfinal.rect) myfinal.update(manGroup) if thefire.collide_final(finalGroup): thefire.remove(fireGroup) # sets up star power-up at different points of the game if points == 15: mystar.rect.topleft = (920, random.randint(5, 495)) mystar.add(starGroup) if points == 45: mystar.rect.topleft = (920, random.randint(5, 495)) mystar.add(starGroup) if points == 75: mystar.rect.topleft = (920, random.randint(5, 495)) mystar.add(starGroup) if points == 105: mystar.rect.topleft = (920, random.randint(5, 495)) mystar.add(starGroup) if points == 135: mystar.rect.topleft = (920, random.randint(5, 495)) mystar.add(starGroup) for mystar in starGroup: mainsurface.blit(mystar.image, mystar.rect) mystar.update() # adds lives if spaceship hits the star power-up myman.colide_2(starGroup, manGroup) pygame.draw.rect(mainsurface, (RED), (115, 480, lives, 15), 0) # deletes sprites and adds labels if player looses if lives <= 0: myman.rect.top = 4000 myman.rect.left = 4000 mainsurface.blit(overlable, (200, 200)) mainsurface.blit(mainscreenlable, (120, 275)) pygame.mixer.music.stop() if pressed[pygame.K_SPACE]: main() pygame.display.update()
def next(root, images): root.destroy() page6w = final.Final(images)