示例#1
0
class Challenge:
    def __init__(self, fileName, keys, stick, stones, helps, ball, bar, rightBall, level, game):
        """
        Initialize a challenge

	        @param self -- the challenge
            @param fileName -- a string that contains the sound name 
            @param keys -- the key vector
            @param stick -- the stick
            @param stones -- the stones
            @param helps -- the helps
            @param ball -- the left ball that it is used in the animation
            @param bar -- the grey bar that it is used in the animation
            @param rightBall -- the right ball that it is used in the animation
            @param level -- the challenge level
            @param game -- the game
	    
		"""
		
        self.fileName = fileName
        self.music = Sound()
        self.music.setFileName("sound/music/" + fileName)
        self.section = Section()
        self.section.setFileName("sound/section/" + fileName)
        self.section.setKeys(keys)
        self.stick = stick
        self.animation = Animation(stones, keys, helps, ball, rightBall, bar, game)
        self.ball = ball
        self.level = level
        self.attempts = 0
        self.game = game
    
    def start(self):
        """
        Start a challenge

    		@param self -- the challenge
	    
		"""
        
        if os.path.exists("sound/section/" + self.fileName + ".wav"):
            self.section.play()
            self.game.statusBar.setText(_("Discover the next musical note"))
            self.animation.playIntroduction()
            self.ball.setSound(self.fileName)
            
    def change(self):
        """
        Change a challenge

    		@param self -- the challenge
	    
		"""
        if os.path.exists("sound/section/" + self.fileName + ".wav"):
            self.section.play()
            self.game.statusBar.setText(_("Discover the next musical note"))
            self.animation.playIntroduction()
            self.ball.setSound(self.fileName)
			
    def finish(self):
        """
        Finish a challenge

    		@param self -- the challenge
	    
		"""
		
        if os.path.exists("sound/music/" + self.fileName + ".ogg"):
            self.music.play()
        self.game.currentChallenge = None
        self.game.statusBar.setText(_("Congratulations!!! You completed the challenge! Choose other to continue playing."))
        self.stick.setVisible(False)
        self.animation.playClosing()
        self.game.setPoints(self.level, self.attempts)
			
    def attempt(self, id):
        """
        Verify a attempt

    		@param self -- the challenge
            @param id -- the key index
	    
		"""
		
        if self.section.isCurrentKey(id):
        	self.game.setBufferPoints(self.level, self.attempts)
        	self.attempts = 0 
        	if self.section.isLastKey():
        		self.finish()
        	else:		
        		self.animation.lowStone(self.section.currentKey)
        		self.section.currentKey = self.section.currentKey + 1
        		self.game.statusBar.setText(_("Discover the next musical note"))
        else:
            self.attempts = self.attempts + 1
            if self.section.moreThan(id):
        	    self.game.statusBar.setText(_("Try a lower note"))
            else:
        	    self.game.statusBar.setText(_("Try a higher note"))
        	    
    def getBall(self):
        """
        Get the ball

    		@param self -- the challenge
	    
	    """
        return self.ball