summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Roversi <diegor@tiscali.it>2020-05-23 09:58:05 +0200
committerDiego Roversi <diegor@tiscali.it>2020-05-23 09:58:05 +0200
commit81c86067960952f0ec87a035ce060da584e05df3 (patch)
tree4923f48ab1c2c39b593fcd67f87568ab88f26314
parent0069108a2cd7129387c940bd642a46fae5e7e8d2 (diff)
boards.py: more string to bytearray convesion
-rw-r--r--bubbob/boards.py52
1 files changed, 32 insertions, 20 deletions
diff --git a/bubbob/boards.py b/bubbob/boards.py
index 2463b11..7d3c540 100644
--- a/bubbob/boards.py
+++ b/bubbob/boards.py
@@ -26,8 +26,14 @@ class Board(Copyable):
def __init__(self, num):
# the subclasses should define 'walls', 'winds', 'monsters'
- self.walls = walls = [line for line in self.walls.split('\n') if line]
- self.winds = winds = [line for line in self.winds.split('\n') if line]
+ print(f"Board: self.walls={self.walls}", file=sys.stderr)
+ self.walls = walls = [line for line in self.walls.split(b'\n') if line]
+ for l in walls:
+ print(f"{l}", file=sys.stderr)
+ print(f"Board: self.winds={self.winds}", file=sys.stderr)
+ self.winds = winds = [line for line in self.winds.split(b'\n') if line]
+ for l in winds:
+ print(f"{l}", file=sys.stderr)
self.num = num
self.width = len(walls[0])
self.height = len(walls)
@@ -43,7 +49,7 @@ class Board(Copyable):
testline = self.walls[0]
else:
testline = self.walls[-1]
- self.holes = testline.find(' ') >= 0
+ self.holes = testline.find(b' ') >= 0
self.playingboard = 0
self.bonuslevel = not self.monsters or (gamesrv.game.finalboard is not None and self.num >= gamesrv.game.finalboard)
self.cleaning_gen_state = 0
@@ -138,7 +144,7 @@ class Board(Copyable):
for y in range(self.height):
for x in xrange:
c = self.walls[y][x]
- if c == '#':
+ if c == ord(b'#'):
wallicon = patget((self.num, x%wnx, y%wny), images.KEYCOL)
w = gamesrv.Sprite(wallicon, x*CELL, y*CELL + deltay)
l.append(w)
@@ -235,7 +241,7 @@ class Board(Copyable):
self.walls_by_pos[y,x] = w
if y >= 0:
line = self.walls[y]
- self.walls[y] = line[:x] + '#' + line[x+1:]
+ self.walls[y] = line[:x] + b'#' + line[x+1:]
def killwall(self, x, y, kill=1):
w = self.walls_by_pos[y,x]
@@ -250,7 +256,7 @@ class Board(Copyable):
w.move(0, -bheight)
del self.walls_by_pos[y,x]
line = self.walls[y]
- self.walls[y] = line[:x] + ' ' + line[x+1:]
+ self.walls[y] = line[:x] + b' ' + line[x+1:]
return w
def reorder_walls(self):
@@ -318,13 +324,16 @@ class Board(Copyable):
yield normal_frame()
self.cleaning_gen_state = 0
+def bchr(i):
+ return bytes([i])
+
def bget(x, y):
if 0 <= x < curboard.width:
if y < 0 or y >= curboard.height:
y = 0
- return curboard.walls[y][x]
+ return bchr(curboard.walls[y][x])
else:
- return '#'
+ return b'#'
def wget(x, y):
delta = curboard.WIND_DELTA
@@ -335,11 +344,11 @@ def wget(x, y):
y = 0
elif y >= curboard.height:
y = -1
- return curboard.winds[y][x]
+ return bchr(curboard.winds[y][x])
elif x < 0:
- return '>'
+ return b'>'
else:
- return '<'
+ return b'<'
def onground(x, y):
if y & 15:
@@ -358,8 +367,9 @@ def onground(x, y):
y0 = 0
y0 = curboard.walls[y0]
y1 = curboard.walls[y1]
- return (' ' == y1[x0] == y1[x1] == y1[x2] and
- not (' ' == y0[x0] == y0[x1] == y0[x2]))
+ ###DEBUG print(f"onground: y0={y0} y0[x0]={y0[x0]}", file=sys.stderr)
+ return (ord(b' ') == y1[x0] == y1[x1] == y1[x2] and
+ not (ord(b' ') == y0[x0] == y0[x1] == y0[x2]))
#return (' ' == bget(x0,y0-1) == bget(x1,y0-1) == bget(x2,y0-1) and
# not (' ' == bget(x0,y0) == bget(x1,y0) == bget(x2,y0)))
#return (bget(x1,y0-1)==' ' and
@@ -387,8 +397,8 @@ def underground(x, y):
y0 = 0
y0 = curboard.walls[y0]
y1 = curboard.walls[y1]
- return (' ' == y0[x0] == y0[x1] == y0[x2] and
- not (' ' == y1[x0] == y1[x1] == y1[x2]))
+ return (ord(b' ') == y0[x0] == y0[x1] == y0[x2] and
+ not (ord(b' ') == y1[x0] == y1[x1] == y1[x2]))
def x2bounds(x):
if x < 32:
@@ -977,7 +987,7 @@ def potion_fill(blist, big=0):
y = 1
while y < 11 or (y < height-2 and (len(all_notes) < 10 or big)):
for x in range(2, width-3, 2):
- if ' ' == bget(x,y) == bget(x+1,y) == bget(x,y+1) == bget(x+1,y+1):
+ if b' ' == bget(x,y) == bget(x+1,y) == bget(x,y+1) == bget(x+1,y+1):
b = Bonus(x*CELL, y*CELL, falling=0, *blist[((x+y)//2)%len(blist)])
b.timeout = (444,666)[big]
all_notes.append(b)
@@ -1230,7 +1240,7 @@ def extra_swap_up_down(N=27):
if not walls:
return
curboard.walls_by_pos.clear()
- emptyline = '##' + ' '*(width-4) + '##'
+ emptyline = b'##' + b' '*(width-4) + b'##'
curboard.walls = [emptyline] * height
l = curboard.sprites['walls']
wallicon = l[0].ico
@@ -1344,15 +1354,17 @@ def extra_make_random_level(cx=None, cy=None, repeat_delay=200):
yield 0
dist += 4.1
speedf *= 0.99
- if curboard.walls[y][x] == ' ':
- if lvl.walls[y][x] == ' ':
+ print(f"extra_make_random_level: walls[y][x]={curboard.walls[y][x]}", file=sys.stderr)
+ print(f"extra_make_random_level: walls[y][x]={lvl.walls[y][x]}", file=sys.stderr)
+ if curboard.walls[y][x] == b' ':
+ if lvl.walls[y][x] == b' ':
continue
else:
curboard.putwall(x, y)
added = 1
big = 1
else:
- if lvl.walls[y][x] == ' ':
+ if lvl.walls[y][x] == b' ':
curboard.killwall(x, y)
big = 1
else: