示例#1
0
    def close_claim(self, poly, speed, game):
        inside, outside = game_utils.cut_poly(self.game_area, poly)

        # we will triangulate only one of the guys
        # then we check if it is the bigger portion (last known area minus new)

        total_area = game_utils.total_area([self._start_game_area])
        prev_remaining = total_area - game.stats['claimed_area']

        rects_out = game_utils.triangulate(outside) or []

        qixes = [qix for qix in self.qix if not qix.claimed]
        # flip sides if the qix is not in the game area - can't claim
        # qix space
        claimed_qix = []
        for qix in qixes:
            if not game_utils.in_area((qix.x, qix.y), rects_out, on_line=True):
                claimed_qix.append(qix)

        claimed_area = prev_remaining - game_utils.total_area(rects_out)
        available_area = prev_remaining - claimed_area

        if (len(claimed_qix) > len(qixes) / 2.0) or (available_area < claimed_area and len(claimed_qix) >= len(qixes)):
            # outside normally should be bigger than inside
            # exception is when we have more qix on the smaller patch
            inside, outside = outside, inside
            rects_out = game_utils.triangulate(outside) or []
            claimed_area = prev_remaining - game_utils.total_area(rects_out)


        for qix in qixes:
            if not game_utils.in_area((qix.x, qix.y), rects_out, on_line=True):
                qix.claimed = True

        self.game_rects = rects_out
        self.game_area = outside
        self.game_area_path.points = outside

        claimed = sprites.ClaimedPoly(inside, speed)
        self.claimed_polys_containter.add_child(claimed)
        claimed.appear()
        self.claimed_polys.append((inside, 1))

        for qix in self.qix:
            # make sure they are not easing some place nasty
            qix.next_target()

        game.update_score(claimed_area, speed)
示例#2
0
文件: game.py 项目: jean/apx
    def __init__(self):
        gobject.GObject.__init__(self)

        maxx, maxy = 600, 500
        self.start_poly = [(0, 0), (maxx, 0), (maxx, maxy), (0, maxy), (0, 0)]
        self._total_area = game_utils.total_area([self.start_poly])

        self.level = 1
        self.level_stats = defaultdict(lambda: defaultdict(int))

        self.speed = 1  #: current game speed

        self.paused = False  #: paused by player
        self.claiming = False  #: currently trying to claim new teritory
        self.immortal = False  #: you cheat!
        self._prev_claim_time = dt.datetime.now()

        self.lives = 3