Advertisement
Hugo_2000

8.functions

Jun 27th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. # Move your character
  2.  
  3. #functions
  4. #---------------------------------
  5. def printField(x,y):
  6.  
  7.     countY = 0;
  8.     while countY <= 10:
  9.         countX = 0;
  10.         while countX <= 10:
  11.             if countX == x and countY == y:
  12.                 print("x", end=' ');
  13.             else:
  14.                 print("#", end=' ');
  15.             countX = countX + 1;
  16.         print()
  17.         countY = countY + 1;
  18.  
  19. def clearScreen():
  20.     count = 0
  21.     while count < 21:
  22.         print();
  23.         count = count + 1;
  24. #---------------------------------
  25.  
  26. #Main
  27. #yfield 0-10
  28. #xfield 0-10
  29. x = 5;
  30. y = 5;
  31. printField(x,y);
  32.  
  33. while x >= 0 and x <= 10 and y >= 0 and y <= 10:
  34.     print("Insert a command");
  35.     command = input("(up, down, left or right): ");
  36.  
  37.     # adds enough empty lines to clear the screan
  38.     clearScreen();
  39.  
  40.     #changes the coordinates of the x
  41.     if command == "up":
  42.         y = y - 1;
  43.     elif command == "down":
  44.         y = y + 1;
  45.     elif command == "left":
  46.         x = x - 1;
  47.     elif command == "right":
  48.         x = x + 1;
  49.     else:
  50.         print("Insert a valid command");
  51.     printField(x,y);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement