Exemple #1
2
class PacmanTests(unittest.TestCase):
    def setUp(self):
        self.pacman = Pacman()
    
    def test_pacman_est_dans_un_labyrinthe(self):
        self.assert_(self.pacman.maze)

    def test_pacman_position(self):
        self.assert_(self.pacman.x == 0)
        self.assert_(self.pacman.y == 0)

    def test_bouge_pacman(self):
        self.pacman.direction = Pacman.Left
        self.pacman.x = 9
        self.pacman.y = 1
        self.pacman.direction = Pacman.Left
        self.pacman.bouge()
        self.assertEqual(self.pacman.x, 8)
        self.assertEqual(self.pacman.y, 1)

        self.pacman.direction = Pacman.Right
        self.pacman.bouge()
        self.assertEqual(self.pacman.x, 9)
        self.assertEqual(self.pacman.y, 1)
        
        self.pacman.direction = Pacman.Up
        self.pacman.bouge()
        self.assertEqual(self.pacman.y, 0)
        self.assertEqual(self.pacman.x, 9)
        
        self.pacman.direction = Pacman.Down
        self.pacman.bouge()
        self.assertEqual(self.pacman.y, 1)
        self.assertEqual(self.pacman.x, 9)

    def test_fin_du_monde(self):
        self.pacman.maze.largeur, self.pacman.maze.longueur = 2, 2
        self.pacman.x, self.pacman.y = 0, 0
        
        self.pacman.direction = Pacman.Left
        self.pacman.bouge()
        self.assertEqual(self.pacman.x, 1)
        self.assertEqual(self.pacman.y, 0)

        self.pacman.direction = Pacman.Right
        self.pacman.bouge()
        self.assertEqual(self.pacman.x, 0)
        self.assertEqual(self.pacman.y, 0)

        self.pacman.direction = Pacman.Up
        self.pacman.bouge()
        self.assertEqual(self.pacman.y, 1)
        self.assertEqual(self.pacman.x, 0)

        self.pacman.direction = Pacman.Down
        self.pacman.bouge()
        self.assertEqual(self.pacman.y, 0)
        self.assertEqual(self.pacman.x, 0)
        
    def test_pacman_ne_defonce_PAS_les_murs(self):
        mazeString = "+.\n"
        self.pacman.maze.loadMaze(mazeString)
        self.pacman.x = 1
        self.pacman.y = 0
        self.pacman.direction = Pacman.Left
        self.pacman.bouge()
        self.assertEqual(self.pacman.x, 1)

    def test_pacman_est_un_morfale(self):
        mazeString = ".*\n"
        self.pacman.score = 0
        self.pacman.maze.loadMaze(mazeString)
        self.pacman.x, self.pacman.y = 0, 0
        self.pacman.direction = Pacman.Left
        self.pacman.bouge()
        self.assertEqual(self.pacman.maze.get(1, 0), '.')
        self.assertEqual(self.pacman.score, 1)
Exemple #2
1
def joue(scr):
    curses.curs_set(0)
    pacman = Pacman()
    pacman.x=1
    pacman.y=1
    with open("terrain.txt") as f:
        pacman.maze.loadMaze(f.read())
    scr.timeout(150)

    while True:
        for i in range(pacman.maze.largeur):
            for j in range(pacman.maze.longueur):
                scr.addstr(j, i, pacman.maze.get(i, j))
        scr.addstr(pacman.y, pacman.x, pacman.tronche)
        scr.addstr(pacman.maze.longueur, pacman.maze.largeur + 5, "Score plutôt que String toute entière : " + str(pacman.score))
        scr.refresh()

        c = scr.getch()
        if c == curses.KEY_UP:
            pacman.direction = Pacman.Up
        elif c == curses.KEY_DOWN:
            pacman.direction = Pacman.Down 
        elif c == curses.KEY_LEFT:
            pacman.direction = Pacman.Left
        elif c == curses.KEY_RIGHT:
            pacman.direction = Pacman.Right
        elif c == curses.KEY_F1:
            return

        pacman.bouge()
Exemple #3
1
def game_start():
    global tilegrp
    global tiles
    global nodegrp
    global nodes
    global coingrp
    global coins
    global ghostgrp
    global ghosts
    global pacman
    global pacman1
    global pacman2
    global pacman3
    global score
    score = 0
    #code to add tiles in the screen
    tilegrp = Tilegroup(width, height)
    tiles = tilegrp.createTileList(maze_filename)

    #nodes added, not displayed on the screen, only for navigation purpose
    nodegrp = NodeGroup(width, height)
    nodes = nodegrp.createNodeList(maze_filename)

    #adding coins to our maze
    coingrp = Coingroup(width)
    coins = coingrp.createCoinList(coin_and_ghosts_filename)

    #ghosts added
    ghostgrp = Ghostgroup(width, height)
    ghosts = ghostgrp.create_ghostlist(maze_filename, coin_and_ghosts_filename, nodes)

    #pacman added
    from random import randint
    ind = randint(0, len(nodes)-1)
    ind1 = randint(0, len(nodes)-1)
    ind2 = randint(0, len(nodes)-1)
    ind3 = randint(0, len(nodes)-1)
    pacman =  Pacman(nodes[ind], (width,height), [nodes[ind].position.x, nodes[ind].position.y])
    pacman1 = Pacman(nodes[ind1], (width,height), [nodes[ind].position.x, nodes[ind].position.y])
    pacman2 = Pacman(nodes[ind2], (width,height), [nodes[ind].position.x, nodes[ind].position.y])
    pacman3 = Pacman(nodes[ind3], (width,height), [nodes[ind].position.x, nodes[ind].position.y])

    #if we are controlling pacman manually
    if args.manual:
        pacman.speed = 0.8
        for g in ghosts:
            g.speed = 0.4
Exemple #4
0
    def __init__(self):
        pygame.init()
        self.screen_width = 599
        self.screen_height = 800
        self.screen = pygame.display.set_mode(
            (self.screen_width, self.screen_height))
        pygame.display.set_caption('Pacman')
        self.clock = pygame.time.Clock()

        self.WHITE = (255, 255, 255)
        self.BLACK = (0, 0, 0)
        self.hovered = False

        # self.blinky = Ghost(self.screen, self.maze, 'blinky')
        #self.ghosts = Group()

        # Give files needed to populate the maze
        self.expandfile = ExpandFile('test.txt', expandBy=2)
        self.maze = Maze(self.screen, 'test.txt', 'images/wall',
                         'images/foodPellet', 'images/portal_1',
                         'images/portal_2')

        self.player = Pacman(self.screen, self.maze, self.maze.pacmanposition)
        self.blinky = Ghost(self.screen, 'blinky', self.maze,
                            self.maze.blinky_position, self.player)
        self.clyde = Ghost(self.screen, 'clyde', self.maze,
                           self.maze.clyde_position, self.player)
        self.inkey = Ghost(self.screen, 'inkey', self.maze,
                           self.maze.inkey_position, self.player)
        self.pinky = Ghost(self.screen, 'pinky', self.maze,
                           self.maze.pinky_position, self.player)

        self.intro_music = pygame.mixer.Sound("sounds/intro.wav")

        self.intro_logo = pygame.image.load('images/pacmanLogo.png')
Exemple #5
0
def main():
    if len(sys.argv) != 2:
        "please pass the file of the commands"
        exit(0)


    Commands = readFile(sys.argv[1])
    orientations = ["NORTH", "EAST", "SOUTH", "WEST"]


    grid = Grid()
    pacman = Pacman(orientations=orientations)


    if "PLACE" not in Commands[0]:
        print("The first valid command to the pacman is a PLACE command, please specify it")


    elif "PLACE" in Commands[0]:
            for command in Commands:
                if "PLACE" in command:
                    command_splitted = preprocessCommands(command)
                    x_axis = float(command_splitted[0])
                    y_axis = float(command_splitted[1])
                    facing = command_splitted[2]
                    orientations_index = orientations.index(facing)
                    pacman_position = Direction(x_axis=x_axis, y_axis=y_axis)
                    pacman = pacman.place(Direction=pacman_position,grid=grid,facing=orientations_index/2.0)
                else:
                    pacman = getattr(pacman,command.lower())()
Exemple #6
0
    def __init__(self):
        pygame.init()
        pygame.mixer.pre_init(44100, 16, 2, 4096)
        self.settings = Settings()
        self.settings.start_intro_music()
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Pacman Portal")
        self.clock = pygame.time.Clock()
        self.radius = 1
        self.start = 1
        self.end = 10
        self.begin = pygame.time.get_ticks()
        self.wait = 800

        self.startup = Start(self.screen, self.settings)
        self.stats = Stats(self.settings)
        self.sb = Scoreboard(self.settings, self.screen, self.stats)

        self.maze = Maze(self.screen, mazefile='images/pacman_portal_maze.txt',
                         brickfile='square', orangeportalfile='portal_orange', blueportalfile='portal_blue',
                         shieldfile='shield', pointfile='point_pill', gatefile="gate")
        self.pacman = Pacman(self.screen, mazefile='images/pacman_portal_maze.txt')

        self.red = Red(self.screen, mazefile='images/pacman_portal_maze.txt')
        self.blue = Blue(self.screen, mazefile='images/pacman_portal_maze.txt')
        self.orange = Orange(self.screen, mazefile='images/pacman_portal_maze.txt')
        self.pink = Pink(self.screen, mazefile='images/pacman_portal_maze.txt')
        self.inc = 0
Exemple #7
0
 def start_game(self):
     self.level.reset()
     level_map = self.level.get_level()
     self.game_over = False
     self.stats = GameStats(settings=self.settings)
     self.sb = Scoreboard(settings=self.settings,
                          screen=self.screen,
                          stats=self.stats)
     self.sound = Sound()
     self.maze = Maze(settings=self.settings, screen=self.screen)
     self.maze.get_maze()
     self.grid_pts = Grid_Pnts_Group(settings=self.settings,
                                     screen=self.screen,
                                     txt_file=level_map["mazename"])
     self.foods = FoodGroup(settings=self.settings,
                            screen=self.screen,
                            food_file=level_map["foodname"])
     self.pacman = Pacman(game=self,
                          settings=self.settings,
                          screen=self.screen,
                          grid_pts=self.grid_pts,
                          foods=self.foods,
                          sb=self.sb)
     self.ghosts = Ghost_Group(game=self,
                               settings=self.settings,
                               screen=self.screen,
                               grid_pts=self.grid_pts)
     self.pellets_eaten = 0
     self.settings.pacman_lives = self.settings.starting_lives
     self.fruit = None
     self.pause.force(True)
Exemple #8
0
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((716, 793 + 60))
        pygame.display.set_caption("Pacman Portal")

        self.bricks = Group()
        self.shields = Group()
        self.powerpills = Group()
        self.qpills = Group()
        self.maze = Maze(self.screen,
                         self.bricks,
                         self.shields,
                         self.powerpills,
                         self.qpills,
                         brickfile='square',
                         mazefile='images/pacmanportalmaze.txt',
                         shieldfile='shield',
                         powerpill='powerpill')

        self.increase = False
        self.scoreboard = Scorebord(self.screen, self)
        self.pacman = Pacman(self.screen, self.scoreboard, self)
        self.play_button = Button(self.screen, "PLAY GAME", 80 / 100)
        self.score_button = Button(self.screen, "HIGH SCORES", 90 / 100)
        self.menu = Menu()
        self.audio = Audio()
        self.fruit = Fruit(self.screen)
        self.blinky = Blinky(self.screen, self.pacman, self.scoreboard)
        self.inky = Inky(self.screen, self.pacman, self.scoreboard)
        self.pinky = Pinky(self.screen, self.pacman, self.scoreboard)
        self.clyde = Clyde(self.screen, self.pacman, self.scoreboard)
        self.oportal = Portal('o', self.pacman)
        self.bportal = Portal('b', self.pacman)
        self.active = False
        self.pause = False
    def __init__(self):
        pygame.init()
        pygame.display.set_caption("Pacman Portal")
        self.screen = pygame.display.set_mode((800, 600))
        self.maze = Maze(screen=self.screen, maze_map_file='pacmanportalmaze.txt')
        self.clock = pygame.time.Clock()
        self.ghost_sounds = Sounds(sound_files=['ghost-blue.wav', 'ghost-eaten.wav', 'ghost-std.wav'],
                                                keys=['blue', 'eaten', 'std'],
                                                channel=Ghost.audio)

        self.stock = PacmanLives(screen=self.screen, ct_pos=((self.screen.get_width() // 3),
                                                                      (self.screen.get_height() * 0.965)),
                                          images_size=(self.maze.block_size, self.maze.block_size))
        self.score = ScoreController(screen=self.screen,
                                            sb_pos=((self.screen.get_width() // 5),
                                                    (self.screen.get_height() * 0.965)),
                                            items_image='cherry.png',
                                            itc_pos=(int(self.screen.get_width() * 0.6),
                                                     self.screen.get_height() * 0.965))
        self.next_level = NextLevel(screen=self.screen, score_controller=self.score)
        self.game_over = True
        self.pause = False
        self.player = Pacman(screen=self.screen, maze=self.maze)
        self.ghosts = Group()
        self.ghost_time = 2500
        self.ghosts_stack = None
        self.top_ghost = None
        self.arr_ghost = []
        self.spawn_ghosts()
        self.events = {PacmanPortal.START_EVENT: self.init_ghosts, PacmanPortal.REBUILD_EVENT: self.rebuild_maze, PacmanPortal.LEVEL_EVENT: self.clear_level}
    def play(self):
        print("Start game")
        # game_state = ts.GameState.TITLE
        #
        # while True:
        #     if game_state is ts.GameState.TITLE:
        #         game_state = ts.title_screen(self.screen)
        #
        #     if game_state is ts.GameState.PlAY:

        self.level.reset()
        levelmap = self.level.getLevel()
        self.maze.getMaze(levelmap["name"].split(".")[0])
        self.maze.constructMaze(self.background, self.background_flash, levelmap["row"])
        self.nodes = NodeGroup(levelmap["name"])
        self.pellets = PelletGroup(levelmap["name"])
        self.pacman = Pacman(self.sound, self.nodes, self.sheet)
        self.ghosts = GhostGroup(self.nodes, self.sheet)
        self.pelletsEaten = 0
        self.fruit = None
        self.pause.force(True)
        self.text.showReady()
        self.sound.intro()
        self.text.updateLevel(self.level.level + 1)
        self.gameover = False
        self.maze.reset()
        self.flashBackground = False
Exemple #11
0
 def startGame(self):
     print("Restarting the game")
     self.maze.setup(self.level)
     self.nodes = NodeGroup(self.maze.filename + ".txt")
     self.pellets = PelletGroup(self.maze.filename + ".txt")
     self.pacman = Pacman(self.nodes, self.sheet)
     self.ghosts = GhostGroup(self.nodes, self.sheet)
     self.paused = True
     self.fruit = None
     self.pelletsEaten = 0
     self.lifeIcons = LifeIcon(self.sheet)
     self.maze.stitchMaze(self.background, self.background_white)
     self.hiScoreTxtStatic = Text("HI SCORE", WHITE, 0, 0, 16)
     self.scoreTxtStatic = Text("SCORE", WHITE, 208, 0, 16)
     self.levelTxtStatic = Text("LEVEL", WHITE, 368, 0, 16)
     self.score = 0
     self.scoreLabel = Text(str(self.score).zfill(8), WHITE, 208, 16, 16)
     self.started = False
     self.pausedByPlayer = False
     self.pauseTime = 0
     self.timer = 0
     self.nextLevelAfterPause = False
     self.startAfterPause = False
     self.restartAfterPause = False
     self.flash_background = False
     self.flash_rate = 0.2
     self.flashtime = 0
     self.show_white_background = False
     self.gameover = False
     self.level = 1  #####
Exemple #12
0
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((680, 740))
        self.ai_settings = Settings()
        pygame.display.set_caption("Pacman Portal")

        self.maze = Maze(self.screen,
                         mazefile='map.txt',
                         brickfile='square',
                         portalfile='square',
                         shieldfile='shield',
                         pointfile='point',
                         dotfile='dot',
                         powerpillfile='powerpill')

        self.pacman = Pacman(self.ai_settings, self.screen, self.maze)
        self.ghosts = Ghosts(self.ai_settings, self.screen, self.maze,
                             self.pacman)
        self.displayname = Button(self.screen, "PacmanPortal")
        self.play_button = Button(self.screen, "PLAY GAME")
        self.highscore_button = Button(self.screen, "HIGH SCORES")
        self.blinkyname = Button(self.screen, "BLiNKY")
        self.pinkyname = Button(self.screen, "PiNKY")
        self.clydename = Button(self.screen, "CLYDE")
        self.inkeyname = Button(self.screen, "iNKEY")
        self.back = Button(self.screen, "Back")
        self.sb = Scoreboard(self.ai_settings, self.screen, self.maze,
                             self.pacman)
        self.score = Button(self.screen, "hello")
        self.blues = 0
Exemple #13
0
    def __init__(self):
        pygame.init()
        pygame.mixer.music.load('sounds/fortnite-dance.wav')
        self.game_screen = pygame.display.set_mode((900, 700))

        pygame.display.set_caption('Pacman')
        self.tick_component = pygame.time.Clock()

        self.hold_score = ScoreController(screen=self.game_screen,
                                            sb_pos=((self.game_screen.get_width() // 5),
                                                    (self.game_screen.get_height() * 0.965)),
                                            items_image='strawb.png',
                                            itc_pos=(int(self.game_screen.get_width() * 0.6),
                                                     self.game_screen.get_height() * 0.965))
        self.map_layout = Maze(screen=self.game_screen, maze_map_file='maze_map.txt')
        self.lives_left = Counter(screen=self.game_screen, ct_pos=((self.game_screen.get_width() // 3),
                                                                      (self.game_screen.get_height() * 0.965)),
                                          images_size=(self.map_layout.block_size, self.map_layout.block_size))
        self.next_level = LevelTransition(screen=self.game_screen, score_controller=self.hold_score)
        self.lost_game = True
        self.pause_game = False
        self.pacman_player = Pacman(screen=self.game_screen, maze=self.map_layout)
        self.pacman_ghosts = pygame.sprite.Group()
        self.pacman_ghosts_sound = SoundManager(sound_files=['ghost.wav', 'pacman_eatghost.wav', 'pacman_siren.wav'],
                                                keys=['blue', 'eaten', 'siren'],
                                                channel=Ghost.ghost_audio)
        self.pacman_ghosts_interval_active = 2500
        self.pacman_ghosts_begin_chase = None
        self.pacman_ghosts_blinky = None
        self.pacman_ghosts_others = []
        self.blit_ghosts()
        self.game_actions = {PlayGame.event_start: self.init_ghosts,
                             PlayGame.event_remake: self.rebuild_maze,
                             PlayGame.event_next_level: self.next_level}
Exemple #14
0
def run_game():
    # Initialize pygame, settings, and screen object.
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.mixer.init()
    pygame.init()
    game_settings = GameSettings()
    screen = pygame.display.set_mode((game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Pac Man Portal")

    # Open sprite sheet
    sprite_sheet = SpriteSheet(file_name='images/spritesheet.png')

    # Make the Play and Scores button.
    play_button = Button(screen=screen, msg="Play", order=0)
    score_button = Button(screen=screen, msg="High Scores", order=1)

    # Open high score file
    try:
        high_score_file = open("high_score_file.txt", "r+")
    except FileNotFoundError:
        high_score_file = open("high_score_file.txt", "w+")

    # Open maze layout file
    maze_file = open('mazelayout.txt', 'r')

    # Make sound manager
    sounds = Sounds()

    # Initialize game stats and scoreboard
    stats = GameStats(game_settings=game_settings)
    sb = Scoreboard(screen=screen, game_settings=game_settings, stats=stats, sprite_sheet=sprite_sheet,
                    high_score_file=high_score_file, sounds=sounds)

    # Initialize pacman
    pacman = Pacman(screen=screen, game_settings=game_settings, stats=stats, sb=sb,
                    image_list=sprite_sheet.pacman_image, death_anim_list=sprite_sheet.pacman_death_image,
                    sounds=sounds)

    # Initialize maze
    maze = Maze(screen=screen, game_settings=game_settings, maze_file=maze_file, sprite_sheet=sprite_sheet,
                pacman=pacman, sounds=sounds)

    # Initialize the event handler
    event_handler = EventHandler(pacman=pacman, play_button=play_button, score_button=score_button, stats=stats, sb=sb,
                                 maze=maze, sounds=sounds)

    # Initialize the display manager
    display = Display(screen=screen, game_settings=game_settings, stats=stats, sb=sb, sprite_sheet=sprite_sheet,
                      play_button=play_button, score_button=score_button, maze=maze, pacman=pacman,
                      event_handler=event_handler, sounds=sounds)

    # Start the main loop for the game
    while True:
        event_handler.check_events()
        if stats.game_active:
            pacman.update(maze=maze, display=display)
            maze.update_ghosts()
            maze.update_bullets()
            maze.update_portals()
        display.update_screen()
Exemple #15
0
def joue(scr):
    curses.curs_set(0)
    pacman = Pacman()
    pacman.x = 1
    pacman.y = 1
    with open("terrain.txt") as f:
        pacman.maze.loadMaze(f.read())
    scr.timeout(150)

    while True:
        for i in range(pacman.maze.largeur):
            for j in range(pacman.maze.longueur):
                scr.addstr(j, i, pacman.maze.get(i, j))
        scr.addstr(pacman.y, pacman.x, pacman.tronche)
        scr.addstr(
            pacman.maze.longueur, pacman.maze.largeur + 5,
            "Score plutôt que String toute entière : " + str(pacman.score))
        scr.refresh()

        c = scr.getch()
        if c == curses.KEY_UP:
            pacman.direction = Pacman.Up
        elif c == curses.KEY_DOWN:
            pacman.direction = Pacman.Down
        elif c == curses.KEY_LEFT:
            pacman.direction = Pacman.Left
        elif c == curses.KEY_RIGHT:
            pacman.direction = Pacman.Right
        elif c == curses.KEY_F1:
            return

        pacman.bouge()
Exemple #16
0
    def __init__(self, player_input, settings, screen):
        self.settings = settings
        self.screen = screen
        self.player_input = player_input

        self.pacman = Pacman(self)
        self.maze = Maze(self)
        self.scoreboard = Scoreboard(self)
Exemple #17
0
    def setUp(self):
        pm1 = Pacman(2, 3, "NORTH")
        pm2 = Pacman(1, 2, "WEST")
        pm3 = Pacman(2, 1, "SOUTH")
        pm4 = Pacman(3, 2, "EAST")

        self.list = [pm1, pm2, pm3, pm4]
        pass
Exemple #18
0
 def init_pacman(self):
     for i in range(len(self.matrix)):
         for j in range(len(self.matrix[i])):
             if self.matrix[i][j] == 5:
                 coords = (j * (self.width_block + SPACE_BLOCKS) -
                           SPACE_BLOCKS,
                           i * (self.height_block + SPACE_BLOCKS) -
                           SPACE_BLOCKS + self.top)
                 self.pacman = Pacman(coords, self.width_block)
Exemple #19
0
 def __init__(self,
              difficulty=4,
              gameMaze=GameMaze(randomMaze=True),
              score=0):
     object.__init__(self)
     self.difficulty = difficulty
     self.gameMaze = gameMaze
     self.ghosts = []
     self.pacman = Pacman((gameMaze.sizeX / 2, gameMaze.sizeY * 3 / 4),
                          score)
Exemple #20
0
 def __init__(self, init_data):
     self.init_data = json.loads(init_data)
     self.game = Pacman(
         seed=self.init_data["seed"],
         height=self.init_data["height"],
         width=self.init_data["width"],
         generator_interval=self.init_data["GENERATOR_INTERVAL"],
         large_fruit_duration=self.init_data["LARGE_FRUIT_DURATION"],
         large_fruit_enhancement=self.init_data["LARGE_FRUIT_ENHANCEMENT"],
         static=self.init_data["static"],
         content=self.init_data["content"])
Exemple #21
0
 def start_game(self):
     self.nodes = NodeGroup("Mazes/maze1.txt")
     self.pellets = PelletGroup("Mazes/maze1.txt")
     self.pacman = Pacman(self.nodes, self.sheet)
     self.ghosts = Ghosts(self.nodes, self.sheet)
     self.paused = True
     self.lifeIcons = Lives(self.sheet)
     self.maze = Maze(self.sheet)
     self.maze.get_maze("Mazes/maze1")
     self.maze.stitch_maze(self.background)
     self.pelletsEaten = 0
     self.switch_song(1)
Exemple #22
0
    def start_game(self):

        self.sheet = Spritesheet()
        self.nodes = NodeGroup("maze.txt")
        self.pellets = Pellets_Group("maze.txt")
        self.pacman = Pacman(self.nodes, self.sheet)
        self.ghosts = GhostGroup(self.nodes, self.sheet)
        self.life_icons = LifeIcon(self.sheet)
        self.paused = False
        self.maze = Maze(self.sheet)
        self.maze.get_maze("maze")
        self.maze.combine_maze(self.background)
Exemple #23
0
 def __init__(self):
     pygame.init()
     self.screen = pygame.display.set_mode((1200, 800))
     pygame.display.set_caption("Pacman Portal")
     # self.expandfile = ExpandFile('images/pacman_maze.txt', expandBy=3)
     self.maze = Maze(self.screen,
                      mazefile='images/pacman_maze_expanded_pts.txt',
                      brickfile='brick',
                      pointfile='point')
     self.pacman = Pacman(self.screen)
     self.pac_group = Group()
     self.ghosts = Ghosts(self.screen)
     self.play_button = Button(self.screen, "Play")
     self.stats = Stats()
class Game:
    BLACK = (0, 0, 0)

    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((900, 1000))
        pygame.display.set_caption("Pacman Portal")

        self.clock = pygame.time.Clock()

        self.expandfile = ExpandFile('mazefile.txt', expandBy=6)

        self.maze = Maze(self.screen, 'mazefile_expanded.txt', 'brick',
                         'orangeportal', 'blueportal', 'shield', 'point')

        self.gamestats = GameStats()

        self.pacmanGroup = Group()
        self.pacman = Pacman(self.screen)
        self.pacmanGroup.add(self.pacman)

    def play(self):
        pacman = self.pacman
        maze = self.maze
        ghost = []
        for i in range(1):
            g = Ghost(self.screen)
            g.type = i
            g.x += 30 * i
            g.prep_ghost()
            ghost.append(g)

        eloop = EventLoop(status=False)

        while not eloop.finished:
            eloop.check_events(pacman)
            eloop.update_screen(pacman)
            pacman.update(maze, self.gamestats, self.pacmanGroup)
            for i in range(1):
                ghost[i].blit()
            self.update_screen()

    def update_screen(self):
        self.screen.fill(Game.BLACK)
        self.maze.blitme()
        self.pacman.blitme()

        pygame.display.flip()
        self.clock.tick(120)
Exemple #25
0
class Game:

    settings: Settings

    def __init__(self):
        pygame.init()
        self.settings = Settings()
        self.settings.reset()
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        self.intro = Intro(self.screen, self.settings)
        self.menu = Menu(self.screen, self.settings)
        pygame.display.set_caption("Pacman Portal")

        self.maze = Maze(self.screen, mazefile='pacmap.txt')

        self.pacman = Pacman(self.screen)

        self.dashboard = Dashboard(self.screen)

        self.portal_enter = Portal("Enter", self.screen, self.settings)
        self.portal_exit = Portal("Exit", self.screen, self.settings)

        scoresheet = open('scoresheet.txt', 'r')
        self.settings.score_high = int(scoresheet.read())

    def __str__(self): return 'Game(Pacman Portal), maze=' + str(self.maze) + ')'

    def play(self):
        eloop = EventLoop(finished=False)
        while not eloop.finished:
            eloop.check_events(self.pacman, self.menu, self.portal_enter, self.portal_exit, self.settings)
            self.update_screen()

    def update_screen(self):
        self.screen.fill((0, 0, 0))
        if self.settings.mode == "Game":
            self.maze.check_pac_conditions(self.pacman, self.settings, self.portal_enter, self.portal_exit)
            self.maze.blitme(self.settings)
            self.pacman.blitme(self.settings)
            self.dashboard.blitme(self.settings)
            self.portal_enter.blitme()
            self.portal_exit.blitme()
        elif self.settings.mode == "Menu":
            self.menu.blitme()
            pass
        elif self.settings.mode == "Intro":
            self.intro.blitme()
        pygame.display.flip()
Exemple #26
0
    def reinit(self):
        self.pacman = Pacman(self, self.sprite_store.pacman, self.graph)  # Pac-man obj

        self.blinky_scatter_nodes = [self.graph.nodes[4], self.graph.nodes[5],
                                     self.graph.nodes[13], self.graph.nodes[12]]

        self.pinky_scatter_nodes = [self.graph.nodes[0], self.graph.nodes[6], self.graph.nodes[7], self.graph.nodes[1]]
        self.clyde_scatter_nodes = [self.graph.nodes[42], self.graph.nodes[43], self.graph.nodes[53],
                                    self.graph.nodes[54], self.graph.nodes[61], self.graph.nodes[60],
                                    self.graph.nodes[50], self.graph.nodes[51], self.graph.nodes[52]]

        self.inkey_scatter_nodes = [self.graph.nodes[46], self.graph.nodes[47], self.graph.nodes[57],
                                    self.graph.nodes[58], self.graph.nodes[59], self.graph.nodes[63],
                                    self.graph.nodes[62], self.graph.nodes[55], self.graph.nodes[56]]

        # 1. Blinky obj (Enemy00)
        self.blinky = Enemy(self, self.sprite_store.blinky, self.graph, self.blinky_scatter_nodes)
        # 2. Pinky  obj (Enemy01)
        self.pinky = Enemy(self, self.sprite_store.pinky, self.graph, self.pinky_scatter_nodes)
        # 3. Clyde  obj (Enemy02)
        self.clyde = Enemy(self, self.sprite_store.clyde, self.graph, self.clyde_scatter_nodes)
        # 4. Inkey  obj (Enemy03)
        self.inkey = Enemy(self, self.sprite_store.inkey, self.graph, self.inkey_scatter_nodes)

        self.inkey_ticks = pg.time.get_ticks()
        self.pinky_ticks = pg.time.get_ticks()
        self.clyde_ticks = pg.time.get_ticks()
        self.blinky_ticks = pg.time.get_ticks()

        for enemy in self.enemies:
            enemy.has_enemy_exited_room = False

        self.blinky.current_state = 'scattered'
        self.pinky.current_state = 'scattered'
        self.clyde.current_state = 'scattered'
        self.inkey.current_state = 'scattered'

        self.enemies = []                                       # List of Enemy obj's
        self.enemies.append(self.blinky)  # Add enemies to list
        self.enemies.append(self.pinky)
        self.enemies.append(self.clyde)
        self.enemies.append(self.inkey)

        self.pacman.rect.centerx = self.graph.nodes[65].x  # Set Pac-man to node 65
        self.pacman.rect.centery = self.graph.nodes[65].y
        self.pacman.adj_node = self.graph.nodes[65]

        self.initialize_enemies()
Exemple #27
0
 def __init__(self, solutionFilePath, logFilePath, height, width,
              pillDensity, wallDensity, fruitProbability, fruitScore,
              timeMultiplier):
     self.pacman1 = Pacman(0, height - 1)
     self.ghost1 = Ghost(width - 1, 0, 1)
     self.ghost2 = Ghost(width - 1, 0, 2)
     self.ghost3 = Ghost(width - 1, 0, 3)
     self.solutionFilePath = solutionFilePath
     self.logFilePath = logFilePath
     self.height = height
     self.width = width
     self.pillDensity = pillDensity
     self.wallDensity = wallDensity
     self.fruitProbability = fruitProbability
     self.fruitScore = fruitScore
     self.timeMultiplier = timeMultiplier
     self.time = timeMultiplier * width * height
     self.grid = [[]]
     self.hasFruit = False
     self.logger = Logger(self.solutionFilePath, self.logFilePath)
     self.numPills = 0  #pills pacman currently has
     self.totalPills = 0
     self.didSpawn = False
     self.fruitx = -1  #fruit position
     self.fruity = -1
     self.solution = []
Exemple #28
0
def init(data):
    # load data.xyz as appropriate
    data.maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0],
                 [0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0],
                 [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0],
                 [0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0],
                 [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0],
                 [0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0],
                 [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0],
                 [0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0],
                 [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    data.gameOver = False
    data.timer = 0
    data.cellSize = 30
    data.board = Board(data.maze)
    data.rows, data.cols = len(data.maze), len(data.maze[0])
    #moves by width and height of each cell
    data.speedX, data.speedY = data.cellSize, data.cellSize
    data.counter = 0
    data.directions = ['up', 'down', 'left', 'right']
    data.mdirection = 'right'
    data.direction = 'Right'
    data.pacman = Pacman(data.cols // 2 - 1, data.rows // 2 - 1, data)
    data.center = None
    data.lives = 3
    data.score = 0
    data.monsterCenter = 0, 1
    data.monster = Monster(data)
    data.food = copy.deepcopy(data.maze)
Exemple #29
0
    def check_play(self, mouse_x, mouse_y):
        """Checks if play button is pressed"""
        button_clicked = self.play.rect2.collidepoint(mouse_x, mouse_y)
        if button_clicked and not self.stats.game_active:
            self.settings.music.play()
            pygame.mouse.set_visible(False)
            # Reset the game statistics
            self.stats.reset_stats()
            self.stats.game_active = True
            # Reset the scoreboard image
            self.sb.prep_score()
            self.sb.prep_level()
            self.sb.prep_pacmen()

            self.pac.empty()
            self.points.empty()
            self.pills.empty()
            self.fruits.empty()
            self.ghosts.empty()

            self.maze.build()
            self.maze.build_points()
            self.pacman = Pacman(self.screen, self.settings, self.maze,
                                 self.portal, self.stats)
            self.pac.add(self.pacman)
            EventLoop.create_ghosts(self)
Exemple #30
0
    def startGame(self):
        #Sets up the game

        self.level.reset()
        levelmap = self.level.getLevel()
        self.maze.getMaze(levelmap["mazename"].split(".")[0])
        self.maze.constructMaze(self.background)
        self.nodes = NodeGroup(levelmap["mazename"])
        self.pellets = PelletGroup(levelmap["pelletname"])
        self.pacman = Pacman(self.nodes, self.sheet)
        #self.ghosts = GhostGroup(self.nodes, self.sheet)  Ghost command, removed to get rid of ghosts
        self.pelletsEaten = 0
        self.fruit = None
        self.pause.force(False)  #Was True, set to false for automatic start
        self.gameover = False
        self.score = 0
Exemple #31
0
 def __init__(self):
     pygame.init()
     self.set = Settings()
     self.screen = pygame.display.set_mode((600, 720))
     pygame.display.set_caption('Pacman')
     self.stats = GameStats(self.set)
     # Create a pacman object to pass to maze
     #sb = Scoreboard(set, self.screen, stats, self.maze)
     self.play_button = Button(self.screen, "Start munchin'")
     # Give files needed to populate the maze
     self.expandfile = ExpandFile('test.txt', expandBy=2)
     self.maze = Maze(self.screen, 'newtest.txt', 'images/purptile4',
                      'images/foodPellet', 'B1', 'C/CL1', 'I/I1', 'P/P1')
     self.intro = pygame.mixer.Sound("sounds/pacman_beginning.wav")
     self.sb = Scoreboard(self.set, self.screen, self.stats, self.maze)
     self.player = Pacman(self.screen, self.maze, self.sb)
Exemple #32
0
 def prep_ships(self):
     self.pacmans = Group()
     for ship_number in range(self.stats.ships_left + 1):
         pacman = Pacman(self.screen, self.maze, self)
         pacman.rect.x = 10 + ship_number * pacman.rect.width
         pacman.rect.y = 10
         self.pacmans.add(pacman)
Exemple #33
0
 def test_point_collect_points(self):
     self.game.point_count = 86
     test_pacman = Pacman(40, 460, False, False, True)
     hit = self.point.collect_points(self, test_pacman, self.game.points)
     self.game.point_count += hit
     self.game._get_points()
     self.assertEqual(self.game.game_win, True)
Exemple #34
-1
 def setUp(self):
     self.pacman = Pacman()