Configurable jobs. Maze has difficulties and fixed S and E symbols.
This commit is contained in:
@@ -4,6 +4,9 @@ class Job:
|
||||
def get_name(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def configure(self):
|
||||
pass
|
||||
|
||||
def print_body(self, p):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
+27
-4
@@ -3,15 +3,33 @@ from PIL import Image, ImageDraw
|
||||
from .base import Job
|
||||
|
||||
class MazeJob(Job):
|
||||
def __init__(self):
|
||||
self.width = 14
|
||||
self.height = 32
|
||||
|
||||
def get_name(self):
|
||||
return "BLUDISTE"
|
||||
|
||||
def configure(self):
|
||||
print("\nSelect Difficulty:")
|
||||
print(" [1] Easy")
|
||||
print(" [2] Medium")
|
||||
print(" [3] Hard")
|
||||
choice = input("Choice [2]: ").strip()
|
||||
|
||||
if choice == '1':
|
||||
self.height = 8
|
||||
elif choice == '3':
|
||||
self.height = 32
|
||||
else:
|
||||
self.height = 18
|
||||
|
||||
def print_body(self, p):
|
||||
# Width and Height in cells.
|
||||
# Total width in chars = 2 * w + 1.
|
||||
# w=15 -> 31 chars (Fits comfortably on 80mm printers, tight on 58mm)
|
||||
w = 14
|
||||
h = 32
|
||||
w = self.width
|
||||
h = self.height
|
||||
|
||||
maze = self.generate_maze(w, h)
|
||||
|
||||
@@ -38,12 +56,17 @@ class MazeJob(Job):
|
||||
|
||||
for r in range(rows):
|
||||
for c in range(cols):
|
||||
x = c * cell_size
|
||||
y = r * cell_size
|
||||
|
||||
# Draw walls as black rectangles
|
||||
if maze[r][c] == '#':
|
||||
x = c * cell_size
|
||||
y = r * cell_size
|
||||
# fill=0 means Black in '1' mode
|
||||
draw.rectangle([x, y, x + cell_size, y + cell_size], fill=0)
|
||||
elif maze[r][c] == 'S':
|
||||
draw.text((x + 5, y + 2), "S", fill=0)
|
||||
elif maze[r][c] == 'E':
|
||||
draw.text((x + 5, y + 2), "E", fill=0)
|
||||
|
||||
return img
|
||||
|
||||
|
||||
Reference in New Issue
Block a user