From 4f97da84bf496d62be9237f8c23abc5c03539c7a Mon Sep 17 00:00:00 2001 From: Vadzim Valchkovich Date: Thu, 15 Jun 2023 18:18:25 +0200 Subject: [PATCH] improved color indication of orders, added penalty points --- README.MD | 2 ++ src/Engine.py | 9 ++++++--- src/controller/UserController.py | 3 +++ src/obj/Kitchen.py | 29 ++++++++++++++++++++++++++--- src/obj/Table.py | 5 +++-- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/README.MD b/README.MD index f54ddee..cb4d044 100644 --- a/README.MD +++ b/README.MD @@ -25,6 +25,8 @@ > **F** - _show or hide fringes_ +> **P** - _penalty time_ + > **SPACE** - _pause or continue_ ## TODO diff --git a/src/Engine.py b/src/Engine.py index dd94cd4..73d663b 100644 --- a/src/Engine.py +++ b/src/Engine.py @@ -123,10 +123,13 @@ class Engine: if self.waiter.on(o.position): o.action(self.waiter, self.action_clock) - if self.waiter.on(self.kitchen.position): - self.kitchen.action(self.waiter, self.action_clock) + self.kitchen.action(self.waiter, self.action_clock) - # STEP 6. Wait + # STEP 6. Update kitchen state + + self.kitchen.updateMark() + + # STEP 7. Wait time.sleep(self.action_duration) diff --git a/src/controller/UserController.py b/src/controller/UserController.py index 96820f8..c0a5e88 100644 --- a/src/controller/UserController.py +++ b/src/controller/UserController.py @@ -22,3 +22,6 @@ class UserController: print(colored("Paused", "red")) else: print(colored("Continued", "green")) + elif event.key == pygame.K_p: + print(colored("Penalty time: 100", "red")) + engine.clock_increment(100) diff --git a/src/obj/Kitchen.py b/src/obj/Kitchen.py index 8a1d75d..7b0ba0e 100644 --- a/src/obj/Kitchen.py +++ b/src/obj/Kitchen.py @@ -1,5 +1,6 @@ from src.obj.Object import Object from src.obj.Table import Table +from src.obj.Mark import Mark class Kitchen(Object): @@ -7,22 +8,44 @@ class Kitchen(Object): super().__init__("kitchen", position, orientation, square_size, screen_size, store) self.cooking: list(Table) = [] self.done: list(Table) = [] + self.mark = None + + def updateMark(self): + if self.done: + self.setMark("dish_done") + elif self.cooking: + self.setMark("dish_cooking") + else: + self.unsetMark() + + def setMark(self, mark_type): + self.mark = Mark(self, mark_type) + + def unsetMark(self): + self.mark = None + + def blit(self, screen): + super().blit(screen) + if self.mark: + self.mark.blit(screen) def action(self, waiter, current_time): self.cook_dishes(current_time) - waiter.combine_orders(current_time, self) - waiter.recharge() + if waiter.on(self.position): + waiter.combine_orders(current_time, self) + waiter.recharge() def cook_dishes(self, current_time): for table in self.cooking: if table.dish_is_ready(current_time): self.done.append(table) - table.setMark("dish_done") for table in self.done: if table in self.cooking: self.cooking.remove(table) + self.updateMark() + def take_order(self, order): order.start_cooking() order.setMark("dish_cooking") diff --git a/src/obj/Table.py b/src/obj/Table.py index 8d74b2b..b673f22 100644 --- a/src/obj/Table.py +++ b/src/obj/Table.py @@ -43,7 +43,7 @@ class Table(Object): self.change_role(new_role, current_time) if self.agent_role == "wait": - self.cooking_time = random.randint(0, 1000) + self.cooking_time = random.randint(0, 500) def dish_is_ready(self, current_time): return current_time - self.waiting_time > self.cooking_time @@ -80,10 +80,11 @@ class Table(Object): def start_cooking(self): if self.agent_role == "wait": - self.cooking_time = random.randint(0, 1000) + self.cooking_time = random.randint(0, 500) def set_done(self, current_time): if self.agent_role == "wait": + self.setMark("dish_done") self.change_role("done", current_time) def is_order(self):