Exemple #1
0
    def __init__(self, window, sceneKey):
        # Save window and sceneKey in instance variables
        self.window = window
        self.sceneKey = sceneKey

        self.backgroundImage = pygwidgets.Image(self.window, (0, 0), "images/GameOverBackground.jpg")

        # The following will create a list of lists
        # Either by building a blank one from scratch, or by reading from a text file
        # The result will look like:
        # [[name, score], [name, score], [name, score] ...]
        # and will always be kept in order of the score (highest to lowest)
        if not SceneManager.fileExists(SceneGameOver.DATA_FILE_PATH):
            self.setEmptyGameOver()
        else:
            data = SceneManager.readFile(SceneGameOver.DATA_FILE_PATH)
            # read in all the data in json format, converts to a list of lists
            self.scoresList = json.loads(data)

        self.scoresField = pygwidgets.DisplayText(self.window, (25, 84), '', \
                                fontSize=48, textColor=BLACK, width=175, justified='right')
        self.namesField = pygwidgets.DisplayText(self.window, (260, 84), '', \
                                fontSize=48, textColor=BLACK, width=300, justified='left')

        self.quitButton = pygwidgets.TextButton(self.window, (30, 650), 'Quit')
        self.resetScoresButton = pygwidgets.TextButton(self.window, (240, 650), 'Reset high scores')
        self.startNewGameButton = pygwidgets.TextButton(self.window, (450, 650), 'Start new game')

        self.showGameOver()
Exemple #2
0
    def __init__(self, window, sceneKey):
        # Save window and sceneKey in instance variables
        self.window = window
        self.sceneKey = sceneKey

        # Set background
        self.backgroundImage = pygwidgets.Image(
            self.window, (0, 0), "images/GameOverBackground.jpg")

        # Read/load game data
        if not SceneManager.fileExists(SceneGameOver.DATA_FILE_PATH):
            pass
        else:
            data = SceneManager.readFile(SceneGameOver.DATA_FILE_PATH)
            # read in all the data in json format, converts to a list of lists
            self.scoresList = json.loads(data)


        self.deathCount = pygwidgets.DisplayText(self.window, (25, 84), 'Deaths: ', \
                                fontSize=48, textColor=DARKVIOLET, width=175, justified='right')
        # + str(nameScoreList[1]),\
        self.deathMessage = pygwidgets.DisplayText(self.window, (260, 84), 'YOU DIED', \
                                fontSize=48, textColor=DARKVIOLET, width=300, justified='left')

        self.quitButton = pygwidgets.TextButton(self.window, (30, 650), 'Quit')
        self.startNewGameButton = pygwidgets.TextButton(
            self.window, (450, 650), 'Try Again')