def main_menu(): menu = True texts = [ "START YOUR RACE", "TWO PLAYERS MODE", "CUSTOMIZE YOUR CAR", "QUIT" ] chosen_option = 0 while menu: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: if chosen_option > 0: chosen_option -= 1 else: chosen_option = len(texts) - 1 elif event.key == pygame.K_DOWN: if chosen_option < len(texts) - 1: chosen_option += 1 else: chosen_option = 0 if event.key == pygame.K_RETURN: if chosen_option == 0: level1.main() elif chosen_option == 1: pygame.quit() os.system('python {}'.format('two_players_mode.py')) elif chosen_option == 2: car_customization.customize_car() elif chosen_option == 3: pygame.quit() quit() screen.fill((0, 0, 0)) img = pygame.image.load("Images/menu.png").convert() img = pygame.transform.scale(img, (screen_width, screen_height)) screen.blit(img, (0, 0)) # Main Menu Text title = pygame_classes.text_format("Racing game", font, 150, red) title_rect = title.get_rect() screen.blit(title, (screen_width / 2 - (title_rect[2] / 2), screen_height / 6)) for text_index in range(len(texts)): col = white if text_index == chosen_option else black text = pygame_classes.text_format(texts[text_index], font, 100, col) text_rect = text.get_rect() screen.blit(text, (screen_width / 2 - (text_rect[2] / 2), (text_index + 3) * screen_height / 8)) pygame.display.update() pygame.display.set_caption("Racing Game - main menu ") clock.tick(FPS)
def test_Main(self): # # INPUT: # <rows> <cols> <n-pos> <pos-1> <pos-2> ... <pos-n> # # OUTPUT: # <row-1> <col-1> <row-2> <col-2> ... <row-n> <col-n> # # 1 2 3 4 5 # 6 7 8 9 0 # 1 2 3 4 5 # 6 7 8 9 0 self.assertEqual(main([4, 5, 3, 1, 17, 13]), '1 1 4 2 3 3')
pygame.init() pygame.mixer.init() if __name__ == "__main__": donePlaying = False while donePlaying == False: level = mainmenu.mainmenu() while level >= 0: if level == 0: level = mainmenu.mainmenu() if level == 1: level = level1.main() if level == 2: level = level2.main() if level == 3: level = level3.main() level, donePlaying = gameOver.main()
#see http://stackoverflow.com/questions/10391123/how-to-run-two-python-blocking-functions-matplotlib-show-and-twisted-reactor-r if __name__ == '__main__': from level1 import main raise SystemExit(main()) from matplotlib import use use('GTK') from matplotlib import pyplot from matplotlib.backends import backend_gtk from twisted.internet import gtk2reactor gtk2reactor.install() #OK, we are done with wierd stuff here, the rest is vanilla from twisted.internet import reactor, task from steering.twisted_steering import press import os import numpy as np import time from math import pi from pylab import get_current_fig_manager import networkx as nx from planning.astar.global_map import (plot_map, GlobalMap, MIN_UNCONTRAINED_PENALTY)
def main(): start.Main() level1.main() level2.Main() level3.Main() level4.main()
'''Author: Jesse Higgins Last Modified By: Jesse Higgins Date Last Modified: July 25th 2013 Program Description: Leapy is a fun little frogger game with unique levels and requires you to collect all the objects in that level in order to move on to the next. version 0.2: - added movement to frogger including boundaries on the game screen - sound implementation for collisions has been included - collision detection included ''' import pygame, mainmenu, level1 pygame.init() pygame.mixer.init() if __name__ == "__main__": level = mainmenu.mainmenu() if level == 1: level1.main()
for i in pygame.event.get(): if i.type == QUIT or press[K_q]: exit() screen.fill((0, 0, 0)) mousepress = pygame.mouse.get_pressed() l1 = pygame.font.SysFont("comicsansms", 50) l2 = pygame.font.SysFont("comicsansms", 30) l3 = pygame.font.SysFont("comicsansms", 30) l4 = pygame.font.SysFont("comicsansms", 30) r2 = Rect((100, 200), l2.size("Press 1 for Level 1 ")) r3 = Rect((100, 250), l3.size("Press 2 for Level 2 ")) r4 = Rect((100, 300), l3.size("Press 3 for Level 3 ")) screen.blit(l1.render("Select Your Level", True, (0, 255, 0)), (100, 100)) screen.blit(l2.render("Press 1 for Level 1 ", True, (0, 255, 0)), (100, 200)) screen.blit(l3.render("Press 2 for level 2 ", True, (0, 255, 0)), (100, 250)) screen.blit(l4.render("Press 3 for level 3 ", True, (0, 255, 0)), (100, 300)) pygame.display.update() if press[K_1] or (r2.collidepoint(pygame.mouse.get_pos()) and mousepress[0]): level1.main() if press[K_2] or (r3.collidepoint(pygame.mouse.get_pos()) and mousepress[0]): level2.main() if press[K_3] or (r4.collidepoint(pygame.mouse.get_pos()) and mousepress[0]): level3.main()
import glob import os from level1 import main if __name__ == '__main__': for fileInPath in glob.glob('data/in/*.in'): fileIn = open(fileInPath, "r") fileInBasename = os.path.basename(fileInPath) fileOut = open("data/out/" + fileInBasename + ".out", "w") fileInContent = fileIn.read() args = fileInContent.split(" ") print("Processing", fileInBasename + ": ", end="") out = main(args) fileOut.write("%s" % out) print("done")