def process_cli_args(args): currentIndex = 0 skipIndex = 0 instructions = None for item in args: if (skipIndex == currentIndex): currentIndex = currentIndex + 1 continue if (item == 'decode'): if (instructions is None): instructions = Instructions("decode") else: print("Not allowed to have multiple methods.") raise Exception() elif (item == 'encode'): if (instructions is None): instructions = Instructions("encode") else: print("Not allowed to have multiple methods.") raise Exception() elif (item == 'main.py'): print("found main method") elif (item == '-i'): iterations = int(args[currentIndex + 1]) instructions.iterations = iterations skipIndex = currentIndex + 1 else: instructions.string = item currentIndex = currentIndex + 1 return instructions
def __init__(self): self.settings = GameSettings() self.scoreBoard = ScoreBoard(self.settings) self.gameBoard = GameBoard(self.settings) self.instructions = Instructions() self.endScreen = EndScreen() self.ballGrid = [[0 for x in range(self.settings.numberBallsH)] for y in range(self.settings.numberBallsV)] self.level = 2 self.score = 0
def game_thread(data): ''' Used by create_game. It is the component of the function that is run in a seperate thread. This is to prevent the controller from locking up. ''' print(data) global GAME global INSTRUCTIONS INSTRUCTIONS = True DISPLAY.update(Instructions().get(data)) SOCKETIO.sleep(25) INSTRUCTIONS = False GAME = GameList.select_game(data, list(USERS.values()), \ socketio=SOCKETIO, display_game=DISPLAY) SOCKETIO.emit('gameStarted', data, broadcast=True) GAME.run_game() threading.Thread(target=check_thread).start()
def main(): #pygame init pygame.mixer.pre_init(SAMPLE_RATE, BIT, CHANNELS, BUFFER_SIZE) pygame.init() pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption('PyTone') #make background background = Gradient((WIDTH, HEIGHT), GRAD_START, GRAD_END) #path to medias path = 'media/' pygame.display.set_icon(pygame.image.load(path + 'petrol.png')) #intro duration in milliseconds duration = 4000 #states intro = Intro(background, path, duration) menu = Menu(background, path) game = Game(background, path) instructions = Instructions(background, path) intro.run() #storing return value from menu running = True while running: option = menu.run() if option == NEW_GAME: option = game.run() elif option == INSTRUCTIONS: instructions.run() elif option == PRACTICE: #intro.run() game.set_practise(True) game.run() game.set_practise(False) #no elif here to make different states be able to quit as well if option == pygame.locals.QUIT: pygame.quit() running = False
#!python # imports do sistema do python import sys import re # criados por nos from instructions import Instructions from registers import Registers instr = Instructions() regs = Registers() # parse dos registradores def parse_immediate(line): line = line.split() for i, token in enumerate(line): # ignore a instrucao e os registradores, # processe somente numeros decimais # (imediatos e numeros crus) if (i == 0 or token[0] == 'r'): continue # verifique o tamanho final das palavra word_size = (5 if i < 3 else 16) # altere o token (que e um numero) token = bin(int(token))[2:] # faca o prepend de zeros na frente do token pra que # ele tenha o tamanho correto line[i] = '0' * (word_size - len(token)) + token return ' '.join(line)
pauseGame = False # Pause mode musicPlaying = False # Toggle for music flashTextTimer = 60 # On-screen text timer highscore = 500 # Default highscore shakeX = 0 health = 10 # Health of ship bulletCount = 9 bombs = 0 # Bombs for player emergencies gameMode = 0 # 0 for arcade, 1 for survival # Counters shuttleTimer = 200 enemyTimer = 400 bossTimer = 500 # Init classes instructions = Instructions() bg = Background(0, 0) player = Player(playerPos[0], playerPos[1], 0, 94, 0, 71) audio = Audio(g_sound, isThisRealHardware) shake = Shake() # Sprites, images, objects bg = graphics.g_background.bg logo = graphics.g_items.logo scoreChars = [graphics.g_numbers.number0, graphics.g_numbers.number1, graphics.g_numbers.number2, graphics.g_numbers.number3, graphics.g_numbers.number4, graphics.g_numbers.number5, graphics.g_numbers.number6, graphics.g_numbers.number7, graphics.g_numbers.number8, graphics.g_numbers.number9] rockImages = [graphics.g_rocks.rock01, graphics.g_rocks.rock02, graphics.g_rocks.rock03, graphics.g_rocks.rock04, graphics.g_rocks.rock05] crystalImages = [graphics.g_items.crystal01, graphics.g_items.crystal02, graphics.g_items.crystal03, graphics.g_items.crystal04, graphics.g_items.crystal05, graphics.g_items.crystal06] playerShip = graphics.g_ships.playerShip shuttleShip = graphics.g_ships.ship04 enemyShipImages = [graphics.g_ships.ship01, graphics.g_ships.ship02, graphics.g_ships.ship03] bossShipImages = [graphics.g_ships.boss01, graphics.g_ships.boss02, graphics.g_ships.boss03, graphics.g_ships.boss04]
def instructionsGame(): screen_dimensions = utils.get_screen_dimensions() instructions = Instructions(screen_dimensions['width'], screen_dimensions['height']) instructions.run(True)
def run_game(): # Initialise pygame, settings and screen object. pygame.init() pygame.mixer.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Alien Invasion") # Make the Play button play_button = Button(ai_settings, screen, "Ready Player 1?") pause_button = Button(ai_settings, screen, "Paused") instructions = Instructions(ai_settings, screen) # Make a ship ship = Ship(ai_settings, screen) # Make a group to store bullets in bullets = Group() # Make a group to store aliens in aliens = Group() # Create a fleet of aliens gf.create_fleet(ai_settings, screen, ship, aliens) bombs = Group() # Make a group to store bricks in bricks_1 = Group() bricks_2 = Group() bricks_3 = Group() # Create a barrier of bricks gf.create_barriers(ai_settings, screen, ship, bricks_1, bricks_2, bricks_3) # create an instance to store game statistics and create a scoreboard stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) # Start the main loop for the game. while True: # Watch for keybaord and mouse events. gf.check_events(ai_settings, stats, sb, screen, play_button, pause_button, ship, aliens, bullets, bombs, bricks_1, bricks_2, bricks_3) if stats.game_paused: gf.check_pause(stats) if stats.game_active: # Update the ship position ship.update() # update the ship bullets gf.update_bullets(ai_settings, stats, sb, screen, ship, aliens, bullets, bricks_1, bricks_2, bricks_3) # update the aliens position gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens, bullets, bombs, bricks_1, bricks_2, bricks_3) gf.update_bombs(ai_settings, stats, sb, screen, ship, aliens, bullets, bombs, bricks_1, bricks_2, bricks_3) # Redraw the screen during each pass through the loop and, # make the most recently drawn screen visible. gf.update_screen(ai_settings, stats, sb, screen, ship, aliens, bullets, bombs, bricks_1, bricks_2, bricks_3, play_button, pause_button, instructions)
def __init__(self, port): self.port = port self.reg = ControlTable() self.instructions = Instructions()