コード例 #1
0
    def read_file(self):
        if "level" in self.metadata.keys():
            data = {
                "level": int(self.metadata["level"]),
                "difficulty": int(self.metadata["difficulty"]),
                "correct": [int(x) for x in eval(self.metadata["correct"])],
                "balls": {}
            }

            balls = eval(self.metadata["balls"])
            for key in balls:
                x = int(key)
                data["balls"][x] = []

                for value in balls[key]:
                    y = int(value)
                    data["balls"][x].append(y)

            current = []
            for x in range(0, get_columns_for_difficulty(data["difficulty"])):
                current.append(data["balls"][x][data["level"]])

            self.ok_button.set_sensitive(not BallType.NULL in current)

        else:
            data = {
                "level": 0,
                "difficulty": Difficulty.MEDIUM,
                "correct": None,
                "balls": {}
            }

            columns = get_columns_for_difficulty(data["difficulty"])

            for x in range(0, columns):
                data["balls"][x] = [BallType.NULL] * 10

            self.ok_button.set_sensitive(False)

        if data["difficulty"] == Difficulty.EASY:
            self.easy_button.set_active(True)

        elif data["difficulty"] == Difficulty.MEDIUM:
            self.medium_button.set_active(True)

        elif data["difficulty"] == Difficulty.ADVANCED:
            self.advanced_button.set_active(True)

        elif data["difficulty"] == Difficulty.EXPERT:
            self.expert_button.set_active(True)

        self.canvas.set_game_data(data)
コード例 #2
0
    def reset(self, difficulty=None):
        if difficulty is not None:
            self.difficulty = difficulty

        self.clear()

        x = -1
        y = 0

        columns = get_columns_for_difficulty(self.difficulty)

        for i in range(0, columns * 10):
            x += 1

            if x >= columns:
                x = 0
                y += 1

            box = BallBox()
            self.attach(box, x, y, 1, 1)

            self.balls[x][9 - y] = box

        for i in range(0, 10):
            box = ResultBox(columns)
            self.attach(box, columns, 9 - i, 1, 1)
            self.result_boxes.append(box)

        self.set_drag_level()
        self.show_all()
コード例 #3
0
    def set_all_data(self, data):
        self.difficulty = data["difficulty"]
        self.clear()

        self.level = data["level"]
        columns = get_columns_for_difficulty(self.difficulty)

        for x in range(0, columns):
            for y in range(0, 10):
                ballid = data["balls"][x][y]
                ball = BallBox()
                ball.set_ball(ballid)
                self.attach(ball, x, 9 - y, 1, 1)
                self.balls[x][y] = ball

        self.set_drag_level()

        for i in range(0, 10):
            box = ResultBox()
            self.attach(box, columns, 9 - i, 1, 1)
            self.result_boxes.append(box)

            if i < self.level:
                user = []
                for x in range(0, columns):
                    user.append(data["balls"][x][i])

                box.set_data(data["correct"], user)

        self.show_all()
コード例 #4
0
ファイル: canvas.py プロジェクト: quozl/mastermind-activity
    def reset(self):
        self.make_level()
        self.grid.reset(self.difficulty)
        self.originbox.reset(self.difficulty)

        balls = [BallType.NULL] * get_columns_for_difficulty(self.difficulty)
        self.emit("data-changed", balls)
コード例 #5
0
    def get_level_data(self):
        level = []
        if self.level < 10:
            for x in range(0, get_columns_for_difficulty(self.difficulty)):
                ball = self.balls[x][self.level]
                level.append(ball.ball)

        return level
コード例 #6
0
    def get_all_data(self):
        data = {"level": self.level, "balls": {}}

        for x in range(0, get_columns_for_difficulty(self.difficulty)):
            data["balls"][x] = []
            for y in range(0, 10):
                data["balls"][x].append(self.balls[x][y].ball)

        return data
コード例 #7
0
ファイル: canvas.py プロジェクト: quozl/mastermind-activity
    def make_level(self):
        del self.level
        self.level = []

        for x in range(0, get_columns_for_difficulty(self.difficulty)):
            ball = get_random_ball(self.difficulty)
            while ball in self.level:
                ball = get_random_ball(self.difficulty)

            self.level.append(ball)
コード例 #8
0
    def set_drag_level(self):
        self.clear_callbacks()

        for x in range(0, get_columns_for_difficulty(self.difficulty)):
            for y in range(0, 10):
                ball = self.balls[x][y]
                ball.set_dest_drag(y == self.level)
                ball.set_draggable(y == self.level
                                   and ball.ball != BallType.NULL)

                if y == self.level:
                    idx = ball.connect("id-changed", self._id_changed_cb)
                    self.callbacks_ids[idx] = ball
コード例 #9
0
    def clear(self):
        for x in self.balls.keys():
            for ball in self.balls[x]:
                if ball is not None:
                    self.remove(ball)

                del ball

        for box in self.result_boxes:
            self.remove(box)
            del box

        del self.balls
        del self.result_boxes

        self.balls = {}
        self.result_boxes = []
        self.level = 0

        self.clear_callbacks()

        for x in range(0, get_columns_for_difficulty(self.difficulty)):
            self.balls[x] = [None] * 10