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


Python Menu.move方法代码示例

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


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

示例1: MainWidget

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import move [as 别名]
class MainWidget(QWidget):
    def __init__(self, map, width, height):
        super(MainWidget, self).__init__()
        self.width = width
        self.height = height
        self.panelWidth = 300
        self.mapSize = 16
        self.map = map
        self.initUI(self.map)
        self.setAttribute(Qt.WA_PaintUnclipped)
        self.pressed = False

    def initUI(self, map):
        self.mapWidget =None
        self.menu = None
        self.hbox = None

        self.setGeometry(0, 0, self.width, self.height)
        self.move(100, 100)
        self.setWindowTitle('Map Generator, CodeName: BAD ASS HEROES')

        self.createLayout(map)
        self.show()



    def createLayout(self, map):
        self.hbox = QHBoxLayout()
        if self.mapWidget != None:
            self.mapWidget.setParent(None)
        if self.menu:
            self.menu.setParent(None)
        else:
            self.menu = Menu(self.panelWidth, 2 * self.mapSize + 1)
        
        self.mapWidget = MapWidget(map)
        self.connect(self.mapWidget, SIGNAL("mousePressed"), self.startDragging)
        self.connect(self.menu, SIGNAL("generateMap"), self.generate)
        self.connect(self.menu, SIGNAL("newSize"), self.changeSize)
        self.connect(self.menu, SIGNAL("save"), self.save)
        self.mapWidget.setSize(self.width - self.panelWidth, self.height)
        self.hbox.addWidget(self.mapWidget)
        self.hbox.addWidget(self.menu)
        self.menu.move(self.width - self.panelWidth, 0)    
        if self.layout() != None:
            sip.delete(self.layout())
        self.setLayout(self.hbox)
        

    def changeSize(self, size):
        self.mapSize = (size - 1) / 2
        
    def generate(self):
        mapgen = mapgenerator.MapGenerator(self.mapSize)
        self.pressed = False
        self.map = mapgen.getMap()
        self.mapWidget.setMap(self.map)
        self.show()

        
    def resizeEvent(self, ev):
        self.mapWidget.setSize(ev.size().width() - self.panelWidth, ev.size().height())
        self.menu.move(ev.size().width() - self.panelWidth, 0)

    def startDragging(self, event):
        self.pressed = True
        self.diff = (-event.x(), -event.y())

    def mouseReleaseEvent(self, event):
        self.pressed = False

    def mouseMoveEvent(self, event):
        if self.pressed:
            self.mapWidget.setPosition(event.x() + self.diff[0], event.y() + self.diff[1])

    def save(self, filename):
        f = open(filename, 'w')
        f.write(str(self.mapSize * 2 + 1))
        f.write("\n")
        for i in range(0, len(self.map)):
            for j in range(0, len(self.map[i])):
                if j > 0:
                    f.write(" ")
                f.write(str(self.map[i][j]))
            f.write("\n")

        f.close()
开发者ID:boogen,项目名称:mapgenerator,代码行数:89,代码来源:start.py

示例2: main

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import move [as 别名]
def main():
  pygame.init()
  pygame.mixer.music.load("rematch.mp3")
  pygame.mixer.music.play(-1)
  screen = pygame.display.set_mode((1000, 1000))
  clock = pygame.time.Clock()
  
  game_map = Map(0)
  player = Character( game_map, 23, 1 )
  
  prevKeys = {}
  
  menu = Menu()
  while True:
    for e in pygame.event.get():
      if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
        pygame.quit()
        return
    key = pygame.key.get_pressed()
    
    if key[K_DOWN] and not prevKeys[K_DOWN]:
      menu.move(1)
    if key[K_UP] and not prevKeys[K_UP]:
      menu.move(-1)
    if key[K_RETURN] and not prevKeys[K_RETURN]:
      r = menu.select()
      if r == -1:
        pygame.quit()
        return
      elif r == 1:
        break
        
    prevKeys = key
    
    menu.draw(screen)
    pygame.display.flip()
    
  
  while True:
    
    clock.tick(30)
    for e in pygame.event.get():
      if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
        pygame.quit()
        return
    key = pygame.key.get_pressed()
    
    if key[K_LSHIFT]:
      if key[K_UP] and not prevKeys[K_UP]:
        player.attack_up()
      elif key[K_DOWN] and not prevKeys[K_DOWN]:
        player.attack_down()
      elif key[K_LEFT] and not prevKeys[K_LEFT]:
        player.attack_left()
      elif key[K_RIGHT] and not prevKeys[K_RIGHT]:
        player.attack_right()
    else:
      if key[K_UP] and not prevKeys[K_UP]:
        player.move_up()
      elif key[K_DOWN] and not prevKeys[K_DOWN]:
        player.move_down()
      elif key[K_LEFT] and not prevKeys[K_LEFT]:
        player.move_left()
      elif key[K_RIGHT] and not prevKeys[K_RIGHT]:
        player.move_right()
    
    while game_map.isWin(player.position.real, player.position.imag):
      screen.blit(winScreen,(0,0))
      pygame.display.flip()
      for e in pygame.event.get():
        if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
          pygame.quit()
          return
    
    prevKeys = key
    game_map.draw(screen)
    player.draw(screen)
    
    
    
    pygame.display.flip()
开发者ID:origamize,项目名称:GameJamFall2011,代码行数:83,代码来源:main.py


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