91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 7.09MB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-11-05
  • 語(yǔ)言: Python
  • 標(biāo)簽: wuziqi??python??pygame??game??

資源簡(jiǎn)介

用python中pygame模塊開(kāi)發(fā)的五子棋小游戲,實(shí)現(xiàn)功能:下棋,悔棋,重新開(kāi)始,退出游戲,判贏,另附背景圖片,背景音樂(lè)。

資源截圖

代碼片段和文件信息

import?numpy?as?np
import?pygame
import?sys
import?traceback
import?copy
from?pygame.locals?import?*


pygame.init()
pygame.mixer.init()

#顏色
background=(201202187)
checkerboard=(000)
button=(525344)



#音樂(lè)
play_chess_sound?=?pygame.mixer.Sound(“music/play_chess.wav“)
play_chess_sound.set_volume(0.2)
button_sound?=?pygame.mixer.Sound(“music/button.wav“)
button_sound.set_volume(0.2)
victor_sound?=?pygame.mixer.Sound(“music/victory.wav“)
victor_sound.set_volume(0.2)

#繪制棋盤
def?Draw_a_chessboard(screen):??
????#填充背景色
????screen.fill(background)
????Background=pygame.image.load(“background.jpg“).convert_alpha()
????screen.blit(Background(00))
????#畫棋盤
????for?i?in?range(21):
????????pygame.draw.line(screen?checkerboard?(40*i+3?3)?(40*i+3?803))?
????????pygame.draw.line(screen?checkerboard?(3?40*i+3)?(803?40*i+3))
????#畫邊線
????pygame.draw.line(screen?checkerboard?(3?3)?(803?3)5)???
????pygame.draw.line(screen?checkerboard?(3?3)?(3?803)5)???
????pygame.draw.line(screen?checkerboard?(803?3)?(803?803)5)???
????pygame.draw.line(screen?checkerboard?(3?803)?(803?803)5)?
????
????#畫定位點(diǎn)
????pygame.draw.circle(screen?checkerboard?(163?163)?6)?
????pygame.draw.circle(screen?checkerboard?(163?643)?6)?
????pygame.draw.circle(screen?checkerboard?(643?163)?6)?
????pygame.draw.circle(screen?checkerboard?(643?643)?6)?
????pygame.draw.circle(screen?checkerboard?(403?403)?6)?
????
????#畫‘悔棋’‘重新開(kāi)始’跟‘退出’按鈕
????pygame.draw.rect(screenbutton[900350120100]5)
????pygame.draw.rect(screenbutton[900500200100]5)
????pygame.draw.rect(screenbutton[900650200100]5)
????s_font=pygame.font.Font(‘font.ttf‘40)
????text1=s_font.render(“悔棋“Truebutton)
????text2=s_font.render(“重新開(kāi)始“Truebutton)
????text3=s_font.render(“退出游戲“Truebutton)
????screen.blit(text1(920370))
????screen.blit(text2(920520))
????screen.blit(text3(920670))

#繪制棋子(橫坐標(biāo),縱坐標(biāo),屏幕,棋子顏色(1代表黑,2代表白))
def?Draw_a_chessman(xyscreencolor):????
????if?color==1:????????
????????Black_chess=pygame.image.load(“Black_chess.png“).convert_alpha()
????????screen.blit(Black_chess(40*x+3-1540*y+3-15))
????if?color==2:
????????White_chess=pygame.image.load(“White_chess.png“).convert_alpha()
????????screen.blit(White_chess(40*x+3-1540*y+3-15))

#繪制帶有棋子的棋盤
def?Draw_a_chessboard_with_chessman(mapscreen):??
????screen.fill(background)
????Draw_a_chessboard(screen)
????for?i?in?range(24):
????????for?j?in?range(24):
????????????Draw_a_chessman(i+1j+1screenmap[i][j])



#定義存儲(chǔ)棋盤的列表
#列表為24列24行是因?yàn)榕袛嗍欠駝倮瘮?shù)里的索引會(huì)超出19
#列表大一點(diǎn)不會(huì)對(duì)游戲有什么影響
map=[]
for?i?in?range(24):
????map.append([000000000000000000000000])

#清零map列表
def?clear():
????global?map
????for?i?in?range(24):
????????for?j?in?range(24):
????????????map[i][j]=0

#判斷是否勝利
def?win(i?j):
????k?=?map[i][j]
????p=[]
????for?a?in?range(20):
????????p.append(0)
????for?i3?in?range(i-4i

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-08-11?16:53??Python?五子棋\
?????文件??????229499??2018-08-11?10:53??Python?五子棋\Background.jpg
?????文件?????1015586??2018-08-10?17:38??Python?五子棋\Background.png
?????文件????????5485??2018-08-10?16:31??Python?五子棋\Black_chess.png
?????文件?????8762068??2017-05-27?09:50??Python?五子棋\font.ttf
?????目錄???????????0??2018-08-11?09:05??Python?五子棋\music\
?????文件????????2104??2018-08-10?10:34??Python?五子棋\music\button.wav
?????文件???????17074??2018-08-11?09:04??Python?五子棋\music\play_chess.wav
?????文件??????455196??2018-08-11?08:58??Python?五子棋\music\victory.wav
?????文件????????1567??2018-08-10?15:23??Python?五子棋\Python?五子棋3.pyproj
?????文件???????10831??2018-08-11?16:53??Python?五子棋\Python_五子棋3.py
?????文件????????5206??2018-08-10?16:31??Python?五子棋\White_chess.png

評(píng)論

共有 條評(píng)論