最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python3利用Qt5實(shí)現(xiàn)簡(jiǎn)易的五子棋游戲

 更新時(shí)間:2022年05月02日 11:45:23   作者:WXjzcccc  
這篇文章主要為大家詳細(xì)介紹了Python3利用Qt5實(shí)現(xiàn)簡(jiǎn)易的五子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

要寫(xiě)出一個(gè)五子棋游戲,我們最先要解決的,就是如何下子,如何判斷已經(jīng)五子連珠,而不是如何繪制畫(huà)面,因此我們先確定棋盤(pán)

五子棋采用15*15的棋盤(pán),因此,我們可以使用二維列表來(lái)創(chuàng)建一個(gè)棋盤(pán),不妨認(rèn)為0表示未放置棋子,1表示放置白子,2表示放置黑子。

顯而易見(jiàn)可以創(chuàng)建列表,注意不能使用*來(lái)復(fù)制列表

self.chess_board = [[0 for i in range(15)] for i in range(15)]

下棋的步驟十分好做,只需要找到對(duì)應(yīng)的索引進(jìn)行賦值即可,下一步應(yīng)該解決如何判斷五子連珠的問(wèn)題。

每當(dāng)我們落子結(jié)束后,應(yīng)該判斷是否已經(jīng)完成五子連珠。對(duì)于剛放置的一顆棋子而言,可能的情況大致分為四種:

1.水平
2.斜向右下
3.豎直
4.斜向右上

要判斷是否已經(jīng)連珠成功,我們以剛放置的棋子為起點(diǎn),先向前遍歷4個(gè)棋子,并計(jì)算相同棋子的個(gè)數(shù),一旦遇到不同的棋子,就停止,然后從起點(diǎn)向后遍歷4個(gè)棋子,直到全部遍歷完成或者棋子總數(shù)已經(jīng)達(dá)到5個(gè),就可以返回。我們只需要注意如何獲得棋子的前后棋子以及棋盤(pán)的邊界問(wèn)題,棋子不可能超出棋盤(pán),因此被遍歷的棋子也不能超出棋盤(pán)。

以水平為例,可以得到代碼

def judge_1(self,x:int,y:int) -> bool:
? ? ? ? count = 1
? ? ? ? if self.chess_board[x][y] != 0:
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if y - i >= 0:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x][y-i]:
? ? ? ? ? ? ? ? ? ? ? ? print(x,y-i)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if y + i <=14:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x][y+i]:
? ? ? ? ? ? ? ? ? ? ? ? print(x,y+i)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? if count == 5:
? ? ? ? ? ? return True
? ? ? ? return False

以相似的步驟完成其余三種判斷,就已經(jīng)完成了五子棋游戲的核心要素了,剩下的就需要交給PyQt5來(lái)完成游戲的繪制來(lái)完善游戲了。

我們創(chuàng)建一個(gè)類(lèi)來(lái)繼承QWidget類(lèi),創(chuàng)建一個(gè)窗口,之后我們需要?jiǎng)?chuàng)建幾個(gè)屬性來(lái)完成儲(chǔ)存我們的數(shù)據(jù)信息

#棋子的坐標(biāo)
self.x = -1
self.y = -1
#區(qū)分玩家
#開(kāi)始標(biāo)簽
self.flag = False
#儲(chǔ)存已經(jīng)下好的白子
self.white_chess = []
#儲(chǔ)存已經(jīng)下好的黑子
self.black_chess = []

我們已經(jīng)可以開(kāi)始繪制棋盤(pán),在Qt5中,如果我們需要進(jìn)行繪制,我們應(yīng)該重寫(xiě)paintEvent方法,這個(gè)方法會(huì)由程序自動(dòng)調(diào)用執(zhí)行。創(chuàng)建一個(gè)QPainter對(duì)象,將需要繪制的內(nèi)容用begin與end方法包裹起來(lái),就可以完成繪制。

我們用drawLine方法來(lái)繪制線條,用drawEllipse方法來(lái)繪制棋子,使用setPen來(lái)更改線條樣式,setBrush來(lái)更改棋子樣式。

得到代碼(本段代碼有參考他人代碼,這是我第一次接觸Qt的繪制)

--------------------GUI中的x軸豎直向下,y軸水平向右,因此繪制棋子時(shí)的x與y需要顛倒---------------

#繪制棋盤(pán)與棋子
? ? def paintEvent(self, e) -> None:
? ? ? ? qp = QPainter()
? ? ? ? qp.begin(self)
? ? ? ? qp.fillRect(self.rect(), QColor("light blue"))
? ? ? ? qp.drawRect(self.rect())
? ? ? ? qp.setBackground(QColor("yellow"))
? ? ? ? qp.setPen(QPen(QColor(0, 0, 0), 2, Qt.SolidLine))
? ? ? ? for i in range(15):
? ? ? ? ? ? qp.drawLine(QPoint(30, 30 + 30 * i), QPoint(450, 30 + 30 * i))
? ? ? ? for i in range(15):
? ? ? ? ? ? qp.drawLine(QPoint(30 + 30 * i, 30), QPoint(30 + 30 * i, 450))
? ? ? ? qp.setBrush(QColor(0, 0, 0))
? ? ? ? key_points = [(3, 3), (11, 3), (3, 11), (11, 11), (7, 7)]
? ? ? ? if len(self.black_chess) != 0:
? ? ? ? ? ? for t in self.black_chess:
? ? ? ? ? ? ? ? #畫(huà)黑子
? ? ? ? ? ? ? ? qp.drawEllipse(QPoint(30 + 30 * t[1], 30 + 30 * t[0]), 6, 6)
? ? ? ? for t in key_points:
? ? ? ? ? ? #棋盤(pán)的5個(gè)定點(diǎn)
? ? ? ? ? ? qp.drawEllipse(QPoint(30 + 30 * t[0], 30 + 30 * t[1]), 3, 3)
? ? ? ? qp.setBrush(QColor(255,255,255))
? ? ? ? if len(self.white_chess) != 0:
? ? ? ? ? ? for t in self.white_chess:
? ? ? ? ? ? ? ? #畫(huà)白子
? ? ? ? ? ? ? ? qp.drawEllipse(QPoint(30 + 30 * t[1], 30 + 30 * t[0]), 6, 6)
? ? ? ? qp.end()

另一個(gè)需要在GUI中解決的問(wèn)題就是,如何獲取要下的棋子的坐標(biāo)?我們可以通過(guò)重寫(xiě)鼠標(biāo)事件來(lái)解決,重寫(xiě)單機(jī)事件mousePressEvent,并修改棋子的x坐標(biāo)與y坐標(biāo)即可,另外,用戶不可能每次都恰巧點(diǎn)到我們規(guī)定的坐標(biāo)點(diǎn)上,因此需要給出一個(gè)大致范圍判斷,這里我的方式是先獲取坐標(biāo),然后根據(jù)坐標(biāo)找到距離最近的點(diǎn)

def mousePressEvent(self, e) -> None:
? ? ? ? if e.buttons() == QtCore.Qt.LeftButton:
? ? ? ? ? ? if e.x() > 15 and e.x() < 465 and e.y() > 15 and e.y() < 465:
? ? ? ? ? ? ? ? x = e.x()/30 - e.x()//30
? ? ? ? ? ? ? ? y = e.y()/30 - e.y()//30
? ? ? ? ? ? ? ? self.y = (e.x()-30)//30 if x < 0.5 else (e.x()-30)//30 + 1
? ? ? ? ? ? ? ? self.x = (e.y()-30)//30 if y < 0.5 else (e.y()-30)//30 + 1
? ? ? ? ? ? ? ? if self.flag:
? ? ? ? ? ? ? ? ? ? print(self.x,self.y)
? ? ? ? ? ? ? ? ? ? if self.player % 2 == 1:
? ? ? ? ? ? ? ? ? ? ? ? if goBang.put_white_chess(self.x,self.y):
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.player += 1?
? ? ? ? ? ? ? ? ? ? ? ? ? ? print('黑子行動(dòng)')
? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? print('白子行動(dòng)')
? ? ? ? ? ? ? ? ? ? ? ? if goBang.judge(self.x,self.y):
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg_box = QMessageBox(QMessageBox.Information, '提示', '白子獲勝!')
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg_box.exec_()
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? if goBang.put_black_chess(self.x,self.y):
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.player += 1
? ? ? ? ? ? ? ? ? ? ? ? ? ? print('白子行動(dòng)')
? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? print('黑子行動(dòng)')
? ? ? ? ? ? ? ? ? ? ? ? if goBang.judge(self.x,self.y):
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg_box = QMessageBox(QMessageBox.Information, '提示', '黑子獲勝!')
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg_box.exec_()

每當(dāng)游戲完成,我們應(yīng)該可以清空棋盤(pán),也就是將所有儲(chǔ)存數(shù)據(jù)的變量都重新初始化再重繪棋盤(pán)

#清除棋盤(pán),重開(kāi)游戲
? ? def clear(self) -> None:
? ? ? ? self.x = -1
? ? ? ? self.y = -1
? ? ? ? self.player = 0
? ? ? ? self.flag = False
? ? ? ? self.white_chess = []
? ? ? ? self.black_chess = []
? ? ? ? self.chess_board = [[0 for i in range(15)] for i in range(15)]
? ? ? ? self.update()

這樣就大致結(jié)束了!!

下面是全部代碼:

from PyQt5 import *
from PyQt5 import QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
?
class GoBang(QWidget):
? ? #初始化棋盤(pán)
? ? def __init__(self):
? ? ? ? super().__init__()
? ? ? ? self.setWindowTitle('五子棋Hi~ o(* ̄▽?zhuān)?)ブ')
? ? ? ? self.x = -1
? ? ? ? self.y = -1
? ? ? ? #區(qū)分玩家
? ? ? ? self.player = 0
? ? ? ? #開(kāi)始標(biāo)簽
? ? ? ? self.flag = False
? ? ? ? #儲(chǔ)存已經(jīng)下好的白子
? ? ? ? self.white_chess = []
? ? ? ? #儲(chǔ)存已經(jīng)下好的黑子
? ? ? ? self.black_chess = []
? ? ? ? self.setFixedSize(800,600)
? ? ? ? self.chess_board = [[0 for i in range(15)] for i in range(15)]
? ? ? ? btn1 = QPushButton('開(kāi)始',self)
? ? ? ? btn1.setGeometry(500,100,50,30)
? ? ? ? btn1.clicked.connect(self.setFlag)
? ? ? ? btn2 = QPushButton('重開(kāi)',self)
? ? ? ? btn2.setGeometry(550,100,50,30)
? ? ? ? btn2.clicked.connect(self.clear)
? ? ? ? self.show()
? ??
? ? #繪制棋盤(pán)與棋子
? ? def paintEvent(self, e) -> None:
? ? ? ? qp = QPainter()
? ? ? ? qp.begin(self)
? ? ? ? qp.fillRect(self.rect(), QColor("light blue"))
? ? ? ? qp.drawRect(self.rect())
? ? ? ? qp.setBackground(QColor("yellow"))
? ? ? ? qp.setPen(QPen(QColor(0, 0, 0), 2, Qt.SolidLine))
? ? ? ? for i in range(15):
? ? ? ? ? ? qp.drawLine(QPoint(30, 30 + 30 * i), QPoint(450, 30 + 30 * i))
? ? ? ? for i in range(15):
? ? ? ? ? ? qp.drawLine(QPoint(30 + 30 * i, 30), QPoint(30 + 30 * i, 450))
? ? ? ? qp.setBrush(QColor(0, 0, 0))
? ? ? ? key_points = [(3, 3), (11, 3), (3, 11), (11, 11), (7, 7)]
? ? ? ? if len(self.black_chess) != 0:
? ? ? ? ? ? for t in self.black_chess:
? ? ? ? ? ? ? ? #畫(huà)黑子
? ? ? ? ? ? ? ? qp.drawEllipse(QPoint(30 + 30 * t[1], 30 + 30 * t[0]), 6, 6)
? ? ? ? for t in key_points:
? ? ? ? ? ? #棋盤(pán)的5個(gè)定點(diǎn)
? ? ? ? ? ? qp.drawEllipse(QPoint(30 + 30 * t[0], 30 + 30 * t[1]), 3, 3)
? ? ? ? qp.setBrush(QColor(255,255,255))
? ? ? ? if len(self.white_chess) != 0:
? ? ? ? ? ? for t in self.white_chess:
? ? ? ? ? ? ? ? #畫(huà)白子
? ? ? ? ? ? ? ? qp.drawEllipse(QPoint(30 + 30 * t[1], 30 + 30 * t[0]), 6, 6)
? ? ? ? qp.end()
?
? ? #更改標(biāo)簽,開(kāi)始游戲
? ? def setFlag(self) -> None:
? ? ? ? self.flag = True
?
? ? def mousePressEvent(self, e) -> None:
? ? ? ? if e.buttons() == QtCore.Qt.LeftButton:
? ? ? ? ? ? if e.x() > 15 and e.x() < 465 and e.y() > 15 and e.y() < 465:
? ? ? ? ? ? ? ? x = e.x()/30 - e.x()//30
? ? ? ? ? ? ? ? y = e.y()/30 - e.y()//30
? ? ? ? ? ? ? ? self.y = (e.x()-30)//30 if x < 0.5 else (e.x()-30)//30 + 1
? ? ? ? ? ? ? ? self.x = (e.y()-30)//30 if y < 0.5 else (e.y()-30)//30 + 1
? ? ? ? ? ? ? ? if self.flag:
? ? ? ? ? ? ? ? ? ? print(self.x,self.y)
? ? ? ? ? ? ? ? ? ? if self.player % 2 == 1:
? ? ? ? ? ? ? ? ? ? ? ? if goBang.put_white_chess(self.x,self.y):
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.player += 1?
? ? ? ? ? ? ? ? ? ? ? ? ? ? print('黑子行動(dòng)')
? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? print('白子行動(dòng)')
? ? ? ? ? ? ? ? ? ? ? ? if goBang.judge(self.x,self.y):
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg_box = QMessageBox(QMessageBox.Information, '提示', '白子獲勝!')
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg_box.exec_()
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? if goBang.put_black_chess(self.x,self.y):
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.player += 1
? ? ? ? ? ? ? ? ? ? ? ? ? ? print('白子行動(dòng)')
? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? print('黑子行動(dòng)')
? ? ? ? ? ? ? ? ? ? ? ? if goBang.judge(self.x,self.y):
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg_box = QMessageBox(QMessageBox.Information, '提示', '黑子獲勝!')
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg_box.exec_()
?
? ? ? ? ? ??
? ? #下白子
? ? def put_white_chess(self,x:int,y:int) -> bool:
? ? ? ? if self.chess_board[x][y] != 0:
? ? ? ? ? ? msg_box = QMessageBox(QMessageBox.Information, '提示', '這個(gè)位置已經(jīng)有棋子了!')
? ? ? ? ? ? msg_box.exec_()
? ? ? ? ? ? return False
? ? ? ? else:
? ? ? ? ? ? self.chess_board[x][y] = 1
? ? ? ? ? ? self.white_chess.append((x,y))
? ? ? ? ? ? self.update()
? ? ? ? ? ? return True
?
? ? #下黑子
? ? def put_black_chess(self,x:int,y:int) -> bool:
? ? ? ? if self.chess_board[x][y] != 0:
? ? ? ? ? ? msg_box = QMessageBox(QMessageBox.Information, '提示', '這個(gè)位置已經(jīng)有棋子了!')
? ? ? ? ? ? msg_box.exec_()
? ? ? ? ? ? return False
? ? ? ? else:
? ? ? ? ? ? self.chess_board[x][y] = 2
? ? ? ? ? ? self.black_chess.append((x,y))
? ? ? ? ? ? self.update()
? ? ? ? ? ? return True
?
? ? #清除棋盤(pán),重開(kāi)游戲
? ? def clear(self) -> None:
? ? ? ? self.x = -1
? ? ? ? self.y = -1
? ? ? ? self.player = 0
? ? ? ? self.flag = False
? ? ? ? self.white_chess = []
? ? ? ? self.black_chess = []
? ? ? ? self.chess_board = [[0 for i in range(15)] for i in range(15)]
? ? ? ? self.update()
?
? ? #判斷是否已經(jīng)五子連珠
? ? def judge(self,x:int,y:int) -> bool:
? ? ? ? if self.judge_1(x,y) or self.judge_2(x,y) or self.judge_3(x,y) or self.judge_4(x,y):
? ? ? ? ? ? return True
? ? ? ? return False
?
? ? #判斷橫線
? ? def judge_1(self,x:int,y:int) -> bool:
? ? ? ? count = 1
? ? ? ? if self.chess_board[x][y] != 0:
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if y - i >= 0:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x][y-i]:
? ? ? ? ? ? ? ? ? ? ? ? print(x,y-i)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if y + i <=14:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x][y+i]:
? ? ? ? ? ? ? ? ? ? ? ? print(x,y+i)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? if count == 5:
? ? ? ? ? ? return True
? ? ? ? return False
?
? ? #判斷右下線
? ? def judge_2(self,x:int,y:int) -> bool:
? ? ? ? count = 1
? ? ? ? if self.chess_board[x][y] != 0:
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if x-i >= 0 and y - i >= 0:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x-i][y-i]:
? ? ? ? ? ? ? ? ? ? ? ? print(x-i,y-i)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if x + i <= 14 and y + i <= 14:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x+i][y+i]:
? ? ? ? ? ? ? ? ? ? ? ? print(x+i,y+i)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? if count == 5:
? ? ? ? ? ? return True
? ? ? ? return False
?
? ? #判斷豎線
? ? def judge_3(self,x:int,y:int) -> bool:
? ? ? ? count = 1
? ? ? ? if self.chess_board[x][y] != 0:
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if x - i >= 0:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x-i][y]:
? ? ? ? ? ? ? ? ? ? ? ? print(x-i,y)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if x + i <= 14:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x+i][y]:
? ? ? ? ? ? ? ? ? ? ? ? print(x+i,y)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? if count == 5:
? ? ? ? ? ? return True
? ? ? ? return False
?
? ? #判斷右上線
? ? def judge_4(self,x:int,y:int) -> bool:
? ? ? ? count = 1
? ? ? ? if self.chess_board[x][y] != 0:
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if x - i >= 0 and y + i <= 14:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x-i][y+i]:
? ? ? ? ? ? ? ? ? ? ? ? print(x-i,y+i)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? for i in range(1,5):
? ? ? ? ? ? ? ? if x + i <= 14 and y - i >= 0:
? ? ? ? ? ? ? ? ? ? if self.chess_board[x][y] == self.chess_board[x+i][y-i]:
? ? ? ? ? ? ? ? ? ? ? ? print(x+i,y-i)
? ? ? ? ? ? ? ? ? ? ? ? count += 1
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? break
? ? ? ? if count == 5:
? ? ? ? ? ? return True
? ? ? ? return False
?
#程序入口
if __name__ == '__main__': ?
? ? app = QApplication(sys.argv) ?
? ? goBang = GoBang()
? ? sys.exit(app.exec_())

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Pandas加速代碼之避免使用for循環(huán)

    Pandas加速代碼之避免使用for循環(huán)

    如果你使用Python和Pandas進(jìn)行數(shù)據(jù)分析,循環(huán)是不可避免要使用的。這篇文章主要給大家介紹了關(guān)于Pandas加速代碼之避免使用for循環(huán)的相關(guān)資料,需要的朋友可以參考下
    2021-05-05
  • Django?ORM?多表查詢(xún)示例代碼

    Django?ORM?多表查詢(xún)示例代碼

    這篇文章主要介紹了Django?ORM?多表查詢(xún),本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-09-09
  • 使用Keras加載含有自定義層或函數(shù)的模型操作

    使用Keras加載含有自定義層或函數(shù)的模型操作

    這篇文章主要介紹了使用Keras加載含有自定義層或函數(shù)的模型操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-06-06
  • Python 數(shù)據(jù)的累加與統(tǒng)計(jì)的示例代碼

    Python 數(shù)據(jù)的累加與統(tǒng)計(jì)的示例代碼

    這篇文章主要介紹了Python 數(shù)據(jù)的累加與統(tǒng)計(jì)的示例代碼,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • Python爬蟲(chóng)實(shí)現(xiàn)selenium處理iframe作用域問(wèn)題

    Python爬蟲(chóng)實(shí)現(xiàn)selenium處理iframe作用域問(wèn)題

    這篇文章主要介紹了Python爬蟲(chóng)實(shí)現(xiàn)selenium處理iframe作用域問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • Python Opencv中用compareHist函數(shù)進(jìn)行直方圖比較對(duì)比圖片

    Python Opencv中用compareHist函數(shù)進(jìn)行直方圖比較對(duì)比圖片

    這篇文章主要介紹了Python Opencv中用compareHist函數(shù)進(jìn)行直方圖比較進(jìn)行對(duì)比圖片,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-04-04
  • Pandas DataFrame 篩選數(shù)據(jù)幾種方法實(shí)現(xiàn)

    Pandas DataFrame 篩選數(shù)據(jù)幾種方法實(shí)現(xiàn)

    本文介紹了四種在DataFrame中篩選數(shù)據(jù)的方法:根據(jù)字段、標(biāo)簽、位置、布爾索引和通過(guò)query進(jìn)行篩選,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-12-12
  • python3 正則表達(dá)式基礎(chǔ)廖雪峰

    python3 正則表達(dá)式基礎(chǔ)廖雪峰

    正則表達(dá)式是一種用來(lái)匹配字符串的強(qiáng)有力的武器。它的設(shè)計(jì)思想是用一種描述性的語(yǔ)言來(lái)給字符串定義一個(gè)規(guī)則,凡是符合規(guī)則的字符串,我們就認(rèn)為它“匹配”了,否則,該字符串就是不合法的
    2020-03-03
  • python實(shí)現(xiàn)回旋矩陣方式(旋轉(zhuǎn)矩陣)

    python實(shí)現(xiàn)回旋矩陣方式(旋轉(zhuǎn)矩陣)

    今天小編就為大家分享一篇python實(shí)現(xiàn)回旋矩陣方式(旋轉(zhuǎn)矩陣),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-12-12
  • 淺談對(duì)Python變量的一些認(rèn)識(shí)理解

    淺談對(duì)Python變量的一些認(rèn)識(shí)理解

    變量(variable)是編程的基礎(chǔ)概念,Python 的變量看似簡(jiǎn)單,深入了解卻不易.文中有非常詳細(xì)的介紹及代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們很有幫助,需要的朋友可以參考下
    2021-05-05

最新評(píng)論

平湖市| 南宁市| 泾川县| 保康县| 扎兰屯市| 通渭县| 惠州市| 齐齐哈尔市| 万宁市| 广灵县| 云龙县| 承德县| 平江县| 甘泉县| 仙居县| 贵州省| 剑川县| 大新县| 清苑县| 大悟县| 馆陶县| 淅川县| 北流市| 合阳县| 酉阳| 乌拉特后旗| 新乡县| 陆丰市| 临桂县| 界首市| 泰兴市| 深州市| 渭南市| 大荔县| 石棉县| 神池县| 鹤庆县| 北京市| 井陉县| 齐齐哈尔市| 元江|