Exemple #1
0
    def explodeGame(self):
        """
        Make an explosion effect on the screen as the grid is destroyed.
        """

        # obtain the size of the playing area
        size = (self.gridContainer.get_allocated_width(),
                self.gridContainer.get_allocated_height())

        # make the explosion flashImage
        flashImage = getImage('Explosion')
        updateImage(flashImage, 'Explosion', size)
        self.gridContainer.add_with_viewport(flashImage)

        # flash the explosion 5 times
        for i in range(5):

            # display the explosion
            updateImage(self.startImage, 'Click', TOOL_SIZE)
            flashImage.show()
            pause(100)  # wait 200ms without blocking the Gtk event loop

            # hide the explosion
            updateImage(self.startImage, 'Lose', TOOL_SIZE)
            flashImage.hide()
            pause(100)  # wait 200ms without blocking the Gtk event loop

        # ... then destroy the explosion image
        flashImage.destroy()
Exemple #2
0
    def leftMouse(self, widget):
        """
        Left-Mouse handler. We use this to clear the area.
        """

        # action exclusions
        if self.flagged:
            if widget == self and not self.parent.exploded:
                self.set_active(False)  # TODO: not sure why this works
                updateImage(self.parent.parent.startImage, 'Start', TOOL_SIZE)
            return False
        if self.exposed or self.exploded:
            return False

        # disable the button and change its colour once it has been left-clicked
        self.set_sensitive(False)
        if not self.parent.exploded: self.set_active(True)

        exposedNeighbours = 0

        # end game - we hit a mine - lose
        if self.mined:
            self.exploded = True

            # choose the image
            if self.parent.exploded:  # cleardown mode
                self.imageKey = 'UXB'
            else:  # normal mode
                self.set_active(True)
                self.imageKey = 'Explosion'  # lose

            updateImage(self.image, self.imageKey, self.imageSize)

            # short pause to let gtk events sort themselves out
            if not self.parent.exploded:
                pause(200)
                self.parent.exploded = True  # notify end-game

        else:  # expose the button, display the number of neighbour mines
            self.exposed = True

            # update the image
            self.imageKey = 'Empty'
            if self.neighbourMines > 0:
                self.imageKey = str(self.neighbourMines)
            updateImage(self.image, self.imageKey, self.imageSize)

            # propagate exposure to the neighbours if mines = flags
            if self.neighbourFlags == self.neighbourMines:
                for neighbour in self.neighbourList:
                    exposedNeighbours += neighbour.leftMouse(widget)

        # update count of exposed buttons - potential win end game
        exposedNeighbours += 1  # add self to the count
        if widget == self:
            self.parent.incrementExposedCount(exposedNeighbours)

            # reset the start button image
            if not self.parent.gameOver:
                updateImage(self.parent.parent.startImage, 'Start', TOOL_SIZE)

        else: return exposedNeighbours