Aggiungi file di configurazione per i binding dei tasti e implementa la gestione degli input nel gioco
This commit is contained in:
@@ -7,6 +7,7 @@ from engine import maze, sdl2 as engine, controls
|
||||
import os
|
||||
import datetime
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
class MiceMaze(controls.KeyBindings):
|
||||
def __init__(self, maze_file):
|
||||
@@ -27,13 +28,19 @@ class MiceMaze(controls.KeyBindings):
|
||||
self.scrolling_direction = None
|
||||
self.pause = False
|
||||
self.game_end = (False, None)
|
||||
self.dialog = "start_menu"
|
||||
self.scrolling = False
|
||||
self.sounds = {}
|
||||
self.start_game()
|
||||
self.background_texture = None
|
||||
keybindings_file, = "keybinding_game.json",
|
||||
with open(os.path.join("conf", keybindings_file)) as f:
|
||||
self.keybindings = json.load(f)
|
||||
|
||||
def start_game(self):
|
||||
for _ in range(5):
|
||||
self.new_rat()
|
||||
self.background_texture = None
|
||||
|
||||
|
||||
|
||||
def count_rats(self):
|
||||
count = 0
|
||||
for unit in self.units.values():
|
||||
@@ -78,9 +85,9 @@ class MiceMaze(controls.KeyBindings):
|
||||
def game_over(self):
|
||||
if self.game_end[0]:
|
||||
if not self.game_end[1]:
|
||||
self.engine.win_screen("Game Over: Mice are too many!", image=self.assets["BMP_WEWIN"])
|
||||
self.engine.dialog("Game Over: Mice are too many!", image=self.assets["BMP_WEWIN"])
|
||||
else:
|
||||
self.engine.win_screen(f"You Win! Points: {self.points}", image=self.assets["BMP_WEWIN"], scores=self.read_score())
|
||||
self.engine.dialog(f"You Win! Points: {self.points}", image=self.assets["BMP_WEWIN"], scores=self.read_score())
|
||||
|
||||
|
||||
return True
|
||||
@@ -106,7 +113,9 @@ class MiceMaze(controls.KeyBindings):
|
||||
|
||||
def update_maze(self):
|
||||
if self.pause:
|
||||
self.engine.pause_screen("Paused")
|
||||
if self.dialog != "start_menu":
|
||||
self.engine.dialog("Pause")
|
||||
self.engine.start_dialog(image=self.assets["BMP_WEWIN"])
|
||||
return
|
||||
if self.game_over():
|
||||
return
|
||||
@@ -128,7 +137,6 @@ class MiceMaze(controls.KeyBindings):
|
||||
|
||||
|
||||
def run(self):
|
||||
self.draw_maze()
|
||||
self.engine.mainloop(update=self.update_maze, bg_update=self.draw_maze)
|
||||
|
||||
def scroll_cursor(self, x=0, y=0):
|
||||
|
||||
Reference in New Issue
Block a user