From a8c79b1c470b59056af1167fb946d75632a52ace Mon Sep 17 00:00:00 2001 From: mpetri Date: Mon, 11 Nov 2019 19:01:02 +0100 Subject: [PATCH] ajout de l'objet pacman et quelques fonctions --- src/pacman.py | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/pacman.py diff --git a/src/pacman.py b/src/pacman.py new file mode 100644 index 0000000..900a5e3 --- /dev/null +++ b/src/pacman.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +import pacmap +import os + +from enum import IntEnum + +pacdot_counter = 88 +score = 0 +lives = 3 + +class Direction(IntEnum): + U = 0 + D = 1 + R = 2 + L = 3 + +class FruitType(IntEnum): + A = 0 + +class Fruit: + def __init__(self, fruit_type, score, position = (0, 0)): + self.fruit_type = fruit_type + self.score = score + self.position = position + + +class Pacman: + def __init__(self): + self.position = (0.0, 0.0) + self.direction = Direction.R + self.next_direction = Direction.R + self.super_power = 0 # Counter of super pacdots in effect (> 0 means super power is active) + self.ghost_combo = 0 + + def matrix_position(self): + return (int(self.position[0]), int(self.position[1])) + + def has_super_power(self): + return self.super_power > 0 + + def eat_pacdot(self, map): + global score + global pacdot_counter + map.dots_map[self.matrix_position()[0]][self.matrix_position()[1]] = pacmap.DotTile.NDT + pacdot_counter -= 1 + score += 10 + + def eat_super_pacdot(self, map): + global score + map.dots_map[self.matrix_position()[0]][self.matrix_position()[1]] = pacmap.DotTile.NDT + score += 50 + self.super_power += 1 + + # TODO + # Requires UNIX + #pid = os.fork() + #if pid == 0: + # return + + #os.sleep(10) + self.super_power -= 1 + self.ghost_combo = 0 + #os._exit(0) + + def eat_fruit(self, fruit, map): + global score + map.dots_map[self.matrix_position()[0]][self.matrix_position()[1]] = pacmap.DotTile.NDT + score += fruit.score + + def eat_ghost(self, ghost): + global score + ghost.despawn_and_respawn() + self.ghost_combo += 1 + score += (2 ^ self.ghost_combo) * 100 + + def get_eaten(self, map): + global lives + #TODO score loss ? + self.position = map.spawn_point #TODO + lives -= 1 + if lives <= 0: + game_over() + +def game_over(): + #TODO + pass + + + + + +