Configurable jobs. Maze has difficulties and fixed S and E symbols.
This commit is contained in:
parent
da8ab4e448
commit
4ee3d12933
@ -4,6 +4,9 @@ class Job:
|
|||||||
def get_name(self):
|
def get_name(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def configure(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def print_body(self, p):
|
def print_body(self, p):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|||||||
31
jobs/maze.py
31
jobs/maze.py
@ -3,15 +3,33 @@ from PIL import Image, ImageDraw
|
|||||||
from .base import Job
|
from .base import Job
|
||||||
|
|
||||||
class MazeJob(Job):
|
class MazeJob(Job):
|
||||||
|
def __init__(self):
|
||||||
|
self.width = 14
|
||||||
|
self.height = 32
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return "BLUDISTE"
|
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):
|
def print_body(self, p):
|
||||||
# Width and Height in cells.
|
# Width and Height in cells.
|
||||||
# Total width in chars = 2 * w + 1.
|
# Total width in chars = 2 * w + 1.
|
||||||
# w=15 -> 31 chars (Fits comfortably on 80mm printers, tight on 58mm)
|
# w=15 -> 31 chars (Fits comfortably on 80mm printers, tight on 58mm)
|
||||||
w = 14
|
w = self.width
|
||||||
h = 32
|
h = self.height
|
||||||
|
|
||||||
maze = self.generate_maze(w, h)
|
maze = self.generate_maze(w, h)
|
||||||
|
|
||||||
@ -38,12 +56,17 @@ class MazeJob(Job):
|
|||||||
|
|
||||||
for r in range(rows):
|
for r in range(rows):
|
||||||
for c in range(cols):
|
for c in range(cols):
|
||||||
|
x = c * cell_size
|
||||||
|
y = r * cell_size
|
||||||
|
|
||||||
# Draw walls as black rectangles
|
# Draw walls as black rectangles
|
||||||
if maze[r][c] == '#':
|
if maze[r][c] == '#':
|
||||||
x = c * cell_size
|
|
||||||
y = r * cell_size
|
|
||||||
# fill=0 means Black in '1' mode
|
# fill=0 means Black in '1' mode
|
||||||
draw.rectangle([x, y, x + cell_size, y + cell_size], fill=0)
|
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
|
return img
|
||||||
|
|
||||||
|
|||||||
@ -79,16 +79,27 @@ def run_tui():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if job:
|
if job:
|
||||||
|
job.configure()
|
||||||
|
|
||||||
|
copies_str = input("\nNumber of copies [1]: ").strip()
|
||||||
|
try:
|
||||||
|
copies = max(1, int(copies_str)) if copies_str else 1
|
||||||
|
except ValueError:
|
||||||
|
copies = 1
|
||||||
|
|
||||||
p = get_printer()
|
p = get_printer()
|
||||||
if p:
|
if p:
|
||||||
print(f"Printing {job.get_name()}...")
|
print(f"Printing {job.get_name()} ({copies} copies)...")
|
||||||
try:
|
try:
|
||||||
job.run(p)
|
for i in range(copies):
|
||||||
|
if copies > 1:
|
||||||
# If using Dummy, print the output to console to verify
|
print(f" Printing copy {i + 1}...")
|
||||||
if isinstance(p, Dummy):
|
job.run(p)
|
||||||
print(p.output.decode('utf-8', errors='ignore'))
|
|
||||||
|
|
||||||
|
# If using Dummy, print the output to console to verify
|
||||||
|
if isinstance(p, Dummy):
|
||||||
|
print(p.output.decode('utf-8', errors='ignore'))
|
||||||
|
|
||||||
print("Success! Job sent to printer.")
|
print("Success! Job sent to printer.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Print Error: {e}")
|
print(f"Print Error: {e}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user