[python] choco_sweeper_v2
ためらう
友达が早くダブルクリックをしてほしいという意见のもと、定処ノートが终わった后、ダブルクリック机能とセレクトグレード机能を追加し、チョコレートバージョン2を作成しました.バニラの上に芝生が建っていると言われていますが、私のバニラは地雷を探していますか?🤢 v 2最後に終わってチョコレート探し!
0.運転画面
選択レベル画面
画面のカスタマイズ
一次画面
1.ダブルクリックの確認
残念ながらpygameはダブルクリックしたライブラリを認識せず,直接実現する必要がある.
ダブルクリックできる条件は次のとおりです.
変更された[ボードをクリック]イベントが発生したときのコード
elif boardSurf.collidepoint(event.pos) : #board pressed
if startTime == 0: #timer on
startTime = time.time()
index = getBoardIndex(cellx, celly)
cell = board[index]
if cell['flag'] == OPENED:
flagCount = getFlagCount(board, cell)
doubleTime = time.time()
doubleCheck = checkDouble(doubleTime, event.pos)
if doubleCheck == 1 and cell['count'] == flagCount:
setAroundOpened(board, cell)
この格がOPENED
であることを確認した後、確認ダブルクリックを実行する関数checkDouble()
をダブルクリックし、地雷と旗の数が一致すれば、setAroundOpened()
を通じて旗を除いた特別なすべての周囲格を開く.ダブルクリックの確認
def checkDouble(doubleTime, firstPos):
passTime = 0
while( passTime < 0.5):
passTime = time.time() - doubleTime
for event in pygame.event.get():
if event.type == MOUSEBUTTONUP:
if event.pos == firstPos :
return 1
else:
return 0
500 ms以内で同じ座標でクリックイベントが発生した場合は1
に戻り、ダブルクリックが確認されていなければ0
に戻る.2.選択レベル
等級は全部で4種類に設定されている.
選択レベル
def showLevelScreen():
...
for event in pygame.event.get():
if event.type == QUIT:
terminate()
elif event.type == MOUSEBUTTONUP:
if beginnerRect.collidepoint((event.pos[0], event.pos[1])):
playButtonSound()
return 15, 10, 20
elif intermediateRect.collidepoint((event.pos[0], event.pos[1])):
playButtonSound()
return 20, 20, 80
elif advancedRect.collidepoint((event.pos[0], event.pos[1])):
playButtonSound()
return 30, 20, 120
elif customRect.collidepoint((event.pos[0], event.pos[1])):
playButtonSound()
wNum, hNum, pNum = showCustomScreen(customRect)
if wNum ==0 and hNum==0 and pNum==0:
continue
return wNum, hNum , pNum
各レベルに適した横、縦、地雷を返します.カスタム・レベルの場合、
showCustomScreen()
を実行してユーザ入力を受信することができる.カスタムレベル入力を受け入れる
def showCustomScreen(customRect):
...
textType = None
wText = ""
hText = ""
pText = ""
wColor = BGCOLOR
hColor = BGCOLOR
pColor = BGCOLOR
while(True):
for event in pygame.event.get():
if event.type == QUIT:
terminate()
elif event.type == MOUSEBUTTONUP:
if customWTBoxRect.collidepoint((event.pos[0], event.pos[1])):
wColor = LINECOLOR
hColor = BGCOLOR
pColor = BGCOLOR
textType = 'W'
elif customHTBoxRect.collidepoint((event.pos[0], event.pos[1])):
hColor = LINECOLOR
wColor = BGCOLOR
pColor = BGCOLOR
textType = 'H'
elif customPTBoxRect.collidepoint((event.pos[0], event.pos[1])):
pColor = LINECOLOR
wColor = BGCOLOR
hColor = BGCOLOR
textType = 'P'
elif customButtonRect.collidepoint((event.pos[0], event.pos[1])):
playButtonSound()
try :
wNum = int(wText)
hNum = int(hText)
pNum = int(pText)
except ValueError :
message = "1~100 사이의 숫자를 입력하세요!"
drawErrorMessage(message)
else:
if wNum < 15 or wNum > 60:
message = "15~60 사이의 가로 숫자를 입력하세요!"
drawErrorMessage(message)
elif hNum < 10 or hNum > 30:
message = "10~30 사이의 세로 숫자를 입력하세요!"
drawErrorMessage(message)
elif pNum < 1:
message = "0보다 큰 지뢰의 숫자를 입력하세요!"
drawErrorMessage(message)
elif pNum >= wNum * hNum:
message = "칸 수보다 적은 지뢰의 숫자를 "
drawErrorMessage(message)
else:
return wNum, hNum, pNum
elif customBackRect.collidepoint((event.pos[0], event.pos[1])):
playButtonSound()
return 0, 0, 0
選択したボックスをマウスで表示します.入力された数値が予め定義された数値範囲を超えている場合、エラーメッセージはdrawErrorMessage()
で出力されます.
elif event.type == KEYDOWN:
if textType == 'W':
if event.key == K_BACKSPACE:
wText = wText[:-1]
else:
if len(wText) < 2:
wText += event.unicode
elif textType == 'H':
if event.key == K_BACKSPACE:
hText = hText[:-1]
else:
if len(hText) < 2:
hText += event.unicode
elif textType == 'P':
if event.key == K_BACKSPACE:
pText = pText[:-1]
else:
if len(pText) < 2:
pText += event.unicode
選択したボックスに数字を入力します.3.完全なコードは..。
旗の下で...💩
https://github.com/yevini118/choco_sweeper
エイリアンコードか?👽
私は本当に怠け者で、数ヶ月後にこの投稿を書き続けました.🙃 百万年も书いていない招待状を书き直して、私のコードですが、何なのか分かりません.いつか退屈な私がファンデーションをやり直して、虫の招待状を终えると信じています^^!
-choco sweeeeperシリーズ終了-
Reference
この問題について([python] choco_sweeper_v2), 我々は、より多くの情報をここで見つけました https://velog.io/@yevini118/python-chocosweeperv2テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol