当前位置: 首页>>代码示例>>Python>>正文


Python Menu.get_position方法代码示例

本文整理汇总了Python中menu.Menu.get_position方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.get_position方法的具体用法?Python Menu.get_position怎么用?Python Menu.get_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在menu.Menu的用法示例。


在下文中一共展示了Menu.get_position方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: menu_loop

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import get_position [as 别名]
	def menu_loop():
		pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
		pygame.mixer.music.load("sound/hearthbeat.wav")
		pygame.mixer.music.play()
		menu_screen = pygame.display.set_mode((854, 480))
		menu_screen.fill((51, 51, 51))
		menu = Menu(['Start', 'Options', 'Quit'], menu_screen)
		menu.draw()
		pygame.key.set_repeat(199, 69)  # (delay,interval)
		pygame.display.update()

		while 1:
			for event in pygame.event.get():
				if event.type == pygame.KEYDOWN:
					if event.key == pygame.K_UP:
						menu.draw(-1)  # here is the Menu class function
					if event.key == pygame.K_DOWN:
						menu.draw(1)  # here is the Menu class function
					if event.key == pygame.K_RETURN:
						if menu.get_position() == 2:  # here is the Menu class function
							pygame.quit()
							sys.exit()
						elif menu.get_position() == 0:
								Main(800, 800, 100)
								pygame.init()
								menu_loop()
					if event.key == pygame.K_ESCAPE:
						pygame.display.quit()
						sys.exit()
					pygame.display.update()
				elif event.type == pygame.QUIT:
					pygame.display.quit()
					sys.exit()
			pygame.time.wait(8)
开发者ID:Pfeter,项目名称:SpaceShooter,代码行数:36,代码来源:game.py

示例2: getPlayer

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import get_position [as 别名]
    def getPlayer(self):

        rtnObject = self.returnObject()
        # Starting screen text
        title = self.titleFont.render("Chocotaco Othello",True,DULLYELLOW)
        self.display.blit(title,(int(self.boardWidth/4),50))
        info = [pygame.Surface]*4
        info[0] = self.font.render("Select playing option using the UP & DOWN arrow keys.", True, WHITE)
        info[1] = self.font.render("Set computer timeout using the LEFT & RIGHT arrow keys",True, WHITE)
        info[2] = self.font.render("Make a selection using the ENTER key", True,WHITE)
        info[3] = self.font.render("Press SPACE to set layout for configuration", True, WHITE)
        for n, blurb in enumerate(info):
            self.display.blit(blurb, (75, self.boardWidth/4+32*n))
        #Time out information
        timeOut = 5
        timeOutLabel = self.font.render("Timeout", True, WHITE)
        self.display.blit(timeOutLabel,(int(3*self.windowSize/4)+16, int(self.boardWidth/2)+32))
        self.showTimeout(timeOut)
        #Actual Menu
        menu = Menu()
        menu.init(['Go First (Black)', 'Go Second (White)','Comp V Comp','Quit'], self.display)
        menu.draw()
        pygame.key.set_repeat(199,69)
        pygame.display.update()
        while 1:
            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    if event.key == K_LEFT:
                        if timeOut >2:
                            timeOut -= 1
                            self.showTimeout(timeOut)
                    elif event.key == K_RIGHT:
                        if timeOut < 15:
                            timeOut += 1
                            self.showTimeout(timeOut)
                    elif event.key == K_UP:
                        menu.draw(-1) #here is the Menu class function
                    elif event.key == K_DOWN:
                        menu.draw(1) #here is the Menu class function
                    elif event.key == K_RETURN or event.key == K_SPACE:
                        if menu.get_position() == 0:
                            # rtnObject.players = ["h", "c"]
                            return ["h", "c"], timeOut, (event.key == K_SPACE)
                        elif menu.get_position() == 1:
                            # rtnObject.players =["c", "h"]
                            return ["c", "h"], timeOut, (event.key == K_SPACE)
                        elif menu.get_position() == 2:
                            # rtnObject.players =["c", "c"]
                            return ["c", "c"], timeOut, (event.key == K_SPACE)
                        elif menu.get_position() == 4:
                            pygame.display.quit()
                            sys.exit()
                    if event.key == K_ESCAPE:
                        pygame.display.quit()
                        sys.exit()
                    pygame.display.update()
                elif event.type == QUIT:
                    pygame.display.quit()
                    sys.exit()
开发者ID:schauhan19,项目名称:Othello-AI,代码行数:61,代码来源:gui.py

示例3: menu_game

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import get_position [as 别名]
def menu_game():                #Функция, извеждаща менюто
    pygame.mixer.init(44100, -16,2,2048) #Инициализация на миксера

#Промяна на иконата на прозореца
    icon = pygame.image.load("files/Skins/Martincho.png")
    icon = pygame.transform.scale(icon, (32, 32))
    pygame.display.set_icon(icon)

    pygame.mouse.set_visible(0)
#В заглавната лента се извежда името на играта 
    pygame.display.set_caption("RBP_V1.2")

#Избор на размер на прозореца 
    screen = pygame.display.set_mode(DISPLAY, pygame.FULLSCREEN) 

#Зареждане на фон на менюто
    background = pygame.image.load("files/Martinchovcite_menu1.png")
    background = pygame.transform.scale(background, (1450,805))
    screen.blit(background, (-40, -60))

#Пояснителен текст над менюто  
    font=pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',30)
    menutext=font.render("MENU", 1,(145,183,220))
    screen.blit(menutext, (720, 270))

    menu = Menu()   #Инициализация на менюто

#Задаване на цветовете на фона, маркера и текста на менюто 
    menu.set_colors((145,183,220),(36,36,168),(59,60,189))

#Задаване на размер на менюто 
    menu.set_fontsize(30)

#Задаване на позиция, където менюто ще бъде изведено     
    menu.move_menu(85, 37)

#Задаване на съдържанието 
    menu.init(['Start','Help','About','Quit'], screen)
#Изчертаване на менюто 
    menu.draw()
    pygame.key.set_repeat(199,69)
    
    pygame.display.update()
    sound = pygame.mixer.Sound('files/Sounds/menu.wav') #Задаване на музика
    sound.set_volume(0.05)                              #Задаване на сила на звука
    while 1:
        
        sound.play()                                    #Изпълнение на музиката
        for event in pygame.event.get():                #Проверка коя от опциите е избрана и изпълнение на съответната функция
            if event.type == KEYDOWN:
                if event.key == K_UP:
                    menu.draw(-1)
                if event.key == K_DOWN:
                    menu.draw(1)
                if event.key == K_RETURN:
                    if menu.get_position() == 0:
                        sound.stop()                        
                        game('Level_1', 3)
                    if menu.get_position() == 1:
                        sound.stop()                        
                        help()
                    if menu.get_position() == 2:
                        sound.stop()                                                
                        about()
                    if menu.get_position() == 3:
                        pygame.display.quit()
                        sys.exit()    
                if event.key == K_ESCAPE:
                    pygame.display.quit()
                    sys.exit()
                pygame.display.update()
            elif event.type == QUIT:
                pygame.display.quit()
                sys.exit()
        
        pygame.time.wait(8)
开发者ID:Plamen1466,项目名称:Robopartans_The_Game,代码行数:78,代码来源:RBP_Game.py


注:本文中的menu.Menu.get_position方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。