|
|
@ -16,8 +16,9 @@ import pygame as pg
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
import socket
|
|
|
|
import socket
|
|
|
|
import SafariChess_backend as backend
|
|
|
|
import SafariChess_backend as backend
|
|
|
|
from SafariChess_Classes import Button
|
|
|
|
from SafariChess_Classes import Button, DropDown
|
|
|
|
from threading import Thread, Lock
|
|
|
|
from threading import Thread, Lock
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
#设置棋盘的参数
|
|
|
|
#设置棋盘的参数
|
|
|
|
WIDTH = 1000
|
|
|
|
WIDTH = 1000
|
|
|
@ -222,18 +223,44 @@ def MainMenu():
|
|
|
|
#ui
|
|
|
|
#ui
|
|
|
|
screen = pg.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
|
|
screen = pg.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
|
|
pg.display.set_caption("SafariChess by ZY&&DQ")
|
|
|
|
pg.display.set_caption("SafariChess by ZY&&DQ")
|
|
|
|
bg = pg.transform.scale(pg.image.load("Image/MenuBg.jpg"), (SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
|
|
bg = pg.transform.scale(pg.image.load("Image/MenuBg.bmp"), (SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
|
|
bt1 = pg.transform.scale(pg.image.load("Image/button1.jpg"),(150,40))
|
|
|
|
bt1 = pg.transform.scale(pg.image.load("Image/button1.jpg"),(150,40))
|
|
|
|
bt2 = pg.transform.scale(pg.image.load("Image/button2.jpg"),(150,40))
|
|
|
|
bt2 = pg.transform.scale(pg.image.load("Image/button2.jpg"),(150,40))
|
|
|
|
bt3 = pg.transform.scale(pg.image.load("Image/button3.jpg"),(150,40))
|
|
|
|
bt3 = pg.transform.scale(pg.image.load("Image/button3.jpg"),(150,40))
|
|
|
|
bt4 = pg.transform.scale(pg.image.load("Image/button4.jpg"),(150,40))
|
|
|
|
bt4 = pg.transform.scale(pg.image.load("Image/button4.jpg"),(150,40))
|
|
|
|
|
|
|
|
music_settings = pg.transform.scale(pg.image.load("Image/music.bmp"),(100,40))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#按钮设置
|
|
|
|
#按钮设置
|
|
|
|
#主菜单包含如下按钮:
|
|
|
|
#主菜单包含如下按钮:
|
|
|
|
#单机游戏,双人游戏,人机对战,退出游戏
|
|
|
|
#单机游戏,双人游戏,人机对战,退出游戏
|
|
|
|
button_1 = Button(bt1,(350,350))
|
|
|
|
button_1 = Button(bt1,(300,350))
|
|
|
|
button_2 = Button(bt2,(350,400))
|
|
|
|
button_2 = Button(bt2,(300,400))
|
|
|
|
button_3 = Button(bt3,(350,450))
|
|
|
|
button_3 = Button(bt3,(300,450))
|
|
|
|
button_4 = Button(bt4,(350,500))
|
|
|
|
button_4 = Button(bt4,(300,500))
|
|
|
|
|
|
|
|
music_button = Button(music_settings,(600,20))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#音乐设置
|
|
|
|
|
|
|
|
pg.mixer.init()
|
|
|
|
|
|
|
|
music = pg.mixer.Sound("./Image/music1.mp3")
|
|
|
|
|
|
|
|
music.set_volume(0)
|
|
|
|
|
|
|
|
music.play()
|
|
|
|
|
|
|
|
pg.display.flip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
COLOR_INACTIVE = (255, 108, 0)
|
|
|
|
|
|
|
|
COLOR_ACTIVE = (255, 208, 0)
|
|
|
|
|
|
|
|
COLOR_LIST_INACTIVE = (0, 143, 90)
|
|
|
|
|
|
|
|
COLOR_LIST_ACTIVE = (3, 252, 140)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# music_ops = DropDown([COLOR_INACTIVE, COLOR_ACTIVE],[COLOR_LIST_INACTIVE, COLOR_LIST_ACTIVE],
|
|
|
|
|
|
|
|
# 600,30, 100, 20,
|
|
|
|
|
|
|
|
# pg.font.SysFont("Courier", 20),
|
|
|
|
|
|
|
|
# "Music",
|
|
|
|
|
|
|
|
# music_lists)
|
|
|
|
|
|
|
|
|
|
|
|
mode = -1
|
|
|
|
mode = -1
|
|
|
|
run = True
|
|
|
|
run = True
|
|
|
|
while run:
|
|
|
|
while run:
|
|
|
@ -262,16 +289,42 @@ def MainMenu():
|
|
|
|
if button_4.rect.collidepoint(event.pos):
|
|
|
|
if button_4.rect.collidepoint(event.pos):
|
|
|
|
pg.quit()
|
|
|
|
pg.quit()
|
|
|
|
sys.exit()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
if music_button.rect.collidepoint(event.pos):
|
|
|
|
|
|
|
|
if music.get_volume() == 0:
|
|
|
|
|
|
|
|
music.set_volume(0.5)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
music.set_volume(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
screen.blit(bg, (0, 0))
|
|
|
|
screen.blit(bg, (0, 0))
|
|
|
|
screen.blit(button_1.image, button_1.rect)
|
|
|
|
screen.blit(button_1.image, button_1.rect)
|
|
|
|
screen.blit(button_2.image, button_2.rect)
|
|
|
|
screen.blit(button_2.image, button_2.rect)
|
|
|
|
screen.blit(button_3.image, button_3.rect)
|
|
|
|
screen.blit(button_3.image, button_3.rect)
|
|
|
|
screen.blit(button_4.image, button_4.rect)
|
|
|
|
screen.blit(button_4.image, button_4.rect)
|
|
|
|
|
|
|
|
screen.blit(music_button.image, music_button.rect)
|
|
|
|
pg.display.flip()
|
|
|
|
pg.display.flip()
|
|
|
|
return mode
|
|
|
|
return mode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#绘制Text在屏幕上
|
|
|
|
|
|
|
|
def showText(screen,fontObj,text,x,y):
|
|
|
|
|
|
|
|
textSurfaceObj = fontObj.render(text, True, pg.Color('red'),pg.Color('white'))# 配置要显示的文字
|
|
|
|
|
|
|
|
textRectObj = textSurfaceObj.get_rect()# 获得要显示的对象的rect
|
|
|
|
|
|
|
|
textRectObj.center = (x, y)# 设置显示对象的坐标
|
|
|
|
|
|
|
|
screen.blit(textSurfaceObj, textRectObj)# 绘制字体
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(mode):
|
|
|
|
def main(mode):
|
|
|
|
global networkMsg
|
|
|
|
global networkMsg
|
|
|
|
networkMsg = None
|
|
|
|
networkMsg = None
|
|
|
@ -298,6 +351,9 @@ def main(mode):
|
|
|
|
square_selected = () #刚开始没有选择任何一个棋子
|
|
|
|
square_selected = () #刚开始没有选择任何一个棋子
|
|
|
|
click_queue = [] #点击队列,记录第一次点击和第二次点击位置,方便移动棋子
|
|
|
|
click_queue = [] #点击队列,记录第一次点击和第二次点击位置,方便移动棋子
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button_music = Button(pg.transform.scale(pg.image.load("Image/music.bmp"),(100,50)),(500,0))
|
|
|
|
|
|
|
|
screen.blit(button_music.image, button_music.rect)
|
|
|
|
|
|
|
|
|
|
|
|
pg.display.update()
|
|
|
|
pg.display.update()
|
|
|
|
startGamePage(mode)
|
|
|
|
startGamePage(mode)
|
|
|
|
|
|
|
|
|
|
|
@ -336,6 +392,11 @@ def main(mode):
|
|
|
|
elif e.type == pg.KEYDOWN:
|
|
|
|
elif e.type == pg.KEYDOWN:
|
|
|
|
#设置某些按键用于悔棋,重新开始游戏,机器提示,退出游戏等功能
|
|
|
|
#设置某些按键用于悔棋,重新开始游戏,机器提示,退出游戏等功能
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
elif e.type == COUNT:# 判断事件是否为计时事件
|
|
|
|
|
|
|
|
counts=counts+1
|
|
|
|
|
|
|
|
countstext=str(counts)
|
|
|
|
|
|
|
|
showText(screen,bigfont,countstext,200,350)
|
|
|
|
|
|
|
|
pg.display.update()
|
|
|
|
|
|
|
|
|
|
|
|
if mademove:
|
|
|
|
if mademove:
|
|
|
|
valid_moves = game_state.getAllMoves()
|
|
|
|
valid_moves = game_state.getAllMoves()
|
|
|
@ -347,6 +408,23 @@ def main(mode):
|
|
|
|
clock.tick(60)
|
|
|
|
clock.tick(60)
|
|
|
|
pg.display.flip()
|
|
|
|
pg.display.flip()
|
|
|
|
elif mode == 2:
|
|
|
|
elif mode == 2:
|
|
|
|
|
|
|
|
##一些按钮实现
|
|
|
|
|
|
|
|
button_stop = Button(pg.transform.scale(pg.image.load("Image/叫停.bmp"),(100,50)),(600,0))
|
|
|
|
|
|
|
|
screen.blit(button_stop.image, button_stop.rect)
|
|
|
|
|
|
|
|
# 初始化计时器
|
|
|
|
|
|
|
|
counts=0
|
|
|
|
|
|
|
|
# 自定义计时事件
|
|
|
|
|
|
|
|
COUNT = pg.USEREVENT +1
|
|
|
|
|
|
|
|
# 每隔1秒发送一次自定义事件
|
|
|
|
|
|
|
|
pg.time.set_timer(COUNT,1000)
|
|
|
|
|
|
|
|
now = time.ctime()# 获得系统当前时间
|
|
|
|
|
|
|
|
countdown_clock = now[11:19]# 格式化形式为时分秒
|
|
|
|
|
|
|
|
bigfont = pg.font.SysFont("Courier", 32)
|
|
|
|
|
|
|
|
minfont = pg.font.SysFont("Courier", 24)
|
|
|
|
|
|
|
|
showText(screen,bigfont,"Time:",600,600)
|
|
|
|
|
|
|
|
showText(screen,minfont,"Count:",600,500)
|
|
|
|
|
|
|
|
showText(screen,bigfont,countdown_clock,600,650)
|
|
|
|
|
|
|
|
pg.display.update()
|
|
|
|
startNetworkServices()
|
|
|
|
startNetworkServices()
|
|
|
|
myPlayerData = {
|
|
|
|
myPlayerData = {
|
|
|
|
'type': 0, # game state type ?
|
|
|
|
'type': 0, # game state type ?
|
|
|
@ -360,6 +438,7 @@ def main(mode):
|
|
|
|
lastNetworkMsg = networkMsg
|
|
|
|
lastNetworkMsg = networkMsg
|
|
|
|
client.send(login_packet)
|
|
|
|
client.send(login_packet)
|
|
|
|
while networkMsg == None: pass
|
|
|
|
while networkMsg == None: pass
|
|
|
|
|
|
|
|
|
|
|
|
while running:
|
|
|
|
while running:
|
|
|
|
#print('current moving color: ',game_state.color())
|
|
|
|
#print('current moving color: ',game_state.color())
|
|
|
|
if lastNetworkMsg != networkMsg:#handle
|
|
|
|
if lastNetworkMsg != networkMsg:#handle
|
|
|
@ -504,13 +583,15 @@ def main(mode):
|
|
|
|
|
|
|
|
|
|
|
|
clock.tick(50)
|
|
|
|
clock.tick(50)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pg.display.flip()
|
|
|
|
pg.display.flip()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print("Loading...")
|
|
|
|
print("Loading...")
|
|
|
|
print("Initialing game...")
|
|
|
|
print("Initialing game...")
|
|
|
|
#mode = MainMenu()
|
|
|
|
mode = MainMenu()
|
|
|
|
mode = 2
|
|
|
|
#mode = 2
|
|
|
|
main(mode)
|
|
|
|
main(mode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|