Пример #1
0
    def loop(self):
        gameVariables = self.main.gameVariables
        levelName = ""
        currentLevel = None
        running = True

        while running:

            while currentLevel == None:
                levelName = "gamelevel" + str(
                    self.data['chapter']) + "_" + str(self.data['level'])
                if base.NEED_MORE_BIBLES == False:
                    levelName = "gamelevel" + str(6) + "_" + str(1)
                #else:
                #	levelName = "gamelevel" + str(self.data['chapter']) + "_" + str(self.data['level'])

                try:
                    if self.data['difficulty'] != 3:
                        if self.data['chapter'] == 3:
                            if self.data['level'] == 3:
                                levelName = "gamelevel" + str(3) + "_" + str(4)

                    ## Load the new level from the dynamically loaded module
                    currentLevel = initLevel(levelName)
                    # save all the variables level and other scripts might have created in gameVariables
                    for key, value in gameVariables.iteritems():
                        self.data[key] = value
                    saveGame(self.data)

                except ImportError, err:
                    # if we weren't looking for the first level of current major
                    # number (x_0), then check for next major
                    if self.data['level'] > 1:
                        self.data['chapter'] += 1
                        self.data['level'] = 1
                    else:
                        raise base.ResourceException("Error loading level " +
                                                     levelName + "!")

                if base.SOUND == True:
                    if self.data["chapter"] == 5:
                        if self.playing != "MountainMusic":
                            for item in music.Music:
                                music.Stop(item)
                            music.Play("MountainMusic")
                            self.playing = "MountainMusic"

                    if self.data["chapter"] == 4:
                        if self.playing != "TempleMusic":
                            for item in music.Music:
                                music.Stop(item)
                            music.Play("TempleMusic")
                            self.playing = "TempleMusic"

                    if self.data["chapter"] == 2:
                        if self.playing != "CaveMusic":
                            for item in music.Music:
                                music.Stop(item)
                            music.Play("CaveMusic")
                            self.playing = "CaveMusic"

                    if (((self.data["chapter"] == 1)
                         or (self.data["chapter"] == 3)
                         or (self.data["chapter"] == 6))):
                        if self.playing != "JungleMusic":
                            for item in music.Music:
                                music.Stop(item)
                            music.Play("JungleMusic")
                            self.playing = "JungleMusic"

            chapter = int(self.data['chapter'])
            print "Loaded level", levelName

            if len(base.testLevelname) > 0:
                currentLevel.levelFileName = base.testLevelname

            # give the level access to the gameVariables
            currentLevel.pvars = gameVariables
            # run until user quits
            endState = currentLevel.run()

            if (endState == base.NEXTLEVEL):
                self.data['bibles'] = base.num_bibles
                self.data['bananas'] = base.numBananas

                self.data['level'] += 1
                currentLevel = None
                base.testLevelname = ""
                if base.num_bibles >= base.NEEDED_BIBLES:
                    base.NEED_MORE_BIBLES = False
                    for key, value in gameVariables.iteritems():
                        self.data[key] = value
                        saveGame(self.data)

                if base.NEED_MORE_BIBLES == True:
                    base.DATA["chapter"] = randrange(1, 5)
                    base.DATA["level"] = randrange(1, 2)

                self.data['bibles'] = base.num_bibles
                self.data['bananas'] = base.numBananas

                #self.data['level'] += 1
                #currentLevel = None
                base.testLevelname = ""
            elif endState == base.GAMEOVER:
                base.num_bibles = int(self.data['bibles'])
                base.numBananas = int(self.data['bananas'])

                if base.testLevelname == "":
                    currentLevel = initLevel(levelName)
                else:  # special case for restarting the testlevel which uses custom level class
                    currentLevel = initCustomLevel("testlevel")

            elif (endState == base.RESTARTLEVEL):
                if base.testLevelname == "":
                    currentLevel = initLevel(levelName)
                else:  # special case for restarting the testlevel which uses custom level class
                    currentLevel = initCustomLevel("testlevel")
            elif endState == base.QUITGAME:  # todo, game over screen?
                running = False
            elif endState == base.GOTOLEVEL:
                levelName = currentLevel.gotoLevelName
                currentLevel = initLevel(levelName)
                # need to keep track on these
                self.data['chapter'] = currentLevel.level_maj
                self.data['level'] = currentLevel.level_min
                base.testLevelname = ""
            elif endState == base.GOTOTESTLEVEL:
                if base.testLevelname == "":
                    Exception("testLevelname not set")
                    # user the testlevel.py level script
                    levelName = "testlevel"

                    currentLevel = initCustomLevel(base.testLevelname)

                    # need to keep track on these
                    self.data['chapter'] = currentLevel.level_maj
                    self.data['level'] = currentLevel.level_min
                else:
                    raise Exception("Unknown level end state", endState)
            elif endState == base.SHOWGAMEOVER:
                return GameOver(self.main)
Пример #2
0
	def loop(self):
		gameVariables = self.main.gameVariables
		levelName = ""
		currentLevel = None
		running = True
		
		while running:
				
			while currentLevel == None:
				levelName = "gamelevel" + str(self.data['chapter']) + "_" + str(self.data['level'])
		
				try:
					if base.num_bibles >= base.NEEDED_BIBLES:
						if base.NEED_MORE_BIBLES == True:
							base.NEED_MORE_BIBLES = False
							levelName = "gamelevel" + str(6) + "_" + str(1)
							
					
					## Load the new level from the dynamically loaded module
					currentLevel = initLevel(levelName)
					# save all the variables level and other scripts might have created in gameVariables
					for key,value in gameVariables.iteritems():
						self.data[key] = value
					saveGame(self.data)
														
				except ImportError, err:
					# if we weren't looking for the first level of current major 
					# number (x_0), then check for next major
					if self.data['level'] > 1:
						self.data['chapter'] += 1
						self.data['level'] = 1
					else:
						raise base.ResourceException("Error loading level " + levelName + "!")
				
				if base.SOUND == True:
					if self.data["chapter"] == 5:
						if self.playing != "MountainMusic":
							for item in music.Music:
								music.Stop(item)
							music.Play("MountainMusic")
							self.playing = "MountainMusic"
					
					if self.data["chapter"] == 4:
						if self.playing != "TempleMusic":
							for item in music.Music:
								music.Stop(item)
							music.Play("TempleMusic")
							self.playing = "TempleMusic"
							
					if self.data["chapter"] == 2:
						if self.playing != "CaveMusic":
							for item in music.Music:
								music.Stop(item)
							music.Play("CaveMusic")
							self.playing = "CaveMusic"
	
					if (((self.data["chapter"] == 1) or (self.data["chapter"] == 3) or (self.data["chapter"] == 6))):
						if self.playing != "JungleMusic":
							for item in music.Music:
								music.Stop(item)
							music.Play("JungleMusic")
							self.playing = "JungleMusic"
			
			chapter = int(self.data['chapter'])
			print "Loaded level", levelName
						
			if len(base.testLevelname) > 0:
				currentLevel.levelFileName = base.testLevelname
														
			# give the level access to the gameVariables
			currentLevel.pvars = gameVariables
			# run until user quits
			endState = currentLevel.run()
		
			if (endState == base.NEXTLEVEL):
				self.data['bibles'] = base.num_bibles
				self.data['bananas'] = base.numBananas
				
				self.data['level'] += 1
				currentLevel = None
				base.testLevelname = ""
			elif endState == base.GAMEOVER:
				base.num_bibles = int(self.data['bibles'])
				base.numBananas = int(self.data['bananas'])
				
				if base.testLevelname == "":
					currentLevel = initLevel(levelName)
				else: # special case for restarting the testlevel which uses custom level class 
					currentLevel = initCustomLevel("testlevel")
				
			elif (endState == base.RESTARTLEVEL):
				if base.testLevelname == "":
					currentLevel = initLevel(levelName)
				else: # special case for restarting the testlevel which uses custom level class 
					currentLevel = initCustomLevel("testlevel")
			elif endState == base.QUITGAME: # todo, game over screen?
				running = False
			elif endState == base.GOTOLEVEL:
				levelName = currentLevel.gotoLevelName
				currentLevel = initLevel(levelName)
				# need to keep track on these
				self.data['chapter'] = currentLevel.level_maj
				self.data['level'] = currentLevel.level_min
				base.testLevelname = ""
			elif endState == base.GOTOTESTLEVEL:
				if base.testLevelname == "": 
					Exception("testLevelname not set")
					# user the testlevel.py level script
					levelName = "testlevel"												 
								
					currentLevel = initCustomLevel(base.testLevelname)
								
					# need to keep track on these
					self.data['chapter'] = currentLevel.level_maj
					self.data['level'] = currentLevel.level_min
				else:
					raise Exception("Unknown level end state",endState)
			elif endState == base.SHOWGAMEOVER:
				return GameOver(self.main)