Aggiungi file .gitignore e nuove immagini BMP per il progetto Rat

This commit is contained in:
Matteo Benedetto
2024-12-08 01:45:16 +01:00
parent b89c4ae375
commit a6a06d1d54
764 changed files with 153 additions and 126 deletions
+50
View File
@@ -0,0 +1,50 @@
import tkinter as tk
import os
class GameWindow:
"""Classe che gestisce la finestra di gioco e il rendering grafico."""
def __init__(self, width, height, cell_size):
self.cell_size = cell_size
self.window = tk.Tk()
self.window.title("Mice!")
self.canvas = tk.Canvas(self.window, width=width*cell_size, height=height*cell_size)
self.canvas.pack()
self.menu = tk.Menu(self.window)
self.menu.add_command(label="Quit", command=self.window.destroy)
self.status_bar = tk.Label(self.window, text="Welcome to Mice!", bd=1, relief=tk.SUNKEN, anchor=tk.W)
self.status_bar.pack(side=tk.BOTTOM, fill=tk.X)
self.window.config(menu=self.menu)
def load_image(self, path, transparent_color=None):
image = tk.PhotoImage(file=os.path.join(os.path.dirname(__file__), "..", "assets", path))
if transparent_color:
gray_pixels = []
for y in range(image.height()):
for x in range(image.width()):
r, g, b = image.get(x, y)
if r == transparent_color[0] and g == transparent_color[1] and b == transparent_color[2]:
gray_pixels.append((x, y))
for x, y in gray_pixels:
image.transparency_set(x, y, 1)
return image.zoom(self.cell_size // 20)
def bind(self, event, callback):
self.window.bind(event, callback)
def draw_image(self, x, y, image, tag, anchor="nw"):
self.canvas.create_image(x, y, image=image, anchor=anchor, tag=tag)
def draw_rectangle(self, x, y, width, height, tag, outline="red"):
self.canvas.create_rectangle(x, y, x+width, y+height, outline=outline, tag=tag)
def delete_tag(self, tag):
self.canvas.delete(tag)
def update_status(self, text):
self.status_bar.config(text=text)
def new_cycle(self, delay, callback):
self.window.after(delay, callback)
def mainloop(self):
self.window.mainloop()
+9
View File
@@ -0,0 +1,9 @@
import json
class Map:
"""Classe che rappresenta la mappa del labirinto."""
def __init__(self, maze_file):
with open(maze_file, 'r') as file:
self.matrix = json.load(file)
self.height = len(self.matrix)
self.width = len(self.matrix[0])