SHARE
TWEET

Untitled

ShchMax Oct 21st, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Yveega
  2.  
  3. def show(a, win):
  4.     global x, y
  5.     print('_' * 13)
  6.     for i in a:
  7.         for j in i:
  8.             if j == 16 and not win:
  9.                 print("|  ", end='')
  10.             else:
  11.                 print("|", j, ' ' * (1 - j // 10), sep='', end='')
  12.         print('|')
  13.         print('_' * 13)
  14.  
  15. # Den
  16. def checker():
  17.     global a, x, y
  18.     for i in range(3):
  19.         for g in range(3):
  20.             if a[i][g] == 16 :
  21.                 x, y = i, g
  22.     for i in range(3):
  23.         for g in range(3):
  24.             if a[i][g] != (i*4)+g+1 :
  25.                 return False
  26.     return True
  27.  
  28. # Vlad
  29. from random import randint
  30.  
  31. a = [list([0] * 4) for i in range(4)]
  32. for i in range(4):
  33.     for j in range(4):
  34.         a[i][j] = i * 4 + (j + 1)
  35.  
  36. def swap(xS, yS, xE, yE):
  37.     t = a[xS][yS]
  38.     a[xS][yS] = a[xE][yE]
  39.     a[xE][yE] = t
  40.  
  41. def shuf():
  42.     cX = 3
  43.     cY = 3
  44.     for i in range(200):
  45.         mX = randint(-1,1)
  46.         mY = randint(-1,1)
  47.                  
  48.         if cX >= 3:
  49.             mX = randint(-1,0)
  50.         if cX <= 0:
  51.             mX = randint(0, 1)
  52.  
  53.        
  54.         if cY >= 3:
  55.             mY = randint(-1, 0)
  56.         if cY <= 0:
  57.             mY = randint(0, 1)
  58.        
  59.         swap(cX + mX, cY + mY, cX, cY)
  60.         cX += mX
  61.         cY += mY
  62.  
  63. shuf()
  64.  
  65. # ShchMax
  66.  
  67. def MoveRight():
  68.     global x, y, win, a
  69.     if (not win):
  70.         if (x == 3):
  71.             return
  72.         else:
  73.             a[x + 1][y], a[x][y] = a[x][y], a[x + 1][y]
  74.             x += 1
  75.             if (checker()):
  76.                 win = True
  77.             show(a, win)
  78.  
  79. def MoveLeft():
  80.     global x, y, win, a
  81.     if (not win):
  82.         if (x == 0):
  83.             return
  84.         else:
  85.             a[x - 1][y], a[x][y] = a[x][y], a[x - 1][y]
  86.             x -= 1
  87.             if (checker()):
  88.                 win = True
  89.             show(a, win)
  90.  
  91. def MoveDown():
  92.     global x, y, win, a
  93.     if (not win):
  94.         if (y == 3):
  95.             return
  96.         else:
  97.             a[x][y + 1], a[x][y] = a[x][y], a[x][y + 1]
  98.             y += 1
  99.             if (checker()):
  100.                 win = True
  101.             show(a, win)
  102.  
  103. def MoveUp():
  104.     global x, y, win, a
  105.     if (not win):
  106.         if (y == 0):
  107.             return
  108.         else:
  109.             a[x][y - 1], a[x][y] = a[x][y], a[x][y - 1]
  110.             y -= 1
  111.             if (checker()):
  112.                 win = True
  113.             show(a, win)
  114.  
  115. # Game
  116. win = False
  117. x, y = 0, 0
  118. checker()
  119. show(a, False)
  120. while (not win):
  121.     b = input()
  122.     if (b == "w" or b == "W"):
  123.         MoveLeft()
  124.     elif (b == "a" or b == "A"):
  125.         MoveUp()
  126.     elif (b == "s" or b == "S"):
  127.         MoveRight()
  128.     elif (b == "d" or b == "D"):
  129.         MoveDown()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top