日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術(shù)文章
文章詳情頁

Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼

瀏覽:26日期:2022-06-16 11:05:14
Python中國象棋單機(jī)版

鼠標(biāo)點(diǎn)擊操作;兩天制作,較為粗糙,很多效果還未實(shí)現(xiàn)。

# -*- coding: utf-8 -*-'''Created on Sun Jun 13 15:41:56 2021@author: Administrator'''import pygamefrom pygame.locals import *import sysimport mathpygame.init()screen=pygame.display.set_mode((450,550))pygame.display.set_caption(’中國象棋’)img_board=pygame.image.load(’F:/images/中國象棋/board.png’)img_redSoldier=pygame.image.load(’F:/images/中國象棋/chess_redSoldier.png’)img_redCannon=pygame.image.load(’F:/images/中國象棋/chess_redCannon.png’)img_redCar=pygame.image.load(’F:/images/中國象棋/chess_redCar.png’)img_redHorse=pygame.image.load(’F:/images/中國象棋/chess_redHorse.png’)img_redElephant=pygame.image.load(’F:/images/中國象棋/chess_redElephant.png’)img_redAttendant=pygame.image.load(’F:/images/中國象棋/chess_redAttendant.png’)img_chief=pygame.image.load(’F:/images/中國象棋/chess_chief.png’)img_blackSoldier=pygame.image.load(’F:/images/中國象棋/chess_blackSoldier.png’)img_blackCannon=pygame.image.load(’F:/images/中國象棋/chess_blackCannon.png’)img_blackCar=pygame.image.load(’F:/images/中國象棋/chess_blackCar.png’)img_blackHorse=pygame.image.load(’F:/images/中國象棋/chess_blackHorse.png’)img_blackElephant=pygame.image.load(’F:/images/中國象棋/chess_blackElephant.png’)img_blackAttendant=pygame.image.load(’F:/images/中國象棋/chess_blackAttendant.png’)img_general=pygame.image.load(’F:/images/中國象棋/chess_general.png’)screen.blit(img_board,(0,0))pygame.display.update()red_chess=[[0,6],[2,6],[4,6],[6,6],[8,6],[1,7],[7,7],[0,9],[1,9],[2,9],[3,9],[4,9],[5,9],[6,9],[7,9],[8,9]]black_chess=[[0,3],[2,3],[4,3],[6,3],[8,3],[1,2],[7,2],[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0]]#畫棋子def draw_chess(): for i in range(len(red_chess)):if 0<=i<=4: screen.blit(img_redSoldier,(red_chess[i][0]*50,red_chess[i][1]*50))elif 5<=i<=6: screen.blit(img_redCannon,(red_chess[i][0]*50,red_chess[i][1]*50))elif i==7 or i==15: screen.blit(img_redCar,(red_chess[i][0]*50,red_chess[i][1]*50))elif i==8 or i==14: screen.blit(img_redHorse,(red_chess[i][0]*50,red_chess[i][1]*50))elif i==9 or i==13: screen.blit(img_redElephant,(red_chess[i][0]*50,red_chess[i][1]*50))elif i==10 or i==12: screen.blit(img_redAttendant,(red_chess[i][0]*50,red_chess[i][1]*50))else: screen.blit(img_chief,(red_chess[i][0]*50,red_chess[i][1]*50)) for i in range(len(black_chess)):if 0<=i<=4: screen.blit(img_blackSoldier,(black_chess[i][0]*50,black_chess[i][1]*50))elif 5<=i<=6: screen.blit(img_blackCannon,(black_chess[i][0]*50,black_chess[i][1]*50))elif i==7 or i==15: screen.blit(img_blackCar,(black_chess[i][0]*50,black_chess[i][1]*50))elif i==8 or i==14: screen.blit(img_blackHorse,(black_chess[i][0]*50,black_chess[i][1]*50))elif i==9 or i==13: screen.blit(img_blackElephant,(black_chess[i][0]*50,black_chess[i][1]*50))elif i==10 or i==12: screen.blit(img_blackAttendant,(black_chess[i][0]*50,black_chess[i][1]*50))else: screen.blit(img_general,(black_chess[i][0]*50,black_chess[i][1]*50)) pygame.display.update()#返回1表示正常移動,返回2表示有子被吃,返回0表示拒絕移動#兵移動規(guī)則,紅兵chess1為red_chess,chess2為black_chessdef soldier_rule(chess1,chess2,current_pos,next_pos): if chess1==red_chess:pos,index=[5,6],1 elif chess1==black_chess:pos,index=[3,4],-1 if current_pos[1] in pos:if current_pos[0]==next_pos[0] and current_pos[1]==next_pos[1]+index and next_pos not in chess1: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2] current_pos=next_pos return [current_pos,1] else:if current_pos[0]==next_pos[0] and current_pos[1]==next_pos[1]+index and next_pos not in chess1: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2] current_pos=next_pos return [current_pos,1]elif current_pos[1]==next_pos[1] and current_pos[0]+1==next_pos[0] and next_pos not in chess1: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2] current_pos=next_pos return [current_pos,1]elif current_pos[1]==next_pos[1] and current_pos[0]-1==next_pos[0] and next_pos not in chess1: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2] current_pos=next_pos return [current_pos,1]#車移動規(guī)則,紅車前兩個參數(shù)為red_chess、black_chess,黑車前兩個參數(shù)為black_chess、red_chessdef car_rule(chess1,chess2,current_pos,next_pos): if next_pos not in chess1 and current_pos[0]==next_pos[0]:a,b=current_pos,next_posif a[1]>b[1]: a,b=b,afor i in range(a[1]+1,b[1]): if [a[0],i] in black_chess+red_chess:return 0for i in range(len(chess2)): if chess2[i]==next_pos:chess2[i]=[-1,-1]current_pos=next_posreturn [current_pos,2]current_pos=next_posreturn [current_pos,1] elif next_pos not in chess1 and current_pos[1]==next_pos[1]:a,b=current_pos,next_posif a[0]>b[0]: a,b=b,afor i in range(a[0]+1,b[0]): if [i,a[1]] in black_chess+red_chess:return 0for i in range(len(chess2)): if chess2[i]==next_pos:chess2[i]=[-1,-1]current_pos=next_posreturn [current_pos,2]current_pos=next_posreturn [current_pos,1]#炮移動規(guī)則def cannon_rule(chess1,chess2,current_pos,next_pos): if next_pos not in chess1 and current_pos[0]==next_pos[0]:num=0a,b=current_pos,next_posif a[1]>b[1]: a,b=b,afor i in range(a[1]+1,b[1]): if [a[0],i] in black_chess+red_chess:num+=1if num==1: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2] return 0elif num==0: current_pos=next_pos return [current_pos,1]else: return 0 elif next_pos not in chess1 and current_pos[1]==next_pos[1]:num=0a,b=current_pos,next_posif a[0]>b[0]: a,b=b,afor i in range(a[0]+1,b[0]): if [i,a[1]] in black_chess+red_chess:num+=1if num==1: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2] return 0elif num==0: current_pos=next_pos return [current_pos,1]else: return 0#馬移動規(guī)則,紅馬chess為black_chessdef horse_rule(chess,current_pos,next_pos): index=[[2,-1],[1,-2],[-1,-2],[-2,-1],[-2,1],[-1,2],[1,2],[2,1]] leg=[[1,0],[0,-1],[0,-1],[-1,0],[-1,0],[0,1],[0,1],[1,0]] if next_pos not in red_chess+black_chess:for i in range(len(index)): if current_pos[0]+index[i][0]==next_pos[0] and current_pos[1]+index[i][1]==next_pos[1]:if [current_pos[0]+leg[i][0],current_pos[1]+leg[i][1]] not in black_chess+red_chess: current_pos=next_pos return [current_pos,1] elif next_pos in chess:for i in range(len(index)): if current_pos[0]+index[i][0]==next_pos[0] and current_pos[1]+index[i][1]==next_pos[1]:if [current_pos[0]+leg[i][0],current_pos[1]+leg[i][1]] not in black_chess+red_chess: for i in range(len(chess)):if chess[i]==next_pos: chess[i]=[-1,-1] current_pos=next_pos return [current_pos,2]#象移動規(guī)則,紅相chess為black_chessdef elephant_rule(chess,current_pos,next_pos): index=[[2,-2],[-2,-2],[-2,2],[2,2]] leg=[[1,-1],[-1,-1],[-1,1],[1,1]] if chess==black_chess:pos=[5,7,9] elif chess==red_chess:pos=[0,2,4] if next_pos not in red_chess+black_chess and next_pos[1] in pos:for i in range(len(index)): if current_pos[0]+index[i][0]==next_pos[0] and current_pos[1]+index[i][1]==next_pos[1]:if [current_pos[0]+leg[i][0],current_pos[1]+leg[i][1]] not in black_chess+red_chess: current_pos=next_pos return [current_pos,1] elif next_pos in chess and next_pos[1] in pos:for i in range(len(index)): if current_pos[0]+index[i][0]==next_pos[0] and current_pos[1]+index[i][1]==next_pos[1]:if [current_pos[0]+leg[i][0],current_pos[1]+leg[i][1]] not in black_chess+red_chess: for i in range(len(chess)):if chess[i]==next_pos: chess[i]=[-1,-1] current_pos=next_pos return [current_pos,2]#士移動規(guī)則def attendant_rule(chess1,chess2,current_pos,next_pos): if chess1==red_chess:pos1=[[3,9],[3,7],[5,7],[5,9]]pos2=[4,8] elif chess1==black_chess:pos1=[[3,0],[3,2],[5,2],[5,0]]pos2=[4,1] if current_pos in pos1 and next_pos==pos2 and next_pos not in chess1:if next_pos not in chess2: current_pos=next_pos return [current_pos,1]else: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2] elif current_pos==pos2 and next_pos in pos1 and next_pos not in chess1:if next_pos not in chess2: current_pos=next_pos return [current_pos,1]else: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2]#將帥移動規(guī)則def boss_rule(chess1,chess2,current_pos,next_pos,j_pos): if chess1==red_chess:pos=[7,8,9] elif chess1==black_chess:pos=[0,1,2] flag=0 if next_pos not in chess1:if next_pos[0]==j_pos[0]: for i in range(j_pos[1]+1,next_pos[1]):if [j_pos[0],j_pos[1]+i] in black_chess+red_chess: flag=1 break if flag==0:return 0 if next_pos not in chess1 and 3<=next_pos[0]<=5 and next_pos[1] in pos:if next_pos not in chess2: if current_pos[0]==next_pos[0]:if current_pos[1]+1==next_pos[1] or current_pos[1]-1==next_pos[1]: current_pos=next_pos return [current_pos,1] elif current_pos[1]==next_pos[1]:if current_pos[0]+1==next_pos[0] or current_pos[0]-1==next_pos[0]: current_pos=next_pos return [current_pos,1]else: if current_pos[0]==next_pos[0]:if current_pos[1]+1==next_pos[1] or current_pos[1]-1==next_pos[1]: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2] elif current_pos[1]==next_pos[1]:if current_pos[0]+1==next_pos[0] or current_pos[0]-1==next_pos[0]: for i in range(len(chess2)):if chess2[i]==next_pos: chess2[i]=[-1,-1] current_pos=next_pos return [current_pos,2]#棋子移動def move(chess1,chess2,next_pos): x=0 if i in range(5): #兵x=soldier_rule(chess1,chess2,chess1[i],next_pos)if x!=None and x!=0: chess1[i]=x[0] print(chess1[i]) screen.blit(img_board,(0,0)) draw_chess() elif i==5 or i==6: #炮x=cannon_rule(chess1,chess2,chess1[i],next_pos)if x!=None and x!=0: chess1[i]=x[0] print(chess1[i]) screen.blit(img_board,(0,0)) draw_chess() elif i==7 or i==15: #?x=car_rule(chess1,chess2,chess1[i],next_pos)if x!=None and x!=0: chess1[i]=x[0] print(chess1[i]) screen.blit(img_board,(0,0)) draw_chess() elif i==8 or i==14: #?x=horse_rule(chess2,chess1[i],next_pos)if x!=None and x!=0: chess1[i]=x[0] print(chess1[i]) screen.blit(img_board,(0,0)) draw_chess() elif i==9 or i==13: #相x=elephant_rule(chess2,chess1[i],next_pos)if x!=None and x!=0: chess1[i]=x[0] print(chess1[i]) screen.blit(img_board,(0,0)) draw_chess() elif i==10 or i==12: #仕x=attendant_rule(chess1,chess2,chess1[i],next_pos)if x!=None and x!=0: chess1[i]=x[0] print(chess1[i]) screen.blit(img_board,(0,0)) draw_chess() else: #??x=boss_rule(chess1,chess2,chess1[i],next_pos,chess2[11])if x!=None and x!=0: chess1[i]=x[0] print(chess1[i]) screen.blit(img_board,(0,0)) draw_chess() return xwhite=(255,255,255)black=(0,0,0)def draw_text(text,x,y,size): pygame.font.init() fontObj=pygame.font.SysFont(’SimHei’,size ) textSurfaceObj=fontObj.render(text, True, white,black) textRectObj=textSurfaceObj.get_rect() textRectObj.center=(x,y) screen.blit(textSurfaceObj, textRectObj) pygame.display.update()#判斷游戲是否結(jié)束def game_over(): if red_chess[11]==[-1,-1]:draw_text(’黑方勝利’,225,525,15)return 1 elif black_chess[11]==[-1,-1]:draw_text(’紅方勝利’,225,525,15)return 1if __name__==’__main__’: all_pos,progress=[],[] for i in range(10):for j in range(9): all_pos.append([j,i]) draw_text(’紅方先走’,225,525,15) chess_kind=0 while True:draw_chess()for event in pygame.event.get(): if event.type==QUIT:pygame.quit()sys.exit() elif event.type==MOUSEBUTTONDOWN:pos=pygame.mouse.get_pos()print(pos)if chess_kind==0: chess1,chess2=red_chess,black_chesselif chess_kind==1: chess1,chess2=black_chess,red_chessfor i in range(len(chess1)): if chess1[i][0]*50<pos[0]<(chess1[i][0]+1)*50 and chess1[i][1]*50<pos[1]<(chess1[i][1]+1)*50:flag=Falsewhile True: for event in pygame.event.get():if event.type==MOUSEBUTTONDOWN: pos=pygame.mouse.get_pos() next_pos=[pos[0]//50,pos[1]//50] flag=True break if flag==True:breakprogress.append(move(chess1,chess2,next_pos))if progress[-1]!=None and progress[-1]!=0: if chess_kind==0:chess_kind=1 elif chess_kind==1:chess_kind=0if chess_kind==1: draw_text(’輪到黑方’,225,525,15)elif chess_kind==0: draw_text(’輪到紅方’,225,525,15)if game_over()==1: while True:for event in pygame.event.get(): if event.type==QUIT:pygame.quit()sys.exit()break

棋盤圖片:

Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼

棋子圖片:

Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼

運(yùn)行效果:

Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼

到此這篇關(guān)于Python pygame實(shí)現(xiàn)中國象棋單機(jī)版源碼的文章就介紹到這了,更多相關(guān)pygame實(shí)現(xiàn)中國象棋內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
成人小电影网站| yellow在线观看网址| 伊人久久成人| 国产农村妇女精品一二区| 男人天堂欧美日韩| 亚洲1区在线观看| 国产精品天堂蜜av在线播放| 久久精品欧洲| 日韩在线二区| 久久九九99| 视频一区中文字幕| 国产精品久久久久久模特| 亚洲精品在线影院| 亚洲乱码视频| 久久香蕉网站| 亚洲黄色在线| 国产精品2区| 欧美大黑bbbbbbbbb在线| 日韩欧美2区| 成人亚洲一区二区| 99视频一区| 美女久久99| 中文日韩欧美| 国产福利一区二区三区在线播放| 麻豆国产在线| 美女久久一区| 精品久久久久中文字幕小说| 欧美性感美女一区二区| 日本99精品| 欧美日韩精品在线一区| 日韩激情视频网站| av一区在线| 欧美午夜三级| 9色精品在线| 国产成人免费av一区二区午夜| 亚洲一区二区三区四区五区午夜| 久久亚洲精品中文字幕| 天使萌一区二区三区免费观看| 国产精品久一| 国产精品美女| 久久三级中文| 亚洲精品福利| 91精品久久久久久久久久不卡| 欧美一区二区三区免费看| 999国产精品| 国产精品a级| 视频一区二区三区在线| 给我免费播放日韩视频| 日本不卡高清| 午夜久久福利| 福利欧美精品在线| 日本精品国产| 9色精品在线| 日韩一区二区在线免费| 日韩国产欧美一区二区三区| 九九久久婷婷| 高清av一区| 国产色99精品9i| 日韩专区一卡二卡| 九一国产精品| 欧美三级精品| 精品国产美女a久久9999| 日韩高清电影免费| 在线视频亚洲| 国产综合亚洲精品一区二| 精品国产一区二| 欧美天堂在线| 日韩激情精品| 亚洲日本久久| 奶水喷射视频一区| 久久国产欧美| 日韩电影免费网址| 久久精品午夜| 国产日韩欧美一区二区三区 | 国产精品福利在线观看播放| 欧美日韩18| 男女男精品视频网| 中文亚洲免费| 国产亚洲精品v| 婷婷精品进入| 精品在线91| 激情欧美一区二区三区| 亚洲91视频| 欧美午夜精彩| 好看的亚洲午夜视频在线| 国产精品97| 国产日韩专区| 视频在线观看一区二区三区| 美日韩精品视频| 亚洲日韩中文字幕一区| 深夜福利亚洲| 日韩午夜视频在线| 日本欧美一区| 国产精品.xx视频.xxtv| 国产精品香蕉| 久久亚洲国产精品尤物| 国产成人精品一区二区免费看京| 精品免费视频| 日韩黄色大片| 999久久久免费精品国产| 蜜桃tv一区二区三区| 黄色在线一区| 亚洲tv在线| 国产精品玖玖玖在线资源| 久久麻豆视频| 日韩大片在线观看| 亚洲国产专区校园欧美| 在线亚洲观看| 97成人在线| 国产高清视频一区二区| 国内精品麻豆美女在线播放视频| 激情国产在线| 国产视频一区免费看| 亚洲欧洲专区| 国产精品亚洲欧美日韩一区在线| 精品国产一区二区三区av片| 日韩高清成人| 午夜宅男久久久| 97成人在线| 国产不卡人人| 99热精品在线观看| 国产美女撒尿一区二区| 高清不卡一区| 香蕉精品999视频一区二区| 91成人在线网站| 国产一区二区三区探花| 婷婷亚洲综合| 国产精品嫩草影院在线看| 在线看片国产福利你懂的| 亚洲制服少妇| 久久伊人国产| 亚洲在线国产日韩欧美| 欧美激情精品| 精品一区毛片| 国产精品白浆| 黄色国产精品| 麻豆久久久久久| 国产亚洲精品v| 老司机免费视频一区二区三区| 久久精品亚洲欧美日韩精品中文字幕| 影院欧美亚洲| 精品国产麻豆| 免费黄网站欧美| 国产欧美一区二区三区精品酒店| 亚洲色图网站| 久久免费国产| 欧美黄色一区二区| 亚洲一区二区毛片| 毛片在线网站| 清纯唯美亚洲综合一区| 亚洲高清二区| 精品伊人久久久| 天使萌一区二区三区免费观看| 精品免费av| 日本久久二区| 欧美日韩一区二区综合 | 美女国产精品| 另类专区亚洲| 欧美午夜网站| 久久国产精品久久w女人spa| 97欧美在线视频| 青青草伊人久久| 99视频精品免费观看| av中文字幕在线观看第一页| 日韩一区二区三免费高清在线观看 | 国产精品av久久久久久麻豆网| 97久久中文字幕| 亚洲经典在线| 色网在线免费观看| 欧美激情福利| 日韩精品视频网| 9色精品在线| 日韩中文在线播放| 精品国产乱码久久久久久1区2匹| 蜜臀久久99精品久久久久久9 | 国产精品99久久精品| 欧美中文一区| 综合激情在线| 9国产精品视频| 久久高清精品| 裤袜国产欧美精品一区| 国产极品嫩模在线观看91精品| 亚洲制服一区| 香蕉久久夜色精品国产| 女人av一区| 亚洲一级二级| 99久久视频| 久久国产日韩| 欧美日韩精品免费观看视欧美高清免费大片| 嫩呦国产一区二区三区av| 国产日韩欧美在线播放不卡| 色综合视频一区二区三区日韩| 亚洲免费影视| 亚洲综合二区| 亚洲免费在线| 日韩专区欧美专区| 免费高清在线一区| 视频在线观看91| 在线精品亚洲| 亚洲毛片在线|