Sokoban for Casio MicroPython.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sokoban.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from locate2 import *
  2. from levels import *
  3. def move(sx, sy):
  4. global c, n_o
  5. tx = x + sx
  6. ty = y + sy
  7. dest = carte.get_cell(tx, ty)
  8. if dest in "./":
  9. return tx, ty
  10. if dest in "+*":
  11. bx = tx + sx
  12. by = ty + sy
  13. bDest = carte.get_cell(bx, by)
  14. if bDest in "#*+":
  15. return x, y
  16. if dest == "+":
  17. c == "."
  18. carte.locate(tx, ty, ".")
  19. else:
  20. c == "/"
  21. carte.locate(tx, ty, "/")
  22. n_o += 1
  23. if bDest == ".":
  24. carte.locate(tx+sx, ty+sy, "+")
  25. return tx, ty
  26. if bDest == "/":
  27. carte.locate(tx+sx, ty+sy, "*")
  28. n_o -= 1
  29. return tx, ty
  30. return x, y
  31. return x, y
  32. def load(n):
  33. global carte
  34. w = lvl_dim[n][0]
  35. h = lvl_dim[n][1]
  36. carte = Pad(w, h)
  37. carte.load(levels[n])
  38. o = 0
  39. for i in range(w * h):
  40. c = levels[n][i]
  41. if c == "@":
  42. x = i % w + 1
  43. y = i // w + 1
  44. elif c == "/":
  45. o += 1
  46. return x, y, o
  47. i = 0
  48. buffer = str()
  49. while 1:
  50. i = int(input("Enter level ID :\n> "))
  51. x, y, n_o = load(i)
  52. while n_o:
  53. c = carte.get_cell(x, y)
  54. if c == "@":
  55. c = "."
  56. carte.locate(x, y, "@")
  57. e = carte.refresh(x-10, y-2)
  58. carte.locate(x, y, c)
  59. if not e:
  60. e = buffer
  61. else:
  62. e = e[-1]
  63. buffer = e
  64. #action switch
  65. sx = 0
  66. sy = 0
  67. if e == "4":
  68. sx = -1
  69. elif e == "8":
  70. sy = -1
  71. elif e == "6":
  72. sx = 1
  73. elif e in "25":
  74. sy = 1
  75. elif e == "0":
  76. buffer == ""
  77. x, y, n_o = load(i)
  78. x, y = move(sx, sy)