def curses_create_subscrs(scr: Screen, right_start: int) -> Tuple[Screen, Screen]: pos_screen = scr.subwin(curses.LINES - 2, right_start, 2, 4) defn_screen = scr.subwin(2, 4 + right_start) return (Screen(pos_screen, curses.LINES - 2, right_start), Screen(defn_screen, curses.LINES - 2, curses.COLS - right_start - 4))
def load(preset: dict): t0, t1 = preset['t0'], preset['t1'] screen = Screen((1920, 1080), xlim=(preset['x0'], preset['x1']), ylim=(preset['y0'], preset['y1'])) x_, y_ = preset['x_'], preset['y_'] return preset['n_iters'], preset['trail_length'], preset['x0'], preset['x1'], preset['y0'], preset['y1'], t0, t1, x_, y_, screen
def __init__(self, asteroids_amnt): """ Initializes the GameRunner class and all the game related parameters :param asteroids_amnt: int representing the amount of asteroids """ self._screen = Screen() self.screen_max = Screen.SCREEN_MAX_X, Screen.SCREEN_MAX_Y self.screen_min = Screen.SCREEN_MIN_X, Screen.SCREEN_MIN_Y self.screen_dist = self.screen_max[self.X] - self.screen_min[self.X], \ self.screen_max[self.Y] - self.screen_min[self.Y] self.ship = Ship(self.get_random_position(), self.INIT_SHIP_VELOCITY) self.asteroids = [] # This section of code creates a list of asteroid objects with random # location and velocity parameters for i in range(asteroids_amnt): # Generates random values for asteroid object location asteroid_pos = self.get_random_position() # Asteroid's position shouldn't be the same as the ship's while asteroid_pos == self.ship.get_position(): asteroid_pos = self.get_random_position() # Generates random values for asteroid object speed on x and y axis asteroid_vel = randint(self.AST_VEL_MIN, self.AST_VEL_MAX), \ randint(self.AST_VEL_MIN, self.AST_VEL_MAX) self.add_asteroid(asteroid_pos, asteroid_vel, self.INIT_AST_SIZE) self.score = 0 self.torpedo_lives = [] self.torpedo_count = 0 self.torpedos = [] self.ship_lives = self.MAX_SHIP_LIVES
def curses_begin() -> Screen: scr = Screen(curses.initscr(), curses.LINES, curses.COLS) curses.noecho() scr.win.keypad(1) curses.start_color() Color.init_color_pairs() return scr
def __init__(self, asteroids_amount): self.__screen = Screen() self.__screen_max_x = Screen.SCREEN_MAX_X self.__screen_max_y = Screen.SCREEN_MAX_Y self.__screen_min_x = Screen.SCREEN_MIN_X self.__screen_min_y = Screen.SCREEN_MIN_Y ship_x = random.randint(Screen.SCREEN_MIN_X, Screen.SCREEN_MAX_X) ship_y = random.randint(Screen.SCREEN_MIN_Y, Screen.SCREEN_MAX_Y) self.__screen.draw_ship(ship_x, ship_y, 0) self.__player = Ship(ship_x, ship_y, 0, 0, 0) ast_speeds = list(range(-4, 0)) + list(range(1, 5)) ast_xs, ast_ys = self.non_colliding_start(self.__player, asteroids_amount) self.__ast_size = 3 self.__ast_ls = [] for i in range(asteroids_amount): as_x_sp = random.choice(ast_speeds) as_y_sp = random.choice(ast_speeds) asteroid = Asteroid(ast_xs[i], ast_ys[i], as_x_sp, as_y_sp, self.__ast_size) self.__ast_ls.append(asteroid) self.__screen.register_asteroid(asteroid, self.__ast_size) self.__screen.draw_asteroid(asteroid, ast_xs[i], ast_ys[i]) self.__life_count = 0 self.__score = 0 self.__torpedo_ls = []
def __init__(self, asteroids_amnt): """ :param asteroids_amnt: number of asteroids in the game This function initialize the game Asteroid """ self._screen = Screen() self.screen_max_x = Screen.SCREEN_MAX_X self.screen_max_y = Screen.SCREEN_MAX_Y self.screen_min_x = Screen.SCREEN_MIN_X self.screen_min_y = Screen.SCREEN_MIN_Y self._max_coordinates_vector = \ Vector(self.screen_max_x, self.screen_max_y) self._min_coordinates_vector = \ Vector(self.screen_min_x, self.screen_min_y) self._delta_axis_vector = \ self._max_coordinates_vector - self._min_coordinates_vector self._ship = self.create_new_ship() self._asteroid_list = self.create_asteroids(asteroids_amnt) self._torpedos_list = [] self._score = GameRunner.START_SCORE_AT self.draw_score()
def main(): """ Entry point """ def game_update(pit_info): """ Boucle principale du jeu """ if not core.update(event_loop.get()): return False screen.update(core.render(screen.get_size(), screen.g_pos(), pit_info)) return True try: # Ecran screen = Screen() #Coeur du jeu core = Core() # boucle d'evenements event_loop = MyEventLoop() event_loop.start() timer = Pit(0.1, game_update) timer.start() screen.stop() print("Votre score : {}$".format(core.player.money)) return True finally: # Stop secu screen.stop()
def __init__(self, asteroids_amount): """ :param .__screen: the screen of the game #### NOTE: the follow parameter are unused, but we left it here so it wouldn't fall in automatic tests. ### :param .__screen_max_x: the max vertical coordination of the screen. :param .__screen_max_y: the max horizontal coordination of the screen. :param .__screen_min_x: the min vertical coordination of the screen. :param .__screen_min_y: the min horizontal coordination of the screen. :param .__current_ship: ship object - the ship of the game. :param .__asteroid_list: list of all the asteroid in the game :param .__torpedo_list: a list of all the torpedoes in the game. :param .__score: the score the player got. """ self.__screen = Screen() self.__screen_max_x = Screen.SCREEN_MAX_X self.__screen_max_y = Screen.SCREEN_MAX_Y self.__screen_min_x = Screen.SCREEN_MIN_X self.__screen_min_y = Screen.SCREEN_MIN_Y self.__current_ship = Ship() self.__asteroid_list = [] self.__torpedo_list = [] self.__score = 0 self._init_asteroid_start(asteroids_amount=asteroids_amount)
def __init__(self, tipo_p1, nome_p1, tipo_p2, nome_p2): p.init() p.font.init() self.screen = Screen() self.juiz = Juiz() self.turno = bool(randint(0, 1)) if tipo_p1: self.player1 = Player(nome_p1) else: self.player1 = Bot(self.juiz, nome_p1) if tipo_p2: self.player2 = Player(nome_p2) else: self.player2 = Bot(self.juiz, nome_p2) self.player1.init_keys(self.juiz.bag) self.player2.init_keys(self.juiz.bag) self.run = True self.msg_atual = '' self.fim_de_jogo = False
def __init__(self, asteroids_amnt=DEFAULT_ASTEROIDS_NUM): ''' :param asteroids_amnt: Amount of asteroids on the screen This initializes our Game to get it started ''' self._screen = Screen() self.screen_max_x = Screen.SCREEN_MAX_X self.screen_max_y = Screen.SCREEN_MAX_Y self.screen_min_x = Screen.SCREEN_MIN_X self.screen_min_y = Screen.SCREEN_MIN_Y random_x_loc = random.randint(self.screen_min_x, self.screen_max_x) random_y_loc = random.randint(self.screen_min_y, self.screen_max_y) ship_location = random_x_loc, random_y_loc self._ship = Ship(ship_location, SHIP_LIFE) # Generates an object with Class type Ship self._score = 0 data_list = [ship_location] times = 0 self._asteroid_list = [] self._torpedo_list = [] while times < asteroids_amnt: # Generates objects with Class type Asteroid loc_asteroid_x = random.randint(self.screen_min_x, self.screen_max_x) loc_asteroid_y = random.randint(self.screen_min_y, self.screen_max_y) asteroid_location = loc_asteroid_x, loc_asteroid_y if asteroid_location not in data_list: data_list.append(asteroid_location) x_speed_asteroid = random.randint(1, INITIAL_MAX_SPEED) y_speed_asteroid = random.randint(1, INITIAL_MAX_SPEED) asteroid_speed = x_speed_asteroid, y_speed_asteroid temp_asteroid = Asteroid(asteroid_location, asteroid_speed, LIFE_ASTEROID) self._asteroid_list.append(temp_asteroid) self._screen.register_asteroid(self._asteroid_list[times], self._asteroid_list[times].get_life()) times += 1
def __init__(self, width, height): self.paddle = Paddle(width, height) self.screen = Screen(width, height) self.bricks = get_bricks(width, height, 1) self.final_boss = False self.ufo = None self.height = height self.width = width self.balls: [Ball] = [ Ball(max_width=width, max_height=height, x=width // 2, y=height // 2) ] self.ball_on_paddle = True self.powerups = [] self.score = 0 self.lives = 3 self.time = time.time() self.active_powerups: [PowerUp] = [] self.thru_ball = False self.grab_ball = False self.game_level = 1 self.time_attack = False self.pending_defense = False self.paddle_bullets: [Bullet] = [] os.system('clear')
def __init__(self, seed: int, log_filename: str): """ Initializes the game :param seed: :param log_filename: """ self.maps = [] self.default_entities = [] self.user_input = "" self.configurations = read_configuration_file() self.language = LanguageManagement(self.configurations.get("language_file")) self.options = OptionsMenu(self) mapname = get_level_file_name(self.language) self.read_units_dat() self.colours = Colours() self.player = self.set_entity("Player", -1, -1) self.maps.append(Map(mapname, self)) self.current_level = self.maps[0] self.rng = Random(seed) self.all_status_effects = status_effects.set_effect_values(status_effects.read_status_effects_dat(self)) self.brezelheim = Brezelheim(self.current_level) self.scr = Screen(self.configurations.get("screen_height"), self.configurations.get("screen_width")) self.msg_box = Messagebox(self.scr.len_x) self.keys = Input() # inits the input keys self.log_filename = log_filename self.log_file = None
def __init__(self, asteroids_amount): # Calls the screen and sets its borders self.__screen = Screen() self.__screen_max_x = Screen.SCREEN_MAX_X self.__screen_max_y = Screen.SCREEN_MAX_Y self.__screen_min_x = Screen.SCREEN_MIN_X self.__screen_min_y = Screen.SCREEN_MIN_Y # Randomizes coordinates for the ship in each of the axis random_x = random.randint(self.__screen_min_x, self.__screen_max_x) random_y = random.randint(self.__screen_min_y, self.__screen_max_y) self.__ship = Ship((random_x, random_y), (0, 0), 0) # Our ship self.__asteroid_list = [] # The list of asteroids the are in the game # Handles the initialization of the asteroids when the game starts for current_asteroid_i in range(asteroids_amount): location = random.randint(self.__screen_min_x, self.__screen_max_x), random.randint( self.__screen_min_x, self.__screen_max_x) velocity = random.choice(SPEED_RANGE), random.choice(SPEED_RANGE) asteroid = Asteroid(location, velocity, INITIAL_AS_SIZE) while asteroid.has_intersection(self.__ship): asteroid = Asteroid(location, velocity, INITIAL_AS_SIZE) self.__asteroid_list.append(asteroid) for asteroid in self.__asteroid_list: self.__screen.register_asteroid(asteroid, INITIAL_AS_SIZE) self.__torpedo_list = [] # The list which stores shouted torpedoes self.__points = 0 # stores the points of the player self.__screen.set_score(self.__points) # Register the intialized
def main(): pygame.init() screen = Screen(1200, 800, (255, 255, 255)) screen.display() jumpman = Jumpman(screen, 50, 200) pygame.display.update() block = Block(screen, 50, 50) jumpman_x = 50 jumpman_y = 200 score = Score(0, screen) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: if jumpman_y < 800 - jumpman.height(): jumpman_y = jumpman_y + 10 if event.key == pygame.K_UP: if jumpman_y > 0: jumpman_y = jumpman_y - 10 screen.screen.fill((255, 255, 255)) score.render() load_jumpman(screen, jumpman, jumpman_x, jumpman_y) handle_block(screen, block, score) pygame.display.update()
def __init__(self, screen=None, termenc="UTF-8", termprop=None, visibility=False, resized=True): """ >>> from screen import MockScreenWithCursor >>> screen = MockScreenWithCursor() >>> screen.getyx() (0, 0) >>> canossa = Canossa(screen=screen, resized=False) """ if screen: self.screen = screen else: import sys from screen import Screen # make screen # get current position result = _get_pos_and_size(sys.stdin, sys.stdout) if result: row, col, y, x = result self.screen = Screen(row, col, y, x, termenc, termprop) self._visibility = visibility self.__cpr = False self._resized = resized CSIHandlerTrait.__init__(self) ESCHandlerTrait.__init__(self)
def main(stdscr): stdscr.clear() stdscr.refresh() if params.filename: grid = Grid.load(params.filename, curses.COLS, curses.LINES) else: grid = Grid(curses.COLS, curses.LINES) engine = SimulationEngine() engine.set_grid(grid) screen = Screen(stdscr, grid) state = State("Edit mode", False, 0, 0, 0, 0) screen.draw(state) inp = get_input(stdscr) setup_test(grid) while inp != Input.QUIT: if inp == Input.SIMULATE: state.message = "Simulation" state.show_power = True stdscr.nodelay(True) inp = get_input(stdscr) while inp != Input.QUIT: engine.tick() screen.draw(state) sleep(.55) inp = get_input(stdscr) state.message = "Edit mode" state.show_power = False stdscr.nodelay(False) if inp == Input.UP: state.cursor_y -= 1 if inp == Input.DOWN: state.cursor_y += 1 if inp == Input.LEFT: state.cursor_x -= 1 if inp == Input.RIGHT: state.cursor_x += 1 new = None if inp == Input.BATTERY: new = Battery.build() elif inp == Input.VERTICAL_LINE: new = VerticalLine.build() elif inp == Input.HORIZONTAL_LINE: new = HorizontalLine.build() elif inp == Input.CROSS_LINE: new = CrossLine.build() elif inp == Input.NOT_PORT: new = NotPort.build() elif inp == Input.CLEAR: new = Empty.build() if new: grid.set(state.cursor_x, state.cursor_y, new) screen.draw(state) inp = get_input(stdscr)
def curses_begin(): global scr scr = Screen(curses.initscr(), curses.LINES, curses.COLS) curses.noecho() scr.win.keypad(1) curses.start_color() Colors.init_color_pairs()
def __parse_cmd(self, namespace) -> Level: screen = Screen(ScreenNumber(namespace.init_num), namespace.portal) # Parse buttons with specialized parser buttons = self.button_parser.parse(namespace.buttons) goal = ScreenNumber(namespace.goal) level = Level(screen, buttons, goal, namespace.max_moves) return level
def main(): rom_data = get_rom_data() width, height = 512, 256 screen = Screen(width, height) mem = Memory() cpu = CPU(mem) cpu.load_rom(rom_data) cycles = 0 while True: cpu.cycle() for event in pygame.event.get(): if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP: if event.key in cpu.k_map: chip_key = cpu.k_map[event.key] if event.type == pygame.KEYDOWN: cpu.keys_pressed[chip_key] = 1 elif event.type == pygame.KEYUP: cpu.keys_pressed[chip_key] = 0 elif event.type == pygame.QUIT: quit() if cpu.update_screen_flag == 1: screen.draw_frame(cpu) pygame.display.update() cycles += 1 if cycles == 10: time.sleep(10 / 1000) cycles = 0
def __init__(self, asteroids_amnt): """ A constructor for a gamerunner object :param asteroids_amnt = the amount of asteroids the game will start with. """ self._screen = Screen() self.screen_max_x = Screen.SCREEN_MAX_X self.screen_max_y = Screen.SCREEN_MAX_Y self.screen_min_x = Screen.SCREEN_MIN_X self.screen_min_y = Screen.SCREEN_MIN_Y self._ship = ship.Ship() self._screen.draw_ship(self._ship.x(), self._ship.y(), self._ship.get_direction()) self.asteroid_list = [] for i in range(asteroids_amnt): self.asteroid_list.append(asteroid.Asteroid(self._ship)) registered_asteroid_list = [] for an_asteroid in self.asteroid_list: self._screen.register_asteroid(an_asteroid, an_asteroid.size) self._screen.draw_asteroid(an_asteroid, an_asteroid.x(), an_asteroid.y()) self.torpedo_list = [] self.score = 0
def main(): s = Screen(fg='white', bg='black') s.cls('green') w = Window(s, 5, 5, 45, 30) w.cls() # for i in range(10): # print >>w, i w2 = Window(s, 66, 5, 120, 10) w2.cls() # for i in range(31): # print >>w, 'a' * i # time.sleep(0.4) # # print >>w, 'abcdefghi\njklmnopqrstuvwxyz' # print >>w, 'abcdefghijklmnopqrstuvwxyz' # print >>w, 'HI' print >> w, open(__file__).read() # print >>w2, 'world' # print >>w2, 'YO' s.gotoxy(s.left, s.bottom)
def __init__(self): self.model = Model() self.params = Params() self.screen = Screen() self.fzf = FzfPrompt() self.info = ''
def main(): args = sys.argv if not validate_command_line_args(args): return json_file_name = args[1] if len(args) == 2: generate_png = False png_file_name = None else: generate_png = True png_file_name = args[3] try: data_to_draw = JsonParser(json_file_name) except IOError as err: print(err) return palette = Palette(data_to_draw.get_palette()) screen = Screen(data_to_draw.get_screen()) figures = [] for figure in data_to_draw.get_figures(): try: figures.append(create_figure_obj(figure)) except Exception as err: print(err) canvas = PyGameCanvas(palette, screen, figures) canvas.run_pygame(generate_png, png_file_name) return
def start_emulation(rom_path, on_pixel_color, off_pixel_color, game_speed): pygame.init() off_pixel_color = off_pixel_color[0:3] on_pixel_color = on_pixel_color[0:3] screen = Screen(on_pixel_color, off_pixel_color, game_speed) chip8 = Chip8(rom_path, screen) emu_loop(chip8, screen)
def readScreen(): fil = open("out2.bin", "rb") msg = bytearray() msg.extend(fil.read()) fil.close() print "msg|%s|end" % str(msg) print "msg len: %d" % len(str(msg)) width = 0 height = 0 asciiPixels = [] curRow = [] #print msg[0] #print "len:%d" % len(str(msg[0])) height, width = struct.unpack("BB", str(msg[:2])) print "height: %d, width %d" % (height, width) for i in range(0, height): # height and width are counting in ASCII PIXELS not bytes for j in range(0, width): curPos = 2 * (i * width + j) + 2 # 2=size of header symbol, color = struct.unpack("BB", str(msg[curPos:(curPos + 2)])) asciiPixel = AsciiPixel(symbol, color) curRow.append(asciiPixel) asciiPixels.append(curRow) curRow = [] screen = Screen(asciiPixels) return screen
def __init__(self, arrmenu=[ "Menu:", "Ipconfig", "Set Date", "Set Mask", "set GateWay", ]): self.power = Power() self.screen = Screen() self.info = self.screen.get_info() self.keyboard = KeyBoard(5, 6, 26, 22) self.strmenu = arrmenu self.menu_index = 0 self.state = 'FIRSTPAGE' self.list_gateway = [] self.marker = 0 self.list_mask = [] self.list_addr = [] self.x = [] self.list_date = self.info[1] self.marker = 0 self.cmd1 = '' self.cmd2 = '' self.cmd3 = '' self.cmd4 = '' self.cmd5 = ''
def __init__(self, asteroids_amnt): self._screen = Screen() self.screen_max_x = Screen.SCREEN_MAX_X self.screen_max_y = Screen.SCREEN_MAX_Y self.screen_min_x = Screen.SCREEN_MIN_X self.screen_min_y = Screen.SCREEN_MIN_Y
def __init__(self, asteroids_amount): """ Constructor method, sets up all parameters needed before starting a game :param asteroids_amount: the amount of asteroid to start the game with :type asteroids_amount: int """ self.__screen = Screen() self.__screen_max_x = Screen.SCREEN_MAX_X self.__screen_max_y = Screen.SCREEN_MAX_Y self.__screen_min_x = Screen.SCREEN_MIN_X self.__screen_min_y = Screen.SCREEN_MIN_Y self.__screen_min = self.__screen_min_x, self.__screen_min_y self.__screen_max = self.__screen_max_x, self.__screen_max_x self.__screen_dimensions = self.__screen_min, self.__screen_max # initiate game objects self.__spaceship = self._create_ship() self.__asteroids = self._get_asteroids(asteroids_amount) self.__torpedos = list() # initiate game counters self.__score = 0 self.__lives = GameRunner.INIT_LIVES # first draws self._draw_ship() self._draw_asteroids() self._draw__torpedos()
def get_path(log, filename): """ Do not change this function """ # create a Screen Object that will contain all of the drawing commands screen = Screen(SCREEN_SIZE, SCREEN_SIZE) screen.background((255, 255, 0)) maze = Maze(screen, SCREEN_SIZE, SCREEN_SIZE, filename) path = solve_path(maze) log.write(f'Number of drawing commands for = {screen.get_command_count()}') done = False speed = 1 while not done: if screen.play_commands(speed): key = cv2.waitKey(0) if key == ord('+'): speed = max(0, speed - 1) elif key == ord('-'): speed += 1 elif key != ord('p'): done = True else: done = True return path
def __init__(self): self.screen = Screen(640, 320) self.input_handler = InputHandler(self.screen) self.cpu = Cpu(self.screen, self.input_handler) self.loop()