Exemplo n.º 1
0
class Puzzle:
    tiles_positioned_correct = 0  # a counter how many tiles guessed correctly.In the begining 0 tiles guessed right.
    sounds, winsounds = init("sounds")
    clock = pygame.time.Clock()
    photo = None
    width = 0
    height = 0
    screen = None
    bar = None
    BLACKTILE = None

    @staticmethod
    def setValues():
        global imageSelected
        Puzzle.photo = pygame.image.load(imageSelected)
        Puzzle.width, Puzzle.height = Puzzle.photo.get_size()
        Puzzle.width = floor(Puzzle.width)
        Puzzle.height = floor(Puzzle.height)
        Puzzle.screen = pygame.display.set_mode(
            (Puzzle.width * 3 - Puzzle.width // 2 + 14, Puzzle.height))
        pygame.display.set_caption("Puzzle-mania 3.1")
        Puzzle.photo.convert()
        Puzzle.bar = pygame.Surface((7, Puzzle.height))
        Puzzle.bar.fill(harmonic_color(Puzzle.photo))
        Puzzle.BLACKTILE = (harmonic_color(Puzzle.photo))
Exemplo n.º 2
0
    class Puzzle:
        tiles_fixed = 0
        score = 0
        sounds, winsounds = init(sound_path)
        image = pygame.image.load(choice(glob(image_path + "\\*.png")))
        w, h = image.get_size()
        w = floor(w)
        h = floor(h)
        screen = pygame.display.set_mode((w * 3 - w // 2 + 14, h))
        pygame.display.set_caption("Puzzle-mania 2.6")
        image.convert()
        bar = pygame.Surface((7, h))
        bar.fill(harmonic_color(image))
        clock = pygame.time.Clock()
        font = pygame.font.SysFont("Arial", 24)
        font2 = pygame.font.SysFont("Arial", 20)
        # pygame.event.set_grab(True)
        maxscore = 0
        ### colors
        BLACKTILE = (harmonic_color(image))

        def __init__(self, file):
            self.file = file
            self.load_maxscore()

        def file_is_empty(self):
            "If a file is empty True"
            with open(self.file, "r") as file_check:
                f = file_check.read()
            if f == "":
                return True
            else:
                return False

        def savescore(self):
            if int(Puzzle.score) > int(Puzzle.maxscore):
                self.write_maxscore(str(int(Puzzle.score)))

        def write_maxscore(self, score):
            "Write in the score.txt file"
            with open(self.file, "w") as file:
                file.write(str(score))
                Puzzle.maxscore = score

        def read_maxscore(self):
            with open(self.file, "r") as file_saved:
                last_maxscore = int(file_saved.read())
                print("Maxscore = " + str(last_maxscore))
                return last_maxscore

        def file_exists(self):
            "Check if file exists"
            if self.file in os.listdir():
                return True
            else:
                return False

        def first_score(self):
            "Create a new file for the score"
            self.write_maxscore("10")

        def load_maxscore(self):
            ''' check if a file exists
                    if exists
                        if is empty: it writes 10 in it
                        else it reads the score as an integer
                    else: create and write 10
            '''
            if self.file_exists():
                if not self.file_is_empty():
                    # This reads the score and put in Puuzzle.maxscore
                    Puzzle.maxscore = int(self.read_maxscore())
                else:
                    self.first_score()
            else:
                self.first_score()