Guest User

Untitled

a guest
Nov 29th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. import random, time, os, msvcrt, sys
  2.  
  3. def clear():
  4.         os.system("cls")
  5.  
  6. inp = 0
  7.  
  8. y = 2
  9. x = 2
  10. foody = random.randint(0, 9)
  11. foodx = random.randint(0, 9)
  12. lengh = 3
  13.  
  14. mapa = [[[0] * 10] * 10]
  15. print(mapa)
  16.  
  17. while True:
  18.         time.sleep(1)
  19.         clear()
  20.  
  21.         for i in range(10):
  22.                 for j in range(10):
  23.                         if mapa[i][j] > 0:
  24.                                 mapa[i][j] -= 1
  25.  
  26.                         if i == y and j == x:
  27.                                 mapa[i][j] = lengh
  28.  
  29.                         if i == foody and j == foodx:
  30.                                 mapa[i][j] = -1
  31.  
  32.                         if i == foody and x == foodx:
  33.                                 mapa[i][j] = lengh
  34.                                 foody = random.randint(0, 9)
  35.                                 foodx = random.randint(0, 9)
  36.                                 lengh += 1
  37.  
  38.                         print("{:^2}".format(mapa[i][j]), end = "")
  39.                 print()
  40.  
  41.         try:
  42.                 inp = msvcrt.getch()
  43.         except:
  44.                 pass
  45.  
  46.         if inp == b'd':
  47.                 x += 1
  48.         if inp == b'a':
  49.                 x -= 1
  50.         if inp == b's':
  51.                 y += 1
  52.         if inp == b'w':
  53.                 y -= 1
  54.         if inp == b'q':
  55.                 clear()
  56.                 print('your score: ', lengh)
  57.  
  58.                 sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment