python实现五子棋小游戏
来源:中文源码网 浏览: 次 日期:2019年11月5日
【下载文档: python实现五子棋小游戏.txt 】
(友情提示:右键点上行txt文档名->目标另存为)
python实现五子棋小游戏本文实例为大家分享了python实现五子棋小游戏的具体代码,供大家参考,具体内容如下
暑假学了十几天python,然后用pygame模块写了一个五子棋的小游戏,代码跟有缘人分享一下。
import numpy as np
import pygame
import sys
import traceback
import copy
from pygame.locals import *
pygame.init()
pygame.mixer.init()#颜色
background=(201,202,187)
checkerboard=(80,80,80)
button=(52,53,44)#音乐
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,(0,0))
#画棋盘
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)
#画定位点
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)
#画‘悔棋'‘重新开始&#