Advertisement
Guest User

moving letters

a guest
Aug 9th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. from random import randint
  2. from copy import deepcopy
  3. grid=[[' ' for _ in range(10)] for _ in range(10)]
  4. letters='qwertyuiopasdfghjklzxcvbnm'
  5. posx,posy=0,0
  6. done=1
  7. def displaygrid():
  8. for row in grid:
  9. print('\n+--+--+--+--+--+--+--+--+--+--+\n|',end='')
  10. for col in row:
  11. print(col,end=' |')
  12. print('\n+--+--+--+--+--+--+--+--+--+--+')
  13. while done:
  14. displaygrid()
  15. grid[posy][posx]=letters[randint(0,25)]
  16. randlist=[]
  17. if posy!=0 and grid[posy-1][posx]==' ':
  18. randlist+=[0]
  19. if posx!=9 and grid[posy][posx+1]==' ':
  20. randlist+=[1]
  21. if posy!=9 and grid[posy+1][posx]==' ':
  22. randlist+=[2]
  23. if posx!=0 and grid[posy][posx-1]==' ':
  24. randlist+=[3]
  25. if not randlist:
  26. done=0
  27. else:
  28. direction=randlist[randint(0,len(randlist)-1)]
  29. if direction==0:
  30. posy-=1
  31. elif direction==1:
  32. posx+=1
  33. elif direction==2:
  34. posy+=1
  35. else:
  36. posx-=1
  37. displaygrid()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement