class GameText:
    """ Sets GameText class.

    The GameText class consists of 2 methods :
        - __init__()
        - run()

    """
    def __init__(self, json_file="labyrinth.json"):
        """ GameText constructor.

        Instantiates objects from Labyrinth, MacGyver and Syringe classes.

        """
        self.labyrinth = Labyrinth(json_file)
        self.macgyver = MacGyver(self.labyrinth)
        self.syringe = Syringe(self.labyrinth)

    def run(self):
        """ Manages the game progress.

        Sets :
            "carry_on" boolean variable
            user interaction
            labyrinth display

        """
        carry_on = True
        print("\nHelp MacGyver to escape from the labyrinth : he needs to pick\
 up a needle, a tube and ether before fighting the guard !")
        while carry_on:
            self.labyrinth.display()
            user_answer = input("In which direction do you want MacGyver to \
move ? Please enter 'u' for up, 'd' for down, 'l' for left and 'r' for \
right, or 'q' to quit : ")
            success = None
            if user_answer not in ["q", "u", "d", "l", "r"]:
                print("\nInvalid choice !")
                continue
            elif user_answer == "q":
                carry_on = False
            else:
                success = self.macgyver.move(user_answer)
                # 'success' becomes True or False after fighting the guard
                if success is not None:
                    carry_on = False
                    self.labyrinth.display()
Exemple #2
0
def main():
    labyrinth = Labyrinth()
    labyrinth.load_labyrinth_from_file("labyrinth.txt")
    macgyver = MacGyver(labyrinth)

    running = True

    while running:
        print(labyrinth.display())

        response = input("Where do you want to go ? ( Q to quit the game)")
        if response == "q" or response == "Q":
            running = False
        elif response in ("h", "b", "d", "g"):
            macgyver.move(directions[response])
                elif event.type == KEYDOWN and event.key == K_F1:
                    # Labyrinth launch
                    continue_home = 0  # quitt home
                    continue_game = 'L1'  # Labyrinth launch
                    finish_game = 0
                    loop_loose = 0

        if continue_game != 0:
            # display background
            background = pygame.image.load(c.PICTURE_BACKGROUND).convert()

            # Generate a labyrinth from the file
            labyrinth = Labyrinth(continue_game)
            labyrinth.generate()
            labyrinth.display(window)

            # Create characteres
            mac_gyver = Character(c.PICTURE_MAC_GYVER_RIGHT,
                                  c.PICTURE_MAC_GYVER_LEFT,
                                  c.PICTURE_MAC_GYVER_UP,
                                  c.PICTURE_MAC_GYVER_DOWN, labyrinth)

            # Generat Items in labyrinth
            Item1 = Item(c.PICTURE_ETHER, labyrinth)
            Item2 = Item(c.PICTURE_NEEDLE, labyrinth)
            Item3 = Item(c.PICTURE_PLASTIC_TUBE, labyrinth)

            # display Items in labyrinth
            Item1.position(window, 'o1')
            Item2.position(window, 'o2')
def main():
    labyrinth = Labyrinth("labyrinth_test.json")
    syringe = Syringe(labyrinth)
    print("Syringe elements positions : ", syringe.positions)  # returns a list
    # of random available positions
    labyrinth.display()  # displays the labyrinth (with the syringe elements)