Beispiel #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()
Beispiel #2
0
    def __init__(self, window):
        self.window = window
        self.oDeck = Deck(self.window)
        self.score = 100
        self.scoreText = pygwidgets.DisplayText(window, (450, 164),
                                                'Score: ' + str(self.score),
                                                fontSize=36,
                                                textColor=WHITE,
                                                justified='right')
        self.messageText = pygwidgets.DisplayText(window, (50, 460),
                                                  '',
                                                  width=900,
                                                  justified='center',
                                                  fontSize=36,
                                                  textColor=WHITE)
        self.loserSound = pygame.mixer.Sound("sounds/loser.wav")
        self.winnerSound = pygame.mixer.Sound("sounds/ding.wav")
        self.cardShuffleSound = pygame.mixer.Sound("sounds/cardShuffle.wav")

        self.cardXPositionsList = []
        thisLeft = Game.CARDS_LEFT
        # Calculate the x positions of all cards ... once
        for i in range(Game.NCARDS):
            self.cardXPositionsList.append(thisLeft)
            thisLeft = thisLeft + Game.CARD_OFFSET
        self.reset()  # start a round of the game
    def __init__(self, window):
        # Save window in instance variables
        self.window = window

        self.backgroundImage = pygwidgets.Image(self.window, (0, 0),
                                                "images/gridBG.png")
        self.dialogImage = pygwidgets.Image(self.window, (150, 30),
                                            "images/score.jpg")

        self.quitButton = pygwidgets.TextButton(self.window, (270, 420),
                                                'Quit')
        self.restartButton = pygwidgets.TextButton(self.window, (570, 420),
                                                   'Restart')

        self.clicksField = pygwidgets.DisplayText(self.window, (500, 223),
                                                  '',
                                                  fontSize=30)
        self.hitsField = pygwidgets.DisplayText(self.window, (500, 250),
                                                '',
                                                fontSize=30)
        self.missesField = pygwidgets.DisplayText(self.window, (500, 278),
                                                  '',
                                                  fontSize=30)
        self.missedTargetsField = pygwidgets.DisplayText(self.window,
                                                         (500, 306),
                                                         '',
                                                         fontSize=30)
        self.scoreField = pygwidgets.DisplayText(self.window, (500, 362),
                                                 '',
                                                 fontSize=30)
Beispiel #4
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')
Beispiel #5
0
    def __init__(self, window):
        '''
        This method is called when the scene is created
        Create and/or load any assets (images, buttons, sounds)
        that you need for this scene
        :param window:
        '''
        # Save window in instance variable
        self.window = window

        # 4 - Load assets: image(s), sounds,  etc.
        self.oGrid = Grid(window)
        self.oPlayer = Player(window)
        self.oBackground = pygwidgets.Image(window, (0, 0), 'images/background.jpg')
        self.oLevelDisplay = pygwidgets.DisplayText(window, (20, 15), '', fontSize=28)
        self.oLivesDisplay = pygwidgets.DisplayText(window, (120, 15), '', fontSize=28)
        self.oScoreDisplay = pygwidgets.DisplayText(window, (220, 15), '', fontSize=28)
        self.oBonusDisplay = pygwidgets.DisplayText(window, (350, 15), '', fontSize=28, textColor=(0, 153, 0))

        self.dingSound = pygame.mixer.Sound('sounds/ding.wav')
        self.winSound = pygame.mixer.Sound('sounds/win.wav')
        self.upSound = pygame.mixer.Sound('sounds/plus.wav')
        self.downSound = pygame.mixer.Sound('sounds/minus.wav')
        self.bonusSound = pygame.mixer.Sound('sounds/bonus.wav')
        self.splatSound = pygame.mixer.Sound('sounds/splat.wav')
        self.loseSound = pygame.mixer.Sound('sounds/lose.wav')
        self.state = ScenePlay.STATE_PLAYING
        self.oTimer = pyghelpers.Timer(.75, callBack=self.startNextRound) # wait 3/5 sec between rounds

        self.reset()
Beispiel #6
0
    def __init__(self, window, id, nRounds):
        self.id = id
        self.window = window
        self.pixelsPerCount = MAX_BAR_HEIGHT

        self.left = COLUMN_LEFT_START + (self.id * COLUMN_OFFSET)
        self.oBinLabel = pygwidgets.DisplayText(
            window, (self.left + 3, BAR_BOTTOM + 12),
            self.id,
            fontName='arial',
            fontSize=24,
            width=25,
            justified='center')
        self.oBinCount = pygwidgets.DisplayText(
            window, (self.left - 5, BAR_BOTTOM + 40),
            '',
            fontName='arial',
            fontSize=18,
            width=45,
            justified='center')
        self.oBinPercent = pygwidgets.DisplayText(
            window, (self.left - 5, BAR_BOTTOM + 60),
            '',
            fontName='arial',
            fontSize=18,
            width=50,
            justified='center')
        self.reset(nRounds)
Beispiel #7
0
    def __init__(self, window):

        self.window = window
        self.backgroundImage = pygame.image.load('images/background.png')
        self.dotImage = pygame.image.load('images/dot.png')
        self.arrowHuman = pygame.image.load('images/arrowHuman.png')
        self.arrowComputer = pygame.image.load('images/arrowComputer.png')
        self.humanImage = pygame.image.load('images/squareHuman.png')
        self.computerImage = pygame.image.load('images/squareComputer.png')
        self.dotLocList = []

        # Layout Dots
        for rowNum in range(0, NROWS + 1):
            for colNum in range(0, NCOLS + 1):
                thisX = STARTING_X + (BOX_AND_LINE_SIZE * colNum)
                thisY = STARTING_Y + (BOX_AND_LINE_SIZE * rowNum)
                self.dotLocList.append((thisX, thisY))

        self.oSquareMgr = SquareMgr(self.window)
        self.oLineMgr = LineMgr(self.window)
        self.humanScoreInGames = 0
        self.computerScoreInGames = 0

        self.humanScoreDisplay = pygwidgets.DisplayText(self.window,
                                                        (534, 185),
                                                        fontSize=36)
        self.computerScoreDisplay = pygwidgets.DisplayText(self.window,
                                                           (652, 185),
                                                           fontSize=36)
        self.humanGameScoreDisplay = pygwidgets.DisplayText(self.window,
                                                            (538, 326),
                                                            '0',
                                                            fontSize=24)
        self.computerGameScoreDisplay = pygwidgets.DisplayText(self.window,
                                                               (658, 326),
                                                               '0',
                                                               fontSize=24)
        self.winnerDisplay = pygwidgets.DisplayText(self.window, (500, 224),
                                                    'Test',
                                                    fontSize=36,
                                                    width=200,
                                                    justified='center')

        self.humanBlipSound = pygame.mixer.Sound('sounds/humanBlip.wav')
        self.computerBlipSound = pygame.mixer.Sound('sounds/computerBlip.wav')
        self.applauseSound = pygame.mixer.Sound('sounds/applause.wav')
        self.gameOverSound = pygame.mixer.Sound('sounds/gameOver.wav')
        self.mReset()
Beispiel #8
0
    def __init__(self, window):
        # Save window ain instance variable
        self.window = window

        #self.backgroundImage = pygwidgets.Image(self.window, (0, 0), "images/splashBackground.jpg")
        #self.frogGemsImage = pygwidgets.Image(self.window, (150, 30), "images/fromGems.png")


        self.startButton = pygwidgets.CustomButton(self.window, (250, 500), \
                                                   up='images/startNormal.png',\
                                                   down='images/startDown.png',\
                                                   over='images/startOver.png',\
                                                   disabled='images/startDisabled.png',\
                                                   enterToActivate=True)

        self.quitButton = pygwidgets.CustomButton(self.window, (30, 650), \
                                                   up='images/quitNormal.png',\
                                                   down='images/quitDown.png',\
                                                   over='images/quitOver.png',\
                                                   disabled='images/quitDisabled.png')

        self.highScoresButton = pygwidgets.CustomButton(self.window, (360, 650), \
                                                   up='images/gotoHighScoresNormal.png',\
                                                   down='images/gotoHighScoresDown.png',\
                                                   over='images/gotoHighScoresOver.png',\
                                                   disabled='images/gotoHighScoresDisabled.png')
        self.intro = pygwidgets.DisplayText(self.window, (30, 30), \
                                            'Welcome to FrogGems\n\n\n' + \
                                            'The object is to get to the water while\n' + \
                                            'collecting as many gems as you can, \n' + \
                                            'without getting squashed.\n\n' + \
                                            'If you grab all the gems on any screen,\n' + \
                                            'you get a bonus equal to the level number.\n\n'+ \
                                            'Every heart gives you an extra life.\n\n' + \
                                            'Good luck!', textColor=WHITE, fontSize=24, fontName='Arial')
Beispiel #9
0
def showCustomAnswerDialog(theWindow, theText):
    oDialogBackground = pygwidgets.Image(theWindow, (35, 450),
                                         'images/dialog.png')
    oPromptDisplayText = pygwidgets.DisplayText(theWindow, (0, 480),
                                                theText,
                                                width=WINDOW_WIDTH,
                                                justified='center',
                                                fontSize=36)
    oUserInputText = pygwidgets.InputText(theWindow, (200, 550),
                                          '',
                                          fontSize=36,
                                          initialFocus=True)
    oNoButton = pygwidgets.CustomButton(theWindow, (65, 595),
                                        'images/noThanksNormal.png',
                                        over='images/noThanksOver.png',
                                        down='images/noThanksDown.png',
                                        disabled='images/noThanksDisabled.png')
    oYesButton = pygwidgets.CustomButton(theWindow, (330, 595),
                                         'images/addNormal.png',
                                         over='images/addOver.png',
                                         down='images/addDown.png',
                                         disabled='images/addDisabled.png')
    userAnswer = pyghelpers.customAnswerDialog(theWindow, oDialogBackground,
                                               oPromptDisplayText,
                                               oUserInputText, oYesButton,
                                               oNoButton)
    return userAnswer
    def __init__(self, window):
        self.window = window
        self.blockImage = pygame.image.load('images/oneBlock.png')
        self.line = pygame.image.load('images/line.png')
        self.lowestY = 490
        self.blockHeight = 30
        self.towerX = 220
        self.computerWins = 0
        self.humanWins = 0
        self.lineBottomY = self.lowestY + self.blockHeight
        self.lineTopY = self.lowestY - (
            (MAX_BLOCKS - 1) * self.blockHeight) - 3
        self.newGameButton = pygwidgets.TextButton(window, (360, 460),
                                                   'New Game',
                                                   width=100,
                                                   height=35)
        self.quitButton = pygwidgets.TextButton(window, (360, 400),
                                                'Quit',
                                                width=100,
                                                height=35)

        self.oneBlockButton = pygwidgets.CustomButton(window, (35, 230), up='images/oneBlock.png',\
                                                      over='images/OneBlockOver.png',\
                                                      down='images/OneBlockDown.png',\
                                                      disabled='images/OneBlockDisabled.png')
        self.twoBlocksButton = pygwidgets.CustomButton(window, (35, 300), up='images/twoBlocks.png', \
                                                       over='images/TwoBlocksOver.png', \
                                                       down='images/TwoBlocksDown.png', \
                                                       disabled='images/TwoBlocksDisabled.png')
        self.threeBlocksButton = pygwidgets.CustomButton(window, (35, 400), up='images/threeBlocks.png', \
                                                         over='images/ThreeBlocksOver.png', \
                                                         down='images/ThreeBlocksDown.png', \
                                                         disabled='images/ThreeBlocksDisabled.png')
        self.nBlocksDisplay = pygwidgets.DisplayText(window, (self.towerX, 530), '0 of ' + str(MAX_BLOCKS), \
                                               fontName='monospaces', fontSize=24, textColor=BLACK)
        self.messageDisplay = pygwidgets.DisplayText(window, (10, 572), '', \
                                                       fontName='monospaces', fontSize=28, textColor=BLACK)
        self.humanWinsDisplay = pygwidgets.DisplayText(window, (360, 230), 'Player:     0', \
                                               fontName='monospaces', fontSize=28, textColor=BLACK)
        self.computerWinsDisplay = pygwidgets.DisplayText(window, (360, 300), 'Computer: 0', \
                                               fontName='monospaces', fontSize=28, textColor=BLACK)
        self.humanBlip = pygame.mixer.Sound('sounds/humanBlip.wav')
        self.computerBlip = pygame.mixer.Sound('sounds/computerBlip.wav')
        self.applause = pygame.mixer.Sound('sounds/applause.wav')
        self.ding = pygame.mixer.Sound('sounds/ding.wav')

        self.reset()
Beispiel #11
0
    def __init__(self, window):
        # Save window  in instance variable
        self.window = window

        return  # temporary, until I build out the high scores scene

        self.backgroundImage = pygwidgets.Image(
            self.window, (0, 0), "images/highScoresBackground.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 pyghelpers.fileExists(SceneHighScores.DATA_FILE_PATH):
            self.setEmptyHighScores()
        else:
            data = pyghelpers.readFile(SceneHighScores.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.CustomButton(self.window, (30, 650), \
                                                   up='images/quitNormal.png',\
                                                   down='images/quitDown.png',\
                                                   over='images/quitOver.png',\
                                                   disabled='images/quitDisabled.png')

        #self.resetScoresButton = pygwidgets.TextButton(self.window, (240, 650), 'Reset high scores')

        self.resetScoresButton = pygwidgets.CustomButton(self.window, (240, 650), \
                                                   up='images/resetNormal.png',\
                                                   down='images/resetDown.png',\
                                                   over='images/resetOver.png',\
                                                   disabled='images/resetDisabled.png')
        #self.startNewGameButton = pygwidgets.TextButton(self.window, (450, 650), 'Start new game')
        self.startNewGameButton = pygwidgets.CustomButton(self.window, (450, 650), \
                                                   up='images/startNewNormal.png',\
                                                   down='images/startNewDown.png',\
                                                   over='images/startNewOver.png',\
                                                   disabled='images/startNewDisabled.png')

        self.showHighScores()
    def __init__(self, window):
        self.window = window
        self.outerRect = pygame.Rect(725, WINDOW_HEIGHT - 30, 150, 40)
        self.thermometerRange = pygame.Rect(750 - 1, WINDOW_HEIGHT - 15, 102,
                                            12)
        self.thermometer = pygame.Rect(750, WINDOW_HEIGHT - 14, 100, 10)


        self.fuelDisplay = pygwidgets.DisplayText(window, (750, WINDOW_HEIGHT - 28), '', \
                                    fontSize=20, textColor=BLACK)
Beispiel #13
0
    def __init__(self, window, dealerOrPlayer):  # 'dealer' or 'player'
        self.window = window
        self.dealerOrPlayer = dealerOrPlayer
        self.handValue = 0
        self.bust = False
        self.cardList = []

        if self.dealerOrPlayer == 'dealer':
            self.dealer = True
            self.top = Hand.DEALER_TOP
            self.backOfCardImage = pygame.image.load('images/BackOfCard.png')
            self.valueText = pygwidgets.DisplayText(self.window, (174, 26), '', \
                            fontSize=40, textColor=BLACK)
        else:
            self.dealer = False
            self.top = Hand.PLAYER_TOP
            self.valueText = pygwidgets.DisplayText(self.window, (174, 290), '', \
                            fontSize=40, textColor=BLACK)
        self.reset()
Beispiel #14
0
    def __init__(self, window):
        self.window = window
        self.oHighScoresData = HighScoresData()

        self.backgroundImage = pygwidgets.Image(
            self.window, (0, 0), 'images/highScoresBackground.jpg')

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

        self.quitButton = pygwidgets.CustomButton(
            self.window, (30, 650),
            up='images/quitNormal.png',
            down='images/quitDown.png',
            over='images/quitOver.png',
            disabled='images/quitDisabled.png')

        self.backButton = pygwidgets.CustomButton(
            self.window, (240, 650),
            up='images/backNormal.png',
            down='images/backDown.png',
            over='images/backOver.png',
            disabled='images/backDisabled.png')

        self.resetScoresButton = pygwidgets.CustomButton(
            self.window, (450, 650),
            up='images/resetNormal.png',
            down='images/resetDown.png',
            over='images/resetOver.png',
            disabled='images/resetDisabled.png')

        self.showHighScores()
Beispiel #15
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), BG_SPLASH)
        self.backButton = pygwidgets.TextButton(self.window, (WINDOW_WIDTH/2 - 50, SPLASH_WINDOW_HEIGHT/2 - 150), 'Back', \
                                                upColor=DUSTYPURPLE, downColor=DARKVIOLET, textColor=WHITE,fontName=FONT_NAME, enterToActivate=True)

        self.moveKeys = pygwidgets.DisplayText(self.window, (WINDOW_WIDTH/2 - 70, SPLASH_WINDOW_HEIGHT/2 - 50), 'Move: Arrow Keys', \
                                fontSize=16, fontName = FONT_NAME,textColor=CONTROL_FONT_COLOR, justified='left')

        self.jumpKeys = pygwidgets.DisplayText(self.window, (WINDOW_WIDTH/2 - 70, SPLASH_WINDOW_HEIGHT/2), 'Jump: Spacebar', \
                                fontSize=16, fontName = FONT_NAME,textColor=CONTROL_FONT_COLOR, justified='left')

        self.interactKeys = pygwidgets.DisplayText(self.window, (WINDOW_WIDTH/2 - 70, SPLASH_WINDOW_HEIGHT/2 + 50), 'Interact: Enter', \
                                fontSize=16, fontName = FONT_NAME,textColor=CONTROL_FONT_COLOR, justified='left')

        self.attackKeys = pygwidgets.DisplayText(self.window, (WINDOW_WIDTH/2 - 70, SPLASH_WINDOW_HEIGHT /2 + 100), 'Attack: Mouse Left', \
                                                 fontName=FONT_NAME,fontSize=16, textColor=CONTROL_FONT_COLOR, justified='left')
Beispiel #16
0
def showCustomAlertDialog(theWindow, theText):
    oDialogBackground = pygwidgets.Image(theWindow, (60, 120), 'images/dialog.png')
    oPromptDisplayText = pygwidgets.DisplayText(theWindow, (0, 170), theText, \
                                width=WINDOW_WIDTH, justified='center', fontSize=36)
    oOKButton = pygwidgets.CustomButton(theWindow, (355, 265), \
                                        'images/okNormal.png',\
                                        over='images/okOver.png',\
                                        down='images/okDown.png',\
                                        disabled='images/okDisabled.png')
    userAnswer = pyghelpers.customYesNoDialog(theWindow, oDialogBackground, \
                                    oPromptDisplayText, oOKButton, None)
    return userAnswer
    def __init__(self, window, sceneKey):
        # Save window and sceneKey in instance variables
        self.window = window
        self.sceneKey = sceneKey

        self.messageField = pygwidgets.DisplayText(self.window, (15, 25), 'Welcome to Turtle-Hare Race!', \
                                              fontSize=50, textColor=Constants.GRAYA, width=610, justified='center')
        self.oEnterButton = pygwidgets.TextButton(self.window, (250, 100), 'Enter')
        
        self.hare = pygwidgets.Image(window, (150, 100), 'images/hare.gif')
        self.turtle = pygwidgets.Image(window, (390, 100), 'images/turtle.gif')
        
        self.oRace = RaceWidgets.Racing
Beispiel #18
0
 def __init__(self, width, height):
     self.width = width
     self.height = height
     self.window = pygame.display.set_mode((self.width, self.height))
     self.basicFont = pygame.font.SysFont(None, 36)
     self.messageTextField = pygwidgets.DisplayText(self.window, (20, 405),
                                                    "",
                                                    textColor=WHITE)
     self.restartButton = pygwidgets.CustomButton(self.window, (514, 440), \
                                     up='images/RestartButtonUp.png', down='images/RestartButtonDown.png', over='images/RestartButtonOver.png', disabled= 'images/RestartButtonDisabled.png')
     self.humanHumanButton = pygwidgets.CustomButton(self.window, (162, 192), \
                                     up='images/humanUp.png', down='images/humanDown.png', over='images/humanUp.png')
     self.humanComputerButton = pygwidgets.CustomButton(self.window, (341, 192), \
                                     up='images/computerUp.png', down='images/computerDown.png', over='images/computerUp.png')
Beispiel #19
0
def showCustomResetDialog(theWindow, theText):
    oDialogBackground = pygwidgets.Image(theWindow, (35, 450),
                                         'images/dialog.png')
    oPromptDisplayText = pygwidgets.DisplayText(theWindow, (0, 480), theText, \
                                width=WINDOW_WIDTH, justified='center', fontSize=36)
    oNoButton = pygwidgets.CustomButton(theWindow, (65, 595), \
                                        'images/cancelNormal.png',\
                                        over='images/cancelOver.png',\
                                        down='images/cancelDown.png',\
                                        disabled='images/cancelDisabled.png')
    oYesButton = pygwidgets.CustomButton(theWindow, (330, 595), \
                                        'images/okNormal.png',\
                                        over='images/okOver.png',\
                                        down='images/okDown.png',\
                                        disabled='images/okDisabled.png')
    choiceAsBoolean = pyghelpers.customYesNoDialog(theWindow, oDialogBackground, \
                                    oPromptDisplayText, oYesButton, oNoButton)
    return choiceAsBoolean
Beispiel #20
0
    def __init__(self, window, sceneKey):
        # Save window and sceneKey in instance variables
        self.window = window
        self.sceneKey = sceneKey

        self.messageField = pygwidgets.DisplayText(self.window, (40, 55), 'Start the Race!!!', \
                                              fontSize=30, textColor=Constants.BLUE, width=510, justified='center')
        self.oStartButton = pygwidgets.TextButton(self.window, (250, 100),
                                                  'Start',
                                                  textColor=Constants.BLACK)

        self.oTurtle = Turtle()
        self.oHare = Turtle()

        self.speedFile = 'speedRate.txt'
        self.winnerRecordFile = 'winnerRecords.txt'

        self.oRace = RaceWidgets.Racing
Beispiel #21
0
    def __init__(self, window, sceneKey):
        # Save window and sceneKey in instance variables
        self.window = window
        self.sceneKey = sceneKey

        self.messageField = pygwidgets.DisplayText(self.window, (30, 55), 'Show player informatin one by one', \
                                              fontSize=30, textColor=Constants.PURPLE, width=510, justified='center')

        self.oStartButton = pygwidgets.TextButton(self.window, (250, 100),
                                                  'Show',
                                                  textColor=Constants.WHITE)

        self.oTurtle = Turtle()
        self.oHare = Turtle()

        self.speedFile = 'speedRate.txt'
        self.winnerRecordFile = 'winnerRecords.txt'

        self.oRace = RaceWidgets.Racing
Beispiel #22
0
def showCustomAnswerDialog(theWindow, theText):
    oDialogBackground = pygwidgets.Image(theWindow, (60, 120), 'images/dialog.png')
    oPromptDisplayText = pygwidgets.DisplayText(theWindow, (0, 170), theText, \
                                width=WINDOW_WIDTH, justified='center', fontSize=36)
    oUserInputText = pygwidgets.InputText(theWindow, (225, 220), '',
                                            fontSize=36, initialFocus=True)
    oNoButton = pygwidgets.CustomButton(theWindow, (105, 265), \
                                        'images/cancelNormal.png',\
                                        over='images/cancelOver.png',\
                                        down='images/cancelDown.png',\
                                        disabled='images/cancelDisabled.png')
    oYesButton = pygwidgets.CustomButton(theWindow, (375, 265), \
                                        'images/okNormal.png',\
                                        over='images/okOver.png',\
                                        down='images/okDown.png',\
                                        disabled='images/okDisabled.png')
    choiceAsBoolean, userAnswer = pyghelpers.customAnswerDialog(theWindow, oDialogBackground, \
                                    oPromptDisplayText, oUserInputText, oYesButton, oNoButton)
    return choiceAsBoolean, userAnswer
SIDES_PER_DIE = 6
SIDES_PER_DIE_PLUS_ONE = SIDES_PER_DIE + 1
STATE_WAITING = 'waiting'
STATE_RUNNING = 'running'

pygame.init()
clock = pygame.time.Clock()
pygame.display.set_caption('Roll Them Dice')
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))

state = STATE_RUNNING
nRoundsRolled = 0
nRoundsToRun = MAX_ROUNDS

oTitleDisplay = pygwidgets.DisplayText(window, (330, 30),
                                       'Roll Them Dice!',
                                       fontName='monospaces',
                                       fontSize=34)
oQuitButton = pygwidgets.TextButton(window, (20, 460),
                                    'Quit',
                                    width=100,
                                    height=35)
oRunButton = pygwidgets.TextButton(window, (690, 460),
                                   'Run',
                                   width=100,
                                   height=35)
oRunButton.disable()

oRoundsDisplay = pygwidgets.DisplayText(window, (315, 460),
                                        '0',
                                        fontName='monospaces',
                                        fontSize=28,

window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption('Slot Machine')

pygame.font.init()
#moneyFont = pygame.font.SysFont(fontName='Haettenschweiler', fontSize=30)
#jackpotFont = pygame.font.SysFont(fontName='Broadway', fontSize=50)
#messageFont = pygame.font.SysFont(fontName='Haettenschweiler', fontSize=35)

slotMachine_image = pygame.image.load("images/slotMachine.png")
slotMachineCoverTop = pygame.image.load("images/slotMachineCoverTop.png")
slotMachineCoverBottom = pygame.image.load("images/slotMachineCoverBottom.png")
payLine = pygame.image.load('images/payline.png')

jackpotDisplay = pygwidgets.DisplayText(window,(530, 212), '', \
                                    fontName='Broadway', fontSize=50, textColor=BLACKISH)
betDisplay = pygwidgets.DisplayText(window, (376,710), '', \
                                    fontName='Haettenschweiler', fontSize=30, textColor=YELLOW)
coinsDisplay = pygwidgets.DisplayText(window,(610, 710), '', \
                                    fontName='Haettenschweiler', fontSize=30, textColor=YELLOW)
winningsDisplay = pygwidgets.DisplayText(window, (800, 710), '', \
                                    fontName='Haettenschweiler', fontSize=30, textColor=YELLOW)
messageDisplay = pygwidgets.DisplayText(window, (181, 870), '', \
                                    fontName='Haettenschweiler', fontSize=35, textColor=BLACKISH)

spinButton = pygwidgets.CustomButton(window,(755, 772, 108, 44), \
                                 up='images/spinButton.png', down='images/spinButtonDown.png', \
                                over='images/spinButtonOver.png', disabled='images/spinButtonGray.png')
bet1Button = pygwidgets.TextButton(window, (230, 785), 'Bet 1', width=108, height=44,\
                                soundOnClick=COIN_DROP_SOUND)
up1Button = pygwidgets.CustomButton(window, (395, 766),\
Beispiel #25
0
# 2 - Define constants
BLACK = (0, 0, 0)
LIME = (0, 255, 0)
WHITE = (255, 255, 255)
WINDOW_WIDTH = 500
WINDOW_HEIGHT = 500
FRAMES_PER_SECOND = 30

# 3 - Initialize the world
pygame.init()
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
clock = pygame.time.Clock()  # set the speed (frames per second)

# 4 - Load assets: image(s), sounds, etc.
oDisplay = pygwidgets.DisplayText(window, (WINDOW_WIDTH - 120, 10),
                                  '',
                                  fontSize=30)

# 5 - Initialize variables
oBasket = Basket(window, WINDOW_WIDTH, WINDOW_HEIGHT)

fruitList = []
fruitNames = ['apple', 'banana', 'cherry', 'grapes', 'pear', 'strawberry']
for fruitName in fruitNames:
    if fruitName == 'pear':
        fruitList.append(
            Fruit(window, WINDOW_WIDTH, WINDOW_HEIGHT, fruitName, -100))
    else:
        fruitList.append(Fruit(window, WINDOW_WIDTH, WINDOW_HEIGHT, fruitName))

oRestartButton = pygwidgets.TextButton(window, (5, 5), 'Restart')
oFuelGauge = FuelGauge(window)

gameState = GAME_FLYING
landedState = LANDED_NOT

# Score
score = 0

#The ground
moon = pygame.image.load("images/moon.png")
austronaut = pygame.image.load("images/astronaut.png")



liveSpeedX = pygwidgets.DisplayText(window, (500, MOON_START + 20), '', \
                                    fontSize=30, textColor=GREEN)
liveSpeedY = pygwidgets.DisplayText(window, (900, MOON_START + 20), '', \
                                    fontSize=30, textColor=GREEN)
scoreText = pygwidgets.DisplayText(window, (10, MOON_START + 20), '', \
                                    fontSize=30, textColor=GREEN)
countUpTimerField = pygwidgets.DisplayText(window, (WINDOW_WIDTH - 150, MOON_START + 20, ), '0', \
                                    fontSize=30, textColor=GREEN)

# Stuff dealing with dialog box when one round of the game is done
messageDisplay = pygwidgets.DisplayText(window, (565, 290), '', \
                                    fontSize=48, textColor=BLACK)
speedDisplay = pygwidgets.DisplayText(window, (565, 340), '', \
                                    fontSize=48, textColor=BLACK)
newSoftestField = pygwidgets.DisplayText(window, (565, 390), '', \
                                    fontSize=48, textColor=BLACK)
newFastestField = pygwidgets.DisplayText(window, (565, 440), '', \
Beispiel #27
0
BLACK = (0, 0, 0)
LIME = (0, 255, 0)
WHITE = (255, 255, 255)
WINDOW_WIDTH = 1000
WINDOW_HEIGHT = 1000
FRAMES_PER_SECOND = 60
MAX_FRUIT = 2

# 3 - Initialize the world
pygame.init()
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
clock = pygame.time.Clock()  # set the speed (frames per second)

# 4 - Load assets: image(s), sounds, etc.
oDisplay = pygwidgets.DisplayText(window, (WINDOW_WIDTH - 120, 10),
                                  '',
                                  fontSize=30)

# 5 - Initialize variables
score = 0
level = 1
fruitType = ['apple', 'banana', 'cherry', 'grapes', 'pear', 'strawberry']
fruitList = []
fruitCount = [0, 0, 0, 0, 0, 0]
fruit = ''
r = random.randint(0, 5)
oBasket = Basket(window, WINDOW_WIDTH, WINDOW_HEIGHT)
oFruit = Fruit(window, WINDOW_WIDTH, WINDOW_HEIGHT, fruitType[r])
oRestartButton = pygwidgets.TextButton(window, (5, 5), 'Restart')
oLevelText = pygwidgets.DisplayText(window, (460, 20), 'LEVEL 1')
oCountText = pygwidgets.DisplayText(
Beispiel #28
0
def textAnswerDialog(theWindow, theRect, prompt, trueButtonText='OK',\
                    falseButtonText='Cancel', backgroundColor=DIALOG_BACKGROUND_COLOR):
    """Puts up a text-based two-button answerable modal dialog (typically Yes/No or OK/Cancel)

    Parameters:
        |    theWindow - the window to draw in
        |    theRect - the rectangle of the dialog box in the application window
        |    prompt - prompt (title) string to be displayed in the dialog box

    Optional keyword parameters:
        |    trueButtonText - text on the True button (defaults to 'OK')
        |    falseButtonText - text on the False button (defaults to 'Cancel')
        |    backgroundColor - rgb background color for the dialog box (defaults to (0, 200, 200))

    Returns:
        |    trueOrFalse - True means true button was pressed, False means false button was pressed
        |    userText - if above is True, then this contains the text that the user typed.

    """

    dialogLeft = theRect[0]
    dialogTop = theRect[1]
    dialogWidth = theRect[2]
    dialogHeight = theRect[3]
    frameRect = pygame.Rect(dialogLeft + 1, dialogTop + 1, dialogWidth - 2, dialogHeight - 2)
    INSET = 30 # inset buttons from the edges of the dialog box

    promptText = pygwidgets.DisplayText(theWindow, (dialogLeft, dialogTop + 30), prompt,
                                        fontSize=24, width=dialogWidth, justified='center')

    inputWidth = dialogWidth - (2 * INSET)
    inputText = pygwidgets.InputText(theWindow, (dialogLeft + INSET, dialogTop + 80),
                                     width=inputWidth, initialFocus=True)

    falseButton = pygwidgets.TextButton(theWindow, (0, 0), falseButtonText)
    trueButton = pygwidgets.TextButton(theWindow, (0, 0), trueButtonText)

    trueButtonRect = trueButton.getRect()
    trueButtonHeight = trueButtonRect[3]
    trueButtonWidth = trueButtonRect[2]  # get width
    xPos = dialogLeft + dialogWidth - trueButtonWidth - INSET
    buttonsY = dialogTop + dialogHeight - trueButtonHeight - 20
    falseButton.setLoc((dialogLeft + INSET, buttonsY))
    trueButton.setLoc((xPos, buttonsY))


    # 6 - Loop forever
    while True:

        # 7 - Check for and handle events
        for event in pygame.event.get():
            if (event.type == QUIT) or \
                ((event.type == KEYDOWN) and (event.key == K_ESCAPE)):
                pygame.quit()
                sys.exit()

            if inputText.handleEvent(event):
                theAnswer = inputText.getValue()
                return True, theAnswer

            if trueButton.handleEvent(event):
                theAnswer = inputText.getValue()
                return True, theAnswer

            if falseButton.handleEvent(event):
                return False, None

        # 8 - Do any "per frame" actions

        # 9 - Clear the screen area before drawing it again
        pygame.draw.rect(theWindow, backgroundColor, theRect)
        pygame.draw.rect(theWindow, DIALOG_BLACK, theRect, 1)

        # 10 - Draw the screen elements
        promptText.draw()
        inputText.draw()
        falseButton.draw()
        trueButton.draw()

        # 11 - Update the screen
        pygame.display.update()
Beispiel #29
0
def textYesNoDialog(theWindow, theRect, prompt, trueButtonText='OK', \
                    falseButtonText='Cancel', backgroundColor=DIALOG_BACKGROUND_COLOR):
    """Puts up a text-based two-button modal dialog (typically Yes/No or OK/Cancel)

    It can also be used to put up a single button alert dialog (typically with an OK button)

    Parameters:
        |    theWindow - the window to draw in
        |    theRect - the rectangle of the dialog box in the application window
        |    prompt - prompt (title) string to be displayed in the dialog box

    Optional keyword parameters:
        |    trueButtonText - text on the True button (defaults to 'OK')
        |    falseButtonText - text on the False button (defaults to 'Cancel')
        |       Note:  If falseButtonText is None or the empty string, the false button will not be drawn
        |              This way, you can present an "alert" box with only an 'OK' button
        |    backgroundColor - rgb background color for the dialog box (defaults to (0, 200, 200))

    Returns:
        |    trueOrFalse - True means true button was pressed, False means false button was pressed

    """
    dialogLeft = theRect[0]
    dialogTop = theRect[1]
    dialogWidth = theRect[2]
    dialogHeight = theRect[3]
    frameRect = pygame.Rect(dialogLeft + 1, dialogTop + 1, dialogWidth - 2, dialogHeight - 2)
    INSET = 30 # inset buttons from the edges of the dialog box

    promptText = pygwidgets.DisplayText(theWindow, (dialogLeft, dialogTop + 30), prompt,
                                        fontSize=24, width=dialogWidth, justified='center')

    # Create buttons, fix locations after finding out the size of the button(s)
    hideFalseButton = (falseButtonText is None) or (falseButtonText == '')
    showFalseButton = not hideFalseButton
    if showFalseButton:
        falseButton = pygwidgets.TextButton(theWindow, (0, 0), falseButtonText)
    trueButton = pygwidgets.TextButton(theWindow, (0, 0), trueButtonText)

    trueButtonRect = trueButton.getRect()
    trueButtonHeight = trueButtonRect[3]
    trueButtonWidth = trueButtonRect[2]  # get width
    xPos = dialogLeft + dialogWidth - trueButtonWidth - INSET
    buttonsY = dialogTop + dialogHeight - trueButtonHeight - 20
    if showFalseButton:
        falseButton.setLoc((dialogLeft + INSET, buttonsY))
    trueButton.setLoc((xPos, buttonsY))

    #print('In dialogYesNo')
    #print('theRect is', theRect)
    #print('frameRect is', frameRect)

    # 6 - Loop forever
    while True:

        # 7 - Check for and handle events
        for event in pygame.event.get():
            if (event.type == QUIT) or \
                ((event.type == KEYDOWN) and (event.key == K_ESCAPE)):
                pygame.quit()
                sys.exit()

            if showFalseButton:
                if falseButton.handleEvent(event):
                    return False

            if trueButton.handleEvent(event):
                return True

        # 8 - Do any "per frame" actions

        # 9 - Clear the screen area before drawing it again
        pygame.draw.rect(theWindow, backgroundColor, theRect)
        pygame.draw.rect(theWindow, DIALOG_BLACK, frameRect, 1)

        # 10 - Draw the screen elements
        promptText.draw()
        if showFalseButton:
            falseButton.draw()
        trueButton.draw()

        # 11 - Update the screen
        pygame.display.update()
Beispiel #30
0
    def __init__(self, window, pos, spritesheet_loc, text, direction):
        # pass in position and walking direction for each NPC
        self.window = window
        self.text = text
        self.font_name = 'gothicpixels'
        #self.font_name = 'pixeledenglishfont'
        self.direction = direction
        self.collision = False
        self.CM = 1

        self.range = random.randrange(0,15)
        self.pacing = 0
        self.paceRight = 0
        self.paceLeft = 100
        self.randomPace = random.randrange(0,2)
        self.idleAmt = random.choice([100, 200,300,400,500,600,100])
        self.idleTimer = 0
        self.state = WALKING

        # state/animation variables
        self.currentFrame = 0  # up to number of frames in an animation
        self.last_update = 0
        self.spritesheet = pygame.image.load(SPRITESHEET_VILLAGERS).convert()
        self.frames = []
        # self.chooseAction = random.randrange(0,10)
        # self.randomTime = random.randrange(0,2)
        # self.myTimer = pyghelpers.Timer(.5)
        # self.finished = self.myTimer.update()
        # self.stateList = [IDLING, WALKING]
        # self.directionList = [RIGHT,LEFT]
        # self.randomPace = random.randrange(0,20)
        # self.actionTimer = 0

        for n in range(18):
            width = 62
            height = 44
            rect = pygame.Rect((n * width, spritesheet_loc), (width, height))
            image = pygame.Surface(rect.size).convert()
            image.blit(self.spritesheet, (0, 0), rect)
            alpha = image.get_at((0, 0))
            image.set_colorkey(alpha)
            self.frames.append(image)

        self.idleFrames_R = self.frames[17:19]
        self.idleFrames_L = self.frames[17:19]
        self.walkFrames_R = self.frames[8:16]
        self.walkFrames_L = self.frames[8:16]
        self.attackFrames_L = self.frames[:9]
        self.attackFrames_R = self.frames[:9]


        for frame in range(2):
            self.idleFrames_L.append(pygame.transform.flip(self.idleFrames_L[frame], True, False))
        self.idleFrames_L = self.idleFrames_L[2:]

        for frame in range(8):
            self.walkFrames_L.append(pygame.transform.flip(self.walkFrames_L[frame], True, False))
        self.walkFrames_L = self.walkFrames_L[9:]

        for frame in range(8):
            self.attackFrames_L.append(pygame.transform.flip(self.attackFrames_L[frame], True, False))
        self.attackFrames_L = self.attackFrames_L[9:]

        self.idleFrame_L = 0
        self.idleFrame_R = 0
        self.idleSpeed = 16
        self.walkFrame_R = 0
        self.walkFrame_L = 0
        self.walkSpeed = 8
        self.attackSpeed = 12
        self.attackFrame_L = 0
        self.attackFrame_R = 0

        self.image = self.frames[0]
        self.rect = self.image.get_rect()
        self.height = self.rect.height
        self.halfHeight = self.height / 2
        self.width = self.rect.width
        self.halfWidth = self.width / 2

        # VEC(X,Y)
        self.pos = VEC(pos)
        self.vel = VEC(0, 0)
        self.acc = VEC(0, 0)

        self.textBox = pygwidgets.DisplayText(window, (self.pos.x + 3, self.pos.y + 15), "", fontName=self.font_name, \
                                              fontSize=12, textColor=WHITE)
        self.shadow = pygwidgets.DisplayText(window, (self.pos.x + 0.5, self.pos.y + 17), "", fontName=self.font_name, \
                                             fontSize=12, textColor=BLACK)

        # instantiate collision platforms
        self.collision_map = pygame.image.load(CM_LEVEL_1)
        self.setCM = False

        self.collide_DOWN = False
        self.collide_RIGHT = False
        self.collide_LEFT = False

        self.color_DOWN = TEAL
        self.color_LEFT = TEAL
        self.color_RIGHT = TEAL

        self.interact = False