|
|
@ -14,12 +14,17 @@ from json import load
|
|
|
|
import pygame as pg
|
|
|
|
import pygame as pg
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
from time import process_time
|
|
|
|
from time import process_time
|
|
|
|
|
|
|
|
import SafariChess_backend as backend
|
|
|
|
|
|
|
|
import SafariChess_Classes as classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#设置棋盘的参数
|
|
|
|
#设置棋盘的参数
|
|
|
|
WIDTH = 800
|
|
|
|
WIDTH = 800
|
|
|
|
HEIGHT = 1000
|
|
|
|
HEIGHT = 1000
|
|
|
|
BOARD_WIDTH = 600
|
|
|
|
BOARD_WIDTH = 600
|
|
|
|
BOARD_HEIGHT = 800
|
|
|
|
BOARD_HEIGHT = 800
|
|
|
|
|
|
|
|
SCREEN_WIDTH = 600
|
|
|
|
|
|
|
|
SCREEN_HEIGHT = 800
|
|
|
|
MOVE_LOG_PANEL_WIDTH = 0
|
|
|
|
MOVE_LOG_PANEL_WIDTH = 0
|
|
|
|
MOVE_LOG_PANEL_HEIGHT = BOARD_HEIGHT
|
|
|
|
MOVE_LOG_PANEL_HEIGHT = BOARD_HEIGHT
|
|
|
|
DIMENSION = 8
|
|
|
|
DIMENSION = 8
|
|
|
@ -27,6 +32,8 @@ DIMENSION_ROWS = 7
|
|
|
|
DIMENSION_COLUMNS = 9
|
|
|
|
DIMENSION_COLUMNS = 9
|
|
|
|
SIZE = 64
|
|
|
|
SIZE = 64
|
|
|
|
IMAGES = {}
|
|
|
|
IMAGES = {}
|
|
|
|
|
|
|
|
bias_top = 200 #棋盘的上边距
|
|
|
|
|
|
|
|
bias_left = 10 #棋盘的左边距
|
|
|
|
|
|
|
|
|
|
|
|
def loadImages():#加载图片,a,b双方分别有象狮豹狼狐鹰鼠七个角色
|
|
|
|
def loadImages():#加载图片,a,b双方分别有象狮豹狼狐鹰鼠七个角色
|
|
|
|
pieces = ["r7_Eleph", "r6_Lion", "r5_Leo", "r4_Wolf", "r3_Fox", "r2_Eag", "r1_Mse",
|
|
|
|
pieces = ["r7_Eleph", "r6_Lion", "r5_Leo", "r4_Wolf", "r3_Fox", "r2_Eag", "r1_Mse",
|
|
|
@ -42,9 +49,8 @@ def loadImages():#加载图片,a,b双方分别有象狮豹狼狐鹰鼠七个角
|
|
|
|
#screen.fill(pg.Color("white"))
|
|
|
|
#screen.fill(pg.Color("white"))
|
|
|
|
|
|
|
|
|
|
|
|
def drawBoard(screen):#绘制棋盘:格子,河流,陷阱,巢穴
|
|
|
|
def drawBoard(screen):#绘制棋盘:格子,河流,陷阱,巢穴
|
|
|
|
#global colors
|
|
|
|
|
|
|
|
bias_top = 200
|
|
|
|
|
|
|
|
bias_left = 10
|
|
|
|
|
|
|
|
#colors = [(255, 255, 255), (0, 0, 0)]
|
|
|
|
#colors = [(255, 255, 255), (0, 0, 0)]
|
|
|
|
for row in range(DIMENSION_ROWS):
|
|
|
|
for row in range(DIMENSION_ROWS):
|
|
|
|
for column in range(DIMENSION_COLUMNS):
|
|
|
|
for column in range(DIMENSION_COLUMNS):
|
|
|
@ -74,17 +80,36 @@ def drawPieces(screen,board):
|
|
|
|
if piece != "--":
|
|
|
|
if piece != "--":
|
|
|
|
screen.blit(IMAGES[piece], pg.Rect((column * SIZE) + 10, (row * SIZE) + 200, SIZE, SIZE))
|
|
|
|
screen.blit(IMAGES[piece], pg.Rect((column * SIZE) + 10, (row * SIZE) + 200, SIZE, SIZE))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# square_selected 是当前选中的可以移动的棋子的位置
|
|
|
|
|
|
|
|
def protrudeSquares(screen,game_state,square_selected,valid_moves):
|
|
|
|
|
|
|
|
#高亮选中的棋子接下来可行的位置
|
|
|
|
|
|
|
|
if square_selected != ():
|
|
|
|
|
|
|
|
row = square_selected[0]
|
|
|
|
|
|
|
|
column = square_selected[1]
|
|
|
|
|
|
|
|
if game_state.board[row][column][0] == ('r' if game_state.red_to_move else 'b'):
|
|
|
|
|
|
|
|
# highlight selected square
|
|
|
|
|
|
|
|
s = pg.Surface((SIZE, SIZE))
|
|
|
|
|
|
|
|
s.set_alpha(100)
|
|
|
|
|
|
|
|
s.fill(pg.Color('blue'))
|
|
|
|
|
|
|
|
screen.blit(s, (column *SIZE + bias_left, row * SIZE + bias_top))
|
|
|
|
|
|
|
|
# highlight moves from that square
|
|
|
|
|
|
|
|
s.fill(pg.Color('yellow'))
|
|
|
|
|
|
|
|
for move in valid_moves:
|
|
|
|
|
|
|
|
if move.start_row == row and move.start_col == column:
|
|
|
|
|
|
|
|
screen.blit(s, (move.end_col * SIZE + bias_left, move.end_row * SIZE + bias_top))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ShowGameState(screen,game_state,valid_moves,square_selected):#游戏状态
|
|
|
|
|
|
|
|
drawBoard(screen)
|
|
|
|
|
|
|
|
protrudeSquares(screen,game_state,square_selected,valid_moves)
|
|
|
|
|
|
|
|
drawPieces(screen,game_state.board)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#待开发
|
|
|
|
def drawValidMoves(screen):#绘制可走的位置
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def drawMovelog(screen):#绘制移动日志
|
|
|
|
def drawMovelog(screen):#绘制移动日志
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def InitScreen(screen):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def startGamePage():#开始游戏界面,Human/AI
|
|
|
|
def startGamePage():#开始游戏界面,Human/AI
|
|
|
|
startpage = '''
|
|
|
|
startpage = '''
|
|
|
@ -112,13 +137,51 @@ Please type one of the numbers below to choose a playing mode:
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
print(startpage)
|
|
|
|
print(startpage)
|
|
|
|
# 选择游戏模式
|
|
|
|
# 选择游戏模式
|
|
|
|
#not_selected = True
|
|
|
|
not_selected = True
|
|
|
|
#p1 , p2 = 0, 0
|
|
|
|
p1 , p2 = 0, 0
|
|
|
|
#while '''
|
|
|
|
while not_selected:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
mode = int(input())
|
|
|
|
|
|
|
|
if mode in [1,2,3,4]:
|
|
|
|
|
|
|
|
if mode == 1:
|
|
|
|
|
|
|
|
p1 = 1
|
|
|
|
|
|
|
|
p2 = 1
|
|
|
|
|
|
|
|
##其余版本还未写
|
|
|
|
|
|
|
|
not_selected = False
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print("Please type one of the numbers below to choose a playing mode:")
|
|
|
|
|
|
|
|
print(" ( 1 ) - Human vs Human")
|
|
|
|
|
|
|
|
print(" ( 2 ) - Human vs AI")
|
|
|
|
|
|
|
|
print(" ( 3 ) - AI vs AI")
|
|
|
|
|
|
|
|
print(" ( 4 ) - Quit")
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
print("Wrong Input")
|
|
|
|
|
|
|
|
return p1, p2, mode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def showGameOverText(screen, text):
|
|
|
|
|
|
|
|
#游戏结束,出现的文字 text是字符串“Left Win”或“Right Win”
|
|
|
|
|
|
|
|
font = pg.font.SysFont("comicsansms", 32)
|
|
|
|
|
|
|
|
text_object = font.render(text, True, pg.Color("red"))
|
|
|
|
|
|
|
|
text_location = pg.Rect(0, 0, BOARD_WIDTH, BOARD_HEIGHT).move(BOARD_WIDTH / 2 - text_object.get_width() / 2,
|
|
|
|
|
|
|
|
BOARD_HEIGHT / 2 - text_object.get_height() / 2)
|
|
|
|
|
|
|
|
screen.blit(text_object, text_location)
|
|
|
|
|
|
|
|
text_object = font.render(text, False, pg.Color('black'))
|
|
|
|
|
|
|
|
screen.blit(text_object, text_location.move(5, 5))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def MainMenu():
|
|
|
|
|
|
|
|
#显示主菜单
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pg.init()
|
|
|
|
|
|
|
|
mainClock = pg.time.Clock()
|
|
|
|
|
|
|
|
screen = pg.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
|
|
|
|
|
|
pg.display.set_caption("SafariChess by ZY&&DQ")
|
|
|
|
|
|
|
|
bg = pg.image.load("images/MenuBg.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#按钮设置
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GameOver(screen):#游戏结束,出现的文字以及图像
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
pg.init()
|
|
|
|
pg.init()
|
|
|
@ -156,3 +219,5 @@ if __name__ == '__main__':
|
|
|
|
print("Initialing game...")
|
|
|
|
print("Initialing game...")
|
|
|
|
main()
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|