0

I am working on a bot, I am working on the db. But I ran into an issue which is providing a space into the file, whenever I do "[bot-prefix]new_file testfile This has spaces in it," it'll only write "This," does anyone have a solution for my issue? (ignore the below comments I had to edit this message for posting privelages, I honestly do wish StackOverflow understood different devs has different styles of programming and that a different question won't always help.)

Here is my code for it:

async def new_file(ctx, filename: str, data: str):
    newfile = open(f'{filename}.txt',"a+")
    newfile.write(data)
    newfile.close()```

1 Answers1

1

You should think of your snake as a list of segments, the first one being the head and the last one being the tail.

initialSize = 3
snake = [(240,240)] * InitialSize

To draw the snake, loop over the list and draw each segment independently.

for segX,segY in snake:
    pygame.draw.rect(screen, (0, 210, 0), ((segX, segY), (15, 15)))

To increase the size of the snake, add a segment to the list by copying the last one:

snake += snake[-1:]

To make the snake move, shift the segment position by one in the list, then assign the new head position to the first element of the list:

snake[1:] = snake[:-1]
snake[0]  = (snakehX,snakehY)
Alain T.
  • 40,517
  • 4
  • 31
  • 51
  • Alright, I will try this, but what does initial size do? –  Aug 28 '21 at 02:09
  • 1
    If you want your snake to start out with a length of 3 segments (for example). You can start with 1 if your snake begins as a single square. – Alain T. Aug 28 '21 at 02:11
  • How come m y answer ended up on a completely unrelated question (this was originally about making a snake longer in a game) ? – Alain T. Aug 29 '21 at 14:26