Esempio n. 1
0
    def test_start_visited(self):
        maze = Maze(10, 10)
        create(maze)

        for x in range(0, len(maze[0])):
            if maze[0][x].getVisited() == False:
                assert maze[0][x].getVisited() == False
Esempio n. 2
0
    def test_starting_position(self):
        maze = Maze(10, 10)
        create(maze)

        for x in range(0, len(maze[0])):
            if maze[0][x].getElement() == ' ':
                assert maze[0][x].getElement() == ' '
Esempio n. 3
0
    def test_end_visited(self):
        maze = Maze(10, 10)
        create(maze)
        lastrow = len(maze) - 1

        for x in range(0, len(maze[lastrow])):
            if maze[lastrow][x].getElement() == ' ':
                assert maze[lastrow][x].getVisited() == True
def mm_maze_create(size):
    w, h = size.split('x')
    w, h = int(w), int(h)

    if w < 5 or h < 5:
        w, h = 5, 5

    maze = Maze(w, h)
    create(maze)
    bank.push(maze)

    print(messages("maze_created"))
    menu()
Esempio n. 5
0
 def test_cell_get_element_pound(self):
     maze = Maze(10, 10)
     assert maze[1][1].getElement() == '#'
Esempio n. 6
0
 def test_cell_get_y(self):
     maze = Maze(10,10)
     assert maze[6][4].getY() == 6
Esempio n. 7
0
 def test_width(self):
     maze = Maze(20, 5)
     assert maze.getCols() == 20
Esempio n. 8
0
 def test_cell_get_x(self):
     maze = Maze(10,10)
     assert maze[4][3].getX() == 3
Esempio n. 9
0
 def test_height(self):
     maze = Maze(5, 50)
     assert maze.getRows() == 50
Esempio n. 10
0
 def test_maze_fill_space(self):
     maze = Maze(5, 5)
     assert maze[4][4].getElement() != ' '
Esempio n. 11
0
 def test_cell_get_visited_true(self):
     maze = Maze(10, 10)
     maze[1][1].setVisited(True)
     assert maze[1][1].getVisited() == True
Esempio n. 12
0
 def test_maze_set_name(self):
     maze = Maze(5, 5)
     maze.setName("Testing")
     assert maze.getName() == "Testing"
Esempio n. 13
0
 def test_maze_fill_pound(self):
     maze = Maze(5, 5)
     assert maze[0][0].getElement() == '#'
Esempio n. 14
0
 def test_maze_get(self):
     maze = Maze(5, 5)
     assert isinstance(maze[0][0], Cell)
Esempio n. 15
0
 def test_maze_name(self):
     maze = Maze(5, 5)
     assert maze.getName() == "MAZE_5x5"
Esempio n. 16
0
 def test_min_height(self):
     maze = Maze(2, 2)
     assert maze.getRows() == 5
Esempio n. 17
0
 def test_cell_get_element_space(self):
     maze = Maze(10, 10)
     maze[1][1].setElement(' ')
     assert maze[1][1].getElement() == ' '
Esempio n. 18
0
 def test_maze_image_null(self):
     maze = Maze(5, 5)
     assert maze.getMazeImage() == []
Esempio n. 19
0
 def test_cell_get_visited_false(self):
     maze = Maze(10, 10)
     assert maze[1][1].getVisited() == False
Esempio n. 20
0
 def __init__(self):
     self.maze = Maze('level/maze.txt')
Esempio n. 21
0
 def test_cell_neighbours(self):
     maze = Maze(10,10)
     assert maze[1][1].findUnvisited(maze)
 def __init__(self):
     self.maze = Maze()
     self.game_result = 0  # win_game = 1 and lose_game = 2
     self._initialisation()
     self.play_game()  # game management
Esempio n. 23
0
 def test_maze_eimage_null(self):
     maze = Maze(5, 5)
     assert maze.getMazeEnhancedImage() == []
Esempio n. 24
0
 def test_min_width(self):
     maze = Maze(2, 2)
     assert maze.getCols() == 5
Esempio n. 25
0
 def test_maze_len(self):
     maze = Maze(5, 10)
     assert len(maze) == 10
class Game:
    """
        This class manages the animation
        and the graphics part of the program
    """
    def __init__(self):
        self.maze = Maze()
        self.game_result = 0  # win_game = 1 and lose_game = 2
        self._initialisation()
        self.play_game()  # game management

    def display_maze_game(self):
        """ displays the items of maze after each movement of MacGyver """
        # the sleep mode wil be actived at the end of game
        sleep = False
        # display the background in the window "fenetre"
        self.fenetre.blit(self.fond_pic, (0, 0))
        # display MacGyver in the window "fenetre"
        self.fenetre.blit(self.macgyver_pic, self.macgyver_pic_position)

        # display differents items of the maze in the window "fenetre"
        for (coords, element) in self.maze.grid.items():
            if element == "w":  # "w" is equivalent to a wall
                self.fenetre.blit(self.mur_pic,
                                  (coords[0] * 40, coords[1] * 40))
            elif element == "G":  # "G" is equivalent to the Guardian
                # game_result != 0 => "end of game" => no more Guardian
                if self.game_result == 0:
                    self.fenetre.blit(self.guardian_pic,
                                      (coords[0] * 40, coords[1] * 40))
            elif element == "needle":
                self.fenetre.blit(self.needle_pic,
                                  (coords[0] * 40, coords[1] * 40))
            elif element == "tube":
                self.fenetre.blit(self.tube_pic,
                                  (coords[0] * 40, coords[1] * 40))
            elif element == "ether":
                self.fenetre.blit(self.ether_pic,
                                  (coords[0] * 40, coords[1] * 40))

        if self.game_result == 1:  # if the player win
            self.fenetre.blit(self.win_pic, (40, 10))
            # actives the sleep mode
            sleep = True
        elif self.game_result == 2:  # if the player lose
            self.fenetre.blit(self.game_over_pic, (0, 0))
            # actives the sleep mode
            sleep = True
        display.flip()  # Screen refresh
        # maintains display for a few seconds after the game ends
        if sleep:
            time.sleep(DELAY)

    def play_game(self):
        """ detects pressing the keyboard's arrows,
            calculates new coordinates of MacGyver and moves him
        """
        # movement when an arrow is held down
        key.set_repeat(FAST[0], FAST[1])

        # this loop continues while game_result == 0
        while self.game_result == 0:
            # browses the list of all the events received
            for evt in event.get():

                if evt.type == QUIT:  # if an event is "QUIT"
                    pygame.quit()  # deactivates the Pygame library
                    exit()  # stop the game

                if evt.type == KEYDOWN:
                    self.test_destination_after_keydown(evt.key)

            self.display_maze_game()

    def test_destination_after_keydown(self, eventkey):
        """ tests the destination after "KEYDOWN" """
        # corresponding movement in the game
        mouvements = {
            K_DOWN: (0, STEP_MOV),
            K_UP: (0, -STEP_MOV),
            K_RIGHT: (STEP_MOV, 0),
            K_LEFT: (-STEP_MOV, 0)
        }
        # corresponding movement in the Maze class
        mvt_in_maze = {
            K_DOWN: "bottom",
            K_UP: "top",
            K_RIGHT: "right",
            K_LEFT: "left"
        }
        try:
            # calculate new coordinates
            # of MacGyver in the Maze class
            x_new, y_new = self.maze.macgyver.move_to(mvt_in_maze[eventkey])
            # tests if destination is ok
            if self.maze.test_destination_is_valid(x_new, y_new):
                # assigns news coordinates to MacGyver
                # after displacement and collects
                # if an object is on the new cell
                self.maze.consequences_macgyver_displacement(x_new, y_new)

                # tests presence of "Guardian" for news coordinates
                if self.maze.test_presence_of_guardian(x_new, y_new):
                    # tests if MacGyver has collect
                    # all objects to win
                    if sorted(self.maze.macgyver.bag) == \
                            ['ether', 'needle', 'tube']:
                        self.game_result = 1  # it's wined
                    else:
                        self.game_result = 2  # it's lost
                # calculate new position of Angus
                # after "event.key"
                self.macgyver_pic_position = \
                    self.macgyver_pic_position.move(
                        mouvements[eventkey])
        except KeyError:
            print("PAS LA BONNE TOUCHE !!!")

    def _initialisation(self):

        pygame.init()

        # path to graphics resources
        os.chdir("c:/Users/utilisateur/Desktop/Formation_OpenClassRoom/"
                 "Projet_3/Projet/Ressources_graphiques")

        # creates a window to put in items of the maze
        self.fenetre = display.set_mode((600, 600))

        # loads the differents pics of the maze
        self.fond_pic = image.load("fond_mcg.jpg").convert()
        self.mur_pic = image.load("mur.png").convert()
        self.macgyver_pic = image.load("macgyver.png").convert_alpha()
        self.guardian_pic = image.load("gardien.png").convert_alpha()
        self.needle_pic = image.load("seringue.png").convert_alpha()
        self.tube_pic = image.load("tube_plastique.png").convert_alpha()
        self.ether_pic = image.load("ether.png").convert_alpha()

        self.win_pic = image.load("win.png").convert_alpha()
        self.game_over_pic = image.load("game_over.png").convert_alpha()

        # calculates the coordinates of MacGyver \
        #  which will change during the play
        self.macgyver_pic_position = self.macgyver_pic.get_rect()
        self.macgyver_pic_position = self.macgyver_pic_position.move(
            self.maze.macgyver.x * 40, self.maze.macgyver.y * 40)