예제 #1
0
 def __init__(self,game,board,config,parent=None):
   super(UI_GameWindow,self).__init__(parent)
   self.game = game
   self.board = board
   self.ui_board = UI_Board(game,board,config,self)
   self.ui_sidebar = UI_BoardSidebar(game,self)
   
   #arrange layout
   windowLayout = QHBoxLayout()
   windowLayout.addWidget(self.ui_board)
   windowLayout.addWidget(self.ui_sidebar)
   self.setLayout(windowLayout)
   
   #handle signals
   self.connect(self.ui_sidebar,SIGNAL("endGame"),self.endGame)
   self.connect(self.ui_sidebar,SIGNAL("continueGame"),self.continueGame)
   self.connect(self.ui_sidebar,SIGNAL("resultButtonClicked"),self.resultButtonClicked)
   self.connect(self.ui_board,SIGNAL("updateDeaths"),self.updateDeaths)
예제 #2
0
class UI_GameWindow(QWidget):
  def __init__(self,game,board,config,parent=None):
    super(UI_GameWindow,self).__init__(parent)
    self.game = game
    self.board = board
    self.ui_board = UI_Board(game,board,config,self)
    self.ui_sidebar = UI_BoardSidebar(game,self)
    
    #arrange layout
    windowLayout = QHBoxLayout()
    windowLayout.addWidget(self.ui_board)
    windowLayout.addWidget(self.ui_sidebar)
    self.setLayout(windowLayout)
    
    #handle signals
    self.connect(self.ui_sidebar,SIGNAL("endGame"),self.endGame)
    self.connect(self.ui_sidebar,SIGNAL("continueGame"),self.continueGame)
    self.connect(self.ui_sidebar,SIGNAL("resultButtonClicked"),self.resultButtonClicked)
    self.connect(self.ui_board,SIGNAL("updateDeaths"),self.updateDeaths)
  
  def updateDeaths(self):  
    self.ui_sidebar.blackDeaths.setText(repr(self.board.whiteDeaths))
    self.ui_sidebar.whiteDeaths.setText(repr(self.board.blackDeaths))
  def endGame(self):
    self.ui_sidebar.resultButton.setEnabled(True) 
    self.ui_sidebar.resignButton.setEnabled(False)
    self.ui_sidebar.passButton.setEnabled(False)
    self.ui_board.changeMode(UI_Board.END_MODE)
    QMessageBox.question(self, "GO","Remove dead stones and click Result",QMessageBox.Ok)
  def continueGame(self):
    self.ui_sidebar.restoreButtonConfig()
    self.ui_board.clearDeaths()
    self.ui_board.changeMode(UI_Board.GAME_MODE)
    self.ui_board.update()
  def resultButtonClicked(self):
    self.ui_board.changeMode(UI_Board.FROZEN_MODE) 
    result = self.game.getResult(self.ui_board.deaths)
    self.ui_board.marks["black"].extend(result["blackMarks"])
    self.ui_board.marks["white"].extend(result["whiteMarks"])
    self.ui_board.update()
    reply = QMessageBox.question(self,"Game Result",self.game.printResult(),\
                                 QMessageBox.Yes|QMessageBox.No)
    if (reply == QMessageBox.Yes):
      self.game.isOver = True
    else:
      self.ui_board.changeMode(UI_Board.GAME_MODE)
      self.ui_board.clearmarks()
      self.ui_board.clearDeaths()
      self.ui_sidebar.restoreButtonConfig()
      self.ui_board.update()