From 5e1e432954813cd783719af89e5bcd6204e6e73a Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Fri, 12 Sep 2025 13:13:51 +0000 Subject: [PATCH] [Sync Iteration] python/ghost-gobble-arcade-game/1 --- .../ghost-gobble-arcade-game/1/arcade_game.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 solutions/python/ghost-gobble-arcade-game/1/arcade_game.py diff --git a/solutions/python/ghost-gobble-arcade-game/1/arcade_game.py b/solutions/python/ghost-gobble-arcade-game/1/arcade_game.py new file mode 100644 index 0000000000..07cf976900 --- /dev/null +++ b/solutions/python/ghost-gobble-arcade-game/1/arcade_game.py @@ -0,0 +1,57 @@ +"""Functions for implementing the rules of the classic arcade game Pac-Man.""" + + +def eat_ghost(power_pellet_active, touching_ghost): + """Verify that Pac-Man can eat a ghost if he is empowered by a power pellet. + + :param power_pellet_active: bool - does the player have an active power pellet? + :param touching_ghost: bool - is the player touching a ghost? + :return: bool - can a ghost be eaten? + """ + + if power_pellet_active and touching_ghost: + return True + else: + return False + +def score(touching_power_pellet, touching_dot): + """Verify that Pac-Man has scored when a power pellet or dot has been eaten. + + :param touching_power_pellet: bool - is the player touching a power pellet? + :param touching_dot: bool - is the player touching a dot? + :return: bool - has the player scored or not? + """ + + if touching_power_pellet or touching_dot: + return True + else: + return False + + +def lose(power_pellet_active, touching_ghost): + """Trigger the game loop to end (GAME OVER) when Pac-Man touches a ghost without his power pellet. + + :param power_pellet_active: bool - does the player have an active power pellet? + :param touching_ghost: bool - is the player touching a ghost? + :return: bool - has the player lost the game? + """ + + if touching_ghost and (power_pellet_active == False): + return True + else: + return False + + +def win(has_eaten_all_dots, power_pellet_active, touching_ghost): + """Trigger the victory event when all dots have been eaten. + + :param has_eaten_all_dots: bool - has the player "eaten" all the dots? + :param power_pellet_active: bool - does the player have an active power pellet? + :param touching_ghost: bool - is the player touching a ghost? + :return: bool - has the player won the game? + """ + + if has_eaten_all_dots and (lose(power_pellet_active, touching_ghost) == False): + return True + else: + return False