Beispiel #1
0
    def mouseReleaseEvent(self, a0: QMouseEvent):
        if self.is_over:  # 如果游戏已经结束,点击失效
            return
        # 如果点击在棋盘区域
        if a0.x() >= 50 and a0.x() <= 50 + 30 * 18 + 14 and a0.y(
        ) >= 50 and a0.y() <= 50 + 30 * 18 + 14:
            # 讲像素坐标转化成棋盘坐标,判断棋盘此位置是否为空
            pos = trans_pos(a0)
            if chessboard[pos[1]][pos[0]] is not None:
                return  # 如果对应位置不为空,说明有棋子,则直接返回

            # 不为空,则生成棋子并显示
            self.chess = Chessman(self.color, self)
            self.chess.move(a0.pos())
            self.logo_move()
            self.chess.show()
            self.change_color()
            pygame.mixer.music.play()

            # 在棋盘的对应位置放上棋子
            chessboard[pos[1]][pos[0]] = self.chess
            # 并且在列表中记录坐标
            history.append((pos[1], pos[0], self.chess.color))

            # 每次落子后,都判断一下胜负
            res = is_win(chessboard)
            if res:
                self.win(res)  # 通过颜色,显示胜利的图片
Beispiel #2
0
    def mouseReleaseEvent(self, a0: QMouseEvent):
        if self.is_over:  # 如果游戏已经结束,点击失效
            return
        if not self.my_turn:
            print("not my turn")
            return
        # 如果点击在棋盘区域
        if a0.x() >= 50 and a0.x() <= 50 + 30 * 19 and a0.y() >= 50 and a0.y(
        ) <= 50 + 30 * 19:

            # 讲像素坐标转化成棋盘坐标,判断棋盘此位置是否为空
            pos = trans_pos(a0)
            if chessboard[pos[1]][pos[0]] is not None:
                return  # 如果对应位置不为空,说明有棋子,则直接返回

            # 不为空,则生成棋子并显示
            self.chess = Chessman(self.color, self)
            self.chess.move(a0.pos())
            self.chess.show()
            pygame.mixer.music.play()  # 播放声音
            self.logo_move()  # 移动小标
            self.change_color()

            # 在棋盘的对应位置放上棋子
            chessboard[pos[1]][pos[0]] = self.chess
            # 并且在列表中记录坐标
            history.append((pos[1], pos[0], self.chess.color))
            # 将坐标发送给另一方
            if self.tcp_socket is not None:
                data = {"msg": "position", "data": pos}
                self.tcp_socket.sendall((json.dumps(data) + " END").encode())

            # 每次落子后,都判断一下胜负
            res = is_win(chessboard)
            if res:
                self.win(res)  # 通过颜色,显示胜利的图片
                return
            self.my_turn = False
            self.label_statuvalue.setText("对方回合")