def __init__(self): self.b_buy_node = Button("Buy Place") self.b_build_detector = Button("Build Detector") self.b_next_turn = Button("Next Round") self.b_buy_node.setEnabled(False) self.b_build_detector.setEnabled(False) self.b_next_turn.setEnabled(False)
def toolkit_section(self): title = tk.Frame(self.toolkit) title.grid(row=0, column=0, columnspan=2, pady=10) Label( title, text="PATH-FINDER", size=24 ).pack(fill=tk.X) Label( self.toolkit, text="Maze Generation", size=14 ).grid(row=1, column=0, padx=10, pady=10, sticky='W') Button( self.toolkit, text="Generate Maze", command=lambda: self.grid.generate_maze( self.visualize_maze.get(), self.perfect_maze.get() + 1 ) ).grid(row=2, column=0, padx=10, pady=5, sticky='WE') Checkbutton( self.toolkit, variable=self.visualize_maze, text="Visualize", ).grid(row=2, column=1, padx=10, pady=5, sticky='W') Button( self.toolkit, text="Clear Maze", command=self.grid.reset ).grid(row=3, column=0, padx=10,pady=5, sticky='WE') Checkbutton( self.toolkit, text="Perfect Maze\n(Only 1 soultion)", variable=self.perfect_maze, ).grid(row=3, column=1, padx=10, pady=5, sticky='W') Label( self.toolkit, text="Path Finding", size=14 ).grid(row=5, column=0, padx=10, pady=10, sticky='W') Button( self.toolkit, text="Find Path", command=lambda: a_star(self.grid), ).grid(row=6, column=0, columnspan=2, padx=10,pady=5, sticky='WE')
def __init__(self): self.identif = 0 #false self.pause_cond = Condition() self.buttonV = Button.Button(3) self.buttonD = Button.Button(4) self.paused = False self.step = 0 self.choice = False #permet de savoir si l'utilisateur a choisi de poser (True) ou de prendre (False) self.categorie = 0 #numero de categorie self.id = 0 #id de l'aliment self.qte = 0 #quantite choisie par l'utilisateur self.stepdate = 1 #etape de la conception de la date de peremption (1 : jour, 2 : date, 3: annee) self.j = "1" #jour par defaut self.m = "01" #mois par defaut self.a = "2020" #annee par defaut
def __init__(self): """ 游戏初始化 """ pygame.init() self.screen = pygame.display.set_mode(WIN_SIZE) pygame.display.set_caption("飞机大战") self.img_bg = pygame.image.load(IMG_BG) self.hero = Hero(self.screen) self.enemies = self.get_enemies(5) self.result = Result() self.btn_enter = [Button(BTN_ENTER1), Button(BTN_ENTER2)] self.font = pygame.font.Font(FONT, 45)
def target_search(self, event): SIZE = min(self.surface.get_size()) path = 'images/target_search.png' icon_position = ((4*self.size[0]/10)-50, 35) button = Button(self.surface, icon_position, (SIZE, SIZE), path,str('target_search')) button.event_handler(self.position, icon_position, event) if button.pressed: action = str('target_search') self.ex.Primative(action) answer = inputbox.ask(self.screen, "Number of Drones")
def __init__(self, screen: pygame.Surface, score: int): self.running = True self.bg = (0, 130, 0) self.screen_w = screen.get_width() self.screen_h = screen.get_height() # Buttons self.btn_w = 120 self.btn_h = 50 self.btn_ds_x = (self.screen_w - self.btn_w) // 3.3 self.btn_s_x = (self.screen_w - self.btn_w) // 1.4 self.btn_y = (self.screen_h - self.btn_h) // 2 self.btn_dont_save = Button(self.btn_ds_x, self.btn_y, self.btn_w, self.btn_h, (200, 0, 0), (255, 0, 0), "Don't Save", self.close_hiscore) self.btn_save = Button(self.btn_s_x, self.btn_y, self.btn_w, self.btn_h, (0, 0, 200), (0, 0, 255), 'Save', self.close_hiscore) self.buttons = (self.btn_dont_save, self.btn_save) # Input Field self.field_w = 150 self.field_h = 50 self.field_x = (self.screen_w - self.field_w) // 2 self.field_y = (self.screen_h - self.field_h) // 3 self.initials_field = Input_Field(self.field_x, self.field_y, self.field_w, self.field_h, (255, 255, 255), (200, 200, 200)) # Score Text self.score = score self.score_text = Text(self.screen_w // 3, self.screen_h // 1.7, 22, f'Your score is {self.score}!') # Initials Text self.initials_text = Text(self.screen_w // 5, self.screen_h // 4.2, 18, 'Enter your initials to save your score') self.drawables = (self.btn_dont_save, self.btn_save, self.initials_field, self.score_text, self.initials_text)
def formation(self, event): SIZE = min(self.surface.get_size()) path = 'images/formation.png' icon_position = ((3*self.size[0]/10) - 50, 35) button = Button(self.surface, icon_position, (SIZE, SIZE), path,str('formation')) button.event_handler(self.position, icon_position, event) if button.pressed: answer = inputbox.ask(self.screen, "Number of Drones") action = str('formation') self.ex.Primative(action) #print(pygame.mouse.get_pos()) button.indication(self.surface, self.position, icon_position)
def __init__(self, players, window, playerChar=Char.EMPTY): self.__buttons = [[[], [], []], [[], []]] self.__buttons[0][0] = Button("Person", gameConfig['width'] * 0.06, gameConfig['height'] * 0.4, (255, 128, 0), 30, gameConfig['width'] * 0.25, 60) self.__buttons[0][1] = Button("Random Bot", gameConfig['width'] * 0.37, gameConfig['height'] * 0.4, (128, 0, 128), 30, gameConfig['width'] * 0.25, 60) self.__buttons[0][2] = Button("Smart Bot", gameConfig['width'] * 0.68, gameConfig['height'] * 0.4, (128, 128, 128), 30, gameConfig['width'] * 0.25, 60) self.__buttons[1][0] = Button("X", gameConfig['width'] * 0.2, gameConfig['height'] * 0.6, fontsConfig['xColor'], 50, 150, 100) self.__buttons[1][1] = Button("O", gameConfig['width'] * 0.6, gameConfig['height'] * 0.6, fontsConfig['oColor'], 50, 150, 100) self.__finishButton = Button("Continue", gameConfig['width'] * 0.7, gameConfig['height'] * 0.9, (0, 100, 0), 20, gameConfig['width'] * 0.25, 40) self.__nameRect = pygame.Rect(gameConfig['width'] * 0.25, gameConfig['height'] * 0.25, gameConfig['width'] * 0.5, 32) self.__id = 1 self.__playerName = "" self.__playerChar = playerChar self.__players = players self.__running = True self.__window = window
class ShooterConfig(object): motors = wpilib.Jaguar(3) shoot_button = Button(rightJoy, 1) manual_reset_button = Button(rightJoy, 4) low_shot_preset_button = Button(rightJoy, 8) high_shot_preset_button = Button(rightJoy, 7) reset_hall_effect = HallEffect(wpilib.DigitalInput(6)) preset_hall_effect_counters = [] low_shot_hall_effect_counter = wpilib.Counter() low_shot_hall_effect_counter.SetUpSource(7) low_shot_hall_effect_counter.SetUpSourceEdge(False, True) low_shot_hall_effect_counter.Start() high_shot_hall_effect_counter = wpilib.Counter() high_shot_hall_effect_counter.SetUpSource(8) high_shot_hall_effect_counter.SetUpSourceEdge(False, True) high_shot_hall_effect_counter.Start()
def menu_page(self): bg = pg.image.load('./assets/bg.jpg') bg = pg.transform.scale(bg, (self.win_width, self.win_height)) new_game_button = Button('NEW GAME', (100, 150, 250, 50), self.game_page) new_game_button.config(hover=(25, 25, 25)) play_online_button = Button('PLAY ONLINE', (100, 225, 250, 50), lambda: self.game_page(online=True)) play_online_button.config(hover=(25, 25, 25)) quit_game_button = Button('QUIT', (100, 300, 250, 50), self.quit) quit_game_button.config(hover=(25, 25, 25)) while True: self.win.blit(bg, (0, 0)) new_game_button.draw(self.win) play_online_button.draw(self.win) quit_game_button.draw(self.win) for event in pg.event.get(): if event.type == pg.QUIT: self.quit() if event.type == pg.MOUSEBUTTONDOWN: new_game_button.collide(event.pos) play_online_button.collide(event.pos) quit_game_button.collide(event.pos) mouse = pg.mouse.get_pos() new_game_button.mouseover(self.win, mouse) play_online_button.mouseover(self.win, mouse) quit_game_button.mouseover(self.win, mouse) pg.display.update()
class DriveConfig(object): left_motors = wpilib.Talon(1) right_motors = wpilib.Talon(2) left_encoder = wpilib.Encoder(2, 3) left_PID_encoder = DistanceEncoder(left_encoder) left_PID_controller = wpilib.PIDController(0, 0, 0, left_PID_encoder, left_motors) right_encoder = wpilib.Encoder(4, 5) right_PID_encoder = DistanceEncoder(right_encoder) right_PID_controller = wpilib.PIDController(0, 0, 0, right_PID_encoder, right_motors) robot_drive = DriveBase(left_motors, right_motors, True, left_encoder, right_encoder, left_PID_controller, right_PID_controller) #robot_drive = wpilib.RobotDrive(left_motors, right_motors) left_shifter = wpilib.DoubleSolenoid(1, 2) right_shifter = wpilib.DoubleSolenoid(3, 4) forward = wpilib.DoubleSolenoid.kForward reverse = wpilib.DoubleSolenoid.kReverse drive_joy = leftJoy align_button = Button(leftJoy, 6) front_left_photo_switch = wpilib.DigitalInput(14) front_right_photo_switch = wpilib.DigitalInput(12) back_left_photo_switch = wpilib.DigitalInput(13) back_right_photo_switch = wpilib.DigitalInput(11) # Buttons squared_drive_stick = Button(leftJoy, 1) shift_button = Button(leftJoy, 9)
def moveToPlayer2(self): self.__id = 2 for i in range(0, 3): self.__buttons[0][i].setIsClicked(False) self.__finishButton = Button("Start Game", gameConfig['width'] * 0.7, gameConfig['height'] * 0.9, (0, 100, 0), 20, gameConfig['width'] * 0.25, 40) self.__playerName = "" if self.__playerChar == Char.X: self.__playerChar = Char.O else: self.__playerChar = Char.X
def __init__(self, state): level = getattr(world1, f"Level_{state['level'] + 1}") self.state = state self.player = Player(position=Vector(*level.player)) self.platforms = Group() self.gems = Group() level_width = PS.PPU * ( max(map(lambda p: p[0] + p[2], level.platforms)) + PS.BLOB_SIZE) self.blobs = HorizontalScrollingGroup( self.player, (GS.SCREEN_WIDTH, GS.SCREEN_HEIGHT), (level_width, GS.SCREEN_HEIGHT), PS.SCROLL_MARGIN * PS.PPU) for x, y, width in level.platforms: platform = Platform(width=width, position=Vector(x, y)) self.blobs.add(platform) self.platforms.add(platform) for x, y, note, winner in level.gems: gem = Gem(note, winner=winner, position=Vector(x, y)) self.blobs.add(gem) self.gems.add(gem) if winner: goal_path = os.path.join("sounds", "long", f"{note}.wav") self.goal_sound = pygame.mixer.Sound(goal_path) self.channels = {} self.greeting = TextBox( "Your task is to find the gem which emits a certain sound.\nYou " "can listen to the sound by clicking on this box. You can also " "listen to it during the game by clicking on the \"Goal\" button " "in the corner.\nClick outside the box to start.", bgcolor=PS.TEXT_BGCOLOR, max_size=(GS.SCREEN_WIDTH * 0.6, GS.SCREEN_HEIGHT * 0.6), style=PS.TEXT_STYLE) self.started = False self.sound_btn = Button("Target sound", Vector(50, 50), Vector(10, 5))
class PickupConfig(object): pickup_motor = wpilib.Talon(4) solenoid = wpilib.DoubleSolenoid(5, 6) # TODO: figure out if forward is pickup-up or pickup-down. # Rename these variables once we know forward = wpilib.DoubleSolenoid.kForward reverse = wpilib.DoubleSolenoid.kReverse pickup_switch = Button(rightJoy, 3) motor_button = Button(rightJoy, 2) pickup_fast_preset = Button(rightJoy, 10) pickup_slow_preset = Button(rightJoy, 11) pass_slow_preset = Button(rightJoy, 12) pass_fast_preset = Button(rightJoy, 13)
quit() def redraw_screen(self): self.screen.fill(self.bg) for button in self.buttons: button.draw(self.screen) pygame.display.update() if __name__ == '__main__': game = Game() button_w = 100 button_h = 50 game.buttons.append( Button((game.screen_w - button_w) // 2, (game.screen_h - button_h) // 3, button_w, button_h, (200, 0, 0), (255, 0, 0), 'Play', run_game, game.screen)) game.buttons.append( Button((game.screen_w - button_w) // 2, (game.screen_h - button_h) // 1.5, button_w, button_h, (200, 0, 0), (255, 0, 0), 'Quit', game.quit_game)) # Temp game.buttons.append( Button((game.screen_w - button_w) // 2, (game.screen_h - button_h) // 2, button_w, button_h, (200, 0, 0), (255, 0, 0), 'Hiscores', run_hiscore, game.screen, 0)) while game.running: playing = True while playing:
class UtilConfig(object): reload_code_button = Button(leftJoy, 8) compressor = wpilib.Compressor(1, 1)