82 lines
1.6 KiB
Python
82 lines
1.6 KiB
Python
from locate2 import *
|
|
from levels import *
|
|
|
|
def move(sx, sy):
|
|
global c, n_o
|
|
tx = x + sx
|
|
ty = y + sy
|
|
dest = carte.get_cell(tx, ty)
|
|
if dest in "./":
|
|
return tx, ty
|
|
if dest in "+*":
|
|
bx = tx + sx
|
|
by = ty + sy
|
|
bDest = carte.get_cell(bx, by)
|
|
if bDest in "#*+":
|
|
return x, y
|
|
if dest == "+":
|
|
c == "."
|
|
carte.locate(tx, ty, ".")
|
|
else:
|
|
c == "/"
|
|
carte.locate(tx, ty, "/")
|
|
n_o += 1
|
|
if bDest == ".":
|
|
carte.locate(tx+sx, ty+sy, "+")
|
|
return tx, ty
|
|
if bDest == "/":
|
|
carte.locate(tx+sx, ty+sy, "*")
|
|
n_o -= 1
|
|
return tx, ty
|
|
return x, y
|
|
return x, y
|
|
|
|
|
|
def load(n):
|
|
global carte
|
|
w = lvl_dim[n][0]
|
|
h = lvl_dim[n][1]
|
|
carte = Pad(w, h)
|
|
carte.load(levels[n])
|
|
o = 0
|
|
for i in range(w * h):
|
|
c = levels[n][i]
|
|
if c == "@":
|
|
x = i % w + 1
|
|
y = i // w + 1
|
|
elif c == "/":
|
|
o += 1
|
|
return x, y, o
|
|
|
|
i = 0
|
|
buffer = str()
|
|
while 1:
|
|
i = int(input("Enter level ID :\n> "))
|
|
x, y, n_o = load(i)
|
|
while n_o:
|
|
c = carte.get_cell(x, y)
|
|
if c == "@":
|
|
c = "."
|
|
carte.locate(x, y, "@")
|
|
e = carte.refresh(x-10, y-2)
|
|
carte.locate(x, y, c)
|
|
if not e:
|
|
e = buffer
|
|
else:
|
|
e = e[-1]
|
|
buffer = e
|
|
#action switch
|
|
sx = 0
|
|
sy = 0
|
|
if e == "4":
|
|
sx = -1
|
|
elif e == "8":
|
|
sy = -1
|
|
elif e == "6":
|
|
sx = 1
|
|
elif e in "25":
|
|
sy = 1
|
|
elif e == "0":
|
|
buffer == ""
|
|
x, y, n_o = load(i)
|
|
x, y = move(sx, sy) |