# Write new score to file with open(high_scores_path, "w+") as file: # 'w+' enables overwriting file.write(str(score)) time.sleep(3) # Main game loop while True: # Check if player is out of boundss if snake.is_oob(): lose() break # Check if food was hit if snake.head_distance_from(food.turt) < 20: # Put the food somewhere else food.place_random() # Extend body new_segment = snake.make_new_segment(color=color_list[color_index]) snake.add_new_segment(new_segment) # Update color index color_index = (color_index + 1) % len(color_list) # Update score counter score += 10 # If score hits a multiple of 50, increase the speed if score % 50 == 0: game.delay = max(game.delay - 0.015, 0) # Move all but first segments in reverse order
fruit | Add to score | Place fruit somewhere else ----------------------------------------------- Player hits a | Lose game body segment | ----------------------------------------------- Always | Update snake's head and | body positions | Write score to screen ''' # Main game loop while True: '''Step 3: TODO see if player has gone of out bounds, lose game if so''' ''' Step 4: TODO Fill in actions for when food is hit ''' if snake.head_distance_from(food.turt) < 20: print(end='') # Delete this line # TODO Put the food somewhere else by getting # and setting a new position in the game window # TODO Extend snake body by making a new segment, then # adding it to the snake # TODO Update score counter ''' Step 5: TODO update the positions of all the snake body segments (not the head) This part is tough! Ask for help if you need it! What should x and y be?