Example #1
0
    def changeState(self,newState) :
        """
        function to change the current state of the main menu
        Transition: self.state is updated to new state
        exception: none
        input: newState - string value of new state
        output: none
        """

        if self.STATES.count(newState)==1 : self.state = newState
        if self.state =='menu' : self.pauseStatus = False
        if self.state == 'instructions' : self.pauseStatus = False
        if self.state=='game' :
            if not(self.pauseStatus) :
                self.gameMap = PlayMap()
        if self.state=='gameOver':
            self.pauseStatus = False
            self.gameOver = GameOver(self.gameMap.score)
        if self.state=='gamePause':
            self.pauseStatus = True
            self.gamePause = GamePause(self.gameMap.score)
Example #2
0
 def __init__(self) :
     """
     Constructor for MainMenu class
     Transition: initialized to main menu state
     exception: none
     """
     self.STATES = ['menu','game','gameOver','gamePause','instructions']
     self.gameMap = PlayMap()
     self.gameOver = GameOver(20)
     self.gamePause = GamePause(20)
     self.gameInstructions = GameInstructions()
     self.pauseStatus = False
     
     # What stage of the interface the game is on
     self.state = 'menu'
     
     # Display objects for the GUI
     self.startGameButton = pygame.Rect(50,200,200,100)
     self.exitGameButton = pygame.Rect(300,200,200,100)
     self.diff0Button = pygame.Rect(100,400,50,50)
     self.diff1Button = pygame.Rect(200,400,50,50)
     self.diff2Button = pygame.Rect(300,400,50,50)
     
     self.updateState()
import unittest
from GamePause import *

testGamePause = GamePause(20)


class TestGamePause(unittest.TestCase):
    def testUpdateState(self):
        testGamePause.updateState(21)
        self.assertEqual(testGamePause.score, 21)

    def testGetCurrentState(self):
        self.assertEqual(testGamePause.getCurrentState(), [
            testGamePause.score, testGamePause.resumeButton,
            testGamePause.menuButton, testGamePause.exitButton
        ])


if __name__ == '__main__':
    unittest.main(verbosity=2)