示例#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
示例#2
0
class Ball(Image):
	def __init__(self, fileName, x, y, polygon, game):
		"""
        Initialize a ball

            @param self -- the ball
            @param fileName -- a string that contains the image name 
            @param x -- a horizontal position of ball
            @param y -- a vertical position of ball
            @param polygon -- a list of (x,y) pairs	
            @param game -- the game
	    
		"""
		
		self.image = pygame.image.load("image/animation/" + fileName + ".png")
		self.image.set_alpha(None) # disable alpha.
		self.image.convert()
		self.image.set_colorkey( ( 255, 0, 255 ) ) # magenta
		self.x = x
		self.y = y
		self.polygon = polygon
		self.isHover = False
		self.isDown = False
		self.isVisible = False
		self.mouseInside = False
		self.currentBall = None
		self.game = game
		
	def setSound(self, sectionFileName):
		"""
        Set a sound ball

    		@param self -- the ball
            @param sectionFileName -- a related section filename  
	    
		"""
		self.sectionFileName = sectionFileName
		self.section = Section()
		self.section.setFileName("sound/section/" + sectionFileName)

	def mouseHover(self):
		"""
        When the mouse is hover on the ball

            @param self -- the ball

        """

		self.isHover = True
		self.game.setEarCursorVisible(True)
		if self.game.lampIsSelected():
		    self.game.setLampCursorVisible(False)
		if os.path.exists("sound/section/" + self.sectionFileName + ".wav"):
		    self.section.play()

	def mouseLeave(self):
		"""
		When the mouse leaves the ball

            @param self -- the ball 

		"""
		
		self.isHover = False
		self.game.setEarCursorVisible(False)
		if self.game.lampIsSelected():
		    self.game.setLampCursorVisible(True)
		
	def draw(self, screen):
		"""
		Draw the ball

            @param self -- the ball
            @param screen -- the screen where the images will be showed
	    
		"""
		
		if self.isVisible:		
		 	screen.blit(self.image, (self.x, self.y))