コード例 #1
0
 def movePiece(self, x, y):
     chessboard.get((self.active_x, self.active_y)).move(x, y)
     chessboard[(x, y)] = chessboard.get((self.active_x, self.active_y))
     del chessboard[(self.active_x, self.active_y)]
     self.deselectAll()
     self.refreshPiece()
     self.next_move = not self.next_move
 
     if not self.black_king.alive:
         dialog = QtGui.QDialog()
     elif not self.white_king.alive:
         QMessageBox.about(self, "Black wins.", "")
コード例 #2
0
 def slotClicked(self, x, y):
     if chessboard.has_key((x, y)) and labels.get((x, y)).styleSheet() == "background: #00f":
         chessboard.get((x, y)).makeNotAlive()
         self.movePiece(x, y)
     elif chessboard.has_key((x, y)):
         if chessboard.get((x, y)).color == self.next_move:
             for i in xrange(8):
                 for j in xrange(8):
                     labels[(i, j)].setStyleSheet(self.style[(i+j) % 2])
                     if chessboard.get((x, y)).moveValidator(i, j) and not chessboard.get((x, y)).isSelfHere(i, j):
                         labels.get((i, j)).setStyleSheet("background: #00f")
                     else:
                         labels.get((x, y)).setStyleSheet(self.style[(i+j) % 2])
                         labels.get((x, y)).setStyleSheet("background: #f00")
                         self.active_x = x
                         self.active_y = y
     elif labels.get((x, y)).styleSheet() == "background: #00f":
         self.movePiece(x, y)
コード例 #3
0
 def refreshPiece(self):
     for i in xrange(8):
         for j in xrange(8):
             if chessboard.has_key((i, j)):
                 piece = chessboard.get((i, j))
                 if piece.alive:
                     if piece.color:
                         labels.get((i, j)).setImagePiece(piece.src_black)
                     else:
                         labels.get((i, j)).setImagePiece(piece.src_white)
             else:
                 labels.get((i, j)).setImagePiece("")