def webhook_handler(): signature = request.headers["X-Line-Signature"] # get request body as text body = request.get_data(as_text=True) app.logger.info(f"Request body: {body}") # parse webhook body try: events = parser.parse(body, signature) except InvalidSignatureError: abort(400) # if event is MessageEvent and message is TextMessage, then echo text for event in events: if not isinstance(event, MessageEvent): continue if not isinstance(event.message, TextMessage): continue if not isinstance(event.message.text, str): continue print(f"\nFSM STATE: {machine.state}") print(f"REQUEST BODY: \n{body}") response = machine.advance(event) if response == False: #send_text_message(event.reply_token, "Not Entering any State") reply_token = event.reply_token button(reply_token) return "OK"
def intro(self, training, testing): pygame.display.set_caption('Grab the coin!') pygame.init() display_width, display_height = 432, 432 game_display = pygame.display.set_mode((display_width, display_height)) fpsClock = pygame.time.Clock() intro = True while intro: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() width = game_display.get_width() height = game_display.get_height() land_image = pygame.image.load('static/land.png') land_image = pygame.transform.scale(land_image, (width // 6, height // 6)) land_rect = land_image.get_rect() for i in np.linspace(0, width, num=7): for j in np.linspace(0, height, num=7): land_rect.topleft = (i, j) game_display.blit(land_image, land_rect) gameOverFont = pygame.font.Font('arcade.ttf', 36) gameOverSurf, gameOverRect = text_object( 'Grab The Coin!', gameOverFont, pygame.Color(120, 120, 120)) gameOverRect.midtop = (width // 2, height // 2 - 120) game_display.blit(gameOverSurf, gameOverRect) player_sprite = AnimatedHero(game_display.get_width() // 2, game_display.get_height() // 2 - 20, hero_type='idle') player_sprite.update() player_sprite.draw(game_display) button(game_display, 'train', width // 8, height // 8 * 7, width // 6, height // 8, pygame.Color(120, 120, 120), pygame.Color(150, 150, 150), training) button(game_display, 'test', width // 4 * 3, height // 8 * 7, width // 6, height // 8, pygame.Color(120, 120, 120), pygame.Color(150, 150, 150), testing) pygame.display.update()
def game_intro(self): intro = True while intro: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() self.playSurface.fill(blackColour) textFont = pygame.font.Font('arial.ttf', 73) textSurf, textRect = text_object('AI Snake', textFont, greyColour) textRect.center = (self.display_width//2, self.display_height//2) self.playSurface.blit(textSurf, textRect) button(self.playSurface,'GO!', self.display_width//4, self.display_height//8*7, self.display_width//4, self.display_height//8, greenColour, brightGreenColour, run) button(self.playSurface, 'AI', display_width//2, self.display_height//8*7, display_width//4, self.display_height//8, redColour, brightRedColour, self.AI_option) pygame.display.update()
def gameOver(self, score): # Set fonts of caption gameOverFont = pygame.font.Font('arial.ttf', 72) gameOverSurf, gameOverRect = text_object('Game Over', gameOverFont, greyColour) gameOverRect.midtop = (320, 125) self.playSurface.blit(gameOverSurf, gameOverRect) # Display scores and set fonts scoreFont = pygame.font.Font('arial.ttf', 48) scoreSurf, scoreRect = text_object('SCORE:'+str(score), scoreFont, greyColour) scoreRect = scoreSurf.get_rect() scoreRect.midtop = (320, 225) self.playSurface.blit(scoreSurf, scoreRect) #pygame.display.update() # Refresh display button(self.playSurface, 'Again', self.display_width//4, self.display_height//8*7, self.display_width//2, self.display_height//8, greenColour, brightGreenColour, self.init_game) # https://stackoverflow.com/questions/55881619/sleep-doesnt-work-where-it-is-desired-to/55882173#55882173 pygame.display.update()
screen.fill((0, 0, 0)) #drawing split line from playing screen and buttons for i in range(int(SCREEN_SIZE / 5)): pygame.draw.rect(screen, (255, 200, 100), (i * 10, SCREEN_SIZE + 15, 5, 5)) pygame.display.update() objectsRect = [] clickedObj = [] AMOUNT = 100 SolveButton = utils.button((0, 255, 0), 10, SCREEN_SIZE + 25, 120, 50, 'Solve', estate=0) SolveButton.draw(screen, (0, 0, 0)) # SolveButtonEstate = 0 GuessButton = utils.button((100, 50, 100), 170, SCREEN_SIZE + 25, 120, 50, 'Guess', estate=0) GuessButton.draw(screen, (0, 0, 0)) # GuessButtonEstate = 0
ROWS = GRID.get_height() // CELL COLUMNS = GRID.get_width() // CELL ARRAY = [[utils.random_color() for i in range(COLUMNS)] for j in range(ROWS)] # drone constants X = (COLUMNS // 2) * CELL + PANEL.get_width() + COLUMN_MARGIN + WINDOW_MARGIN Y = (ROWS // 2) * CELL + ROW_MARGIN + WINDOW_MARGIN DRONE1 = drone.Drone() RUN = True greenbutton = utils.button((0, 200, 0), int(PANEL.get_width() // 5), 50, int(PANEL.get_width() // 2), int(PANEL.get_width() // 5), 'test') def redrawWindow(): pygame.draw.circle(WINDOW, DRONE1.color, (X, Y), DRONE1.radius) greenbutton.draw(WINDOW, (0, 0, 0)) grid = [] for row in range(ROWS): grid.append([]) for column in range(COLUMNS): grid[row].append(0) while RUN:
white_turn = not white_turn # The turn passes to the other player player_turn = not player_turn # The turn passes to the AI victory = ai.check_victory( grid) # Check if the game has ended if gameState == "title": ut.display_text("tictAItoe", largeFont, (0, 0, 255), width // 2, height // 4, screen) if aiType == "nn": if modelTrained: ut.button("play against the AI", center_rect(width // 2 + 150, height // 2 - 60, 175, 50), (0, 195, 255), (18, 206, 255), white, screen, mouse, action=update_game_state, arg="aiGame") ut.button("plot training results", center_rect(width // 2 + 150, height // 2 + 120, 175, 50), (120, 0, 255), (140, 40, 255), white, screen, mouse, action=nn.plot_training, arg=modelHistory) else: ut.display_text(
#Loading background image background = pygame.image.load("Background.png") background = pygame.transform.scale(background, (SCREENWIDTH, SCREENHEIGHT)) #create starting screen start_screen = pygame.Surface(screen.get_size()) start_screen.fill((150, 150, 150)) #display start screen text font = pygame.font.SysFont("MatisseITC", 36) text = font.render("Diamond in the Ruff", 1, (10, 10, 10)) text_position = text.get_rect() text_position.centerx = start_screen.get_rect().centerx start_screen.blit(background, (0, 0)) start_screen.blit(text, text_position) #load button images and character portraits start_button = button("bone1.png") quit_button = button("bone2.png") #creating button objects by specifying its pygame.Rect object start_img_position = pygame.Rect( (start_screen.get_rect().x, (text_position.y + 100)), (start_button.button_image.get_size())) start_img_position.centerx = start_screen.get_rect( ).centerx #center the button relatively to screen start_button.set_button_text("START", 16) start_button.draw(start_screen, start_img_position) quit_img_position = pygame.Rect( (start_screen.get_rect().x, (start_img_position.y + 300)),
if len(containers[pos+1])==0 or (containers[pos+1][-1].get_size() > containers[selected+1][-1].get_size()): containers[pos+1].append(containers[selected+1].pop()) # creating instances of box class and allocating values. def allocate(): containers[1].clear() for i in range(n): containers[1].append(box(win,(10*i),space)) def Reset(): containers[1].clear() containers[2].clear() containers[3].clear() reset=button(win,"RESET",20,(255,255,255),50,0) solve=button(win,"SOLVE",20,(255,255,255),150,0) decrement=button(win,"<<",20,(255,255,255),250,0) increment=button(win,">>",20,(255,255,255),300,0) allocate() run=True while run: mouse_pos=pygame.mouse.get_pos() for event in pygame.event.get(): if event.type == pygame.QUIT: run=False