|
|
@ -9,7 +9,7 @@ Main code for run the game
|
|
|
|
it handle user input and GUI
|
|
|
|
it handle user input and GUI
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from curses import COLOR_GREEN, COLOR_YELLOW
|
|
|
|
import colorsys
|
|
|
|
from json import load
|
|
|
|
from json import load
|
|
|
|
import pygame as pg
|
|
|
|
import pygame as pg
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
@ -29,28 +29,57 @@ SIZE = 64
|
|
|
|
IMAGES = {}
|
|
|
|
IMAGES = {}
|
|
|
|
|
|
|
|
|
|
|
|
def loadImages():#加载图片,a,b双方分别有象狮豹狼狐鹰鼠七个角色
|
|
|
|
def loadImages():#加载图片,a,b双方分别有象狮豹狼狐鹰鼠七个角色
|
|
|
|
pieces = ["a7_Eleph", "a6_Lion", "a5_Leo", "a4_Wolf", "a3_Fox", "a2_Eag", "a1_Mse",
|
|
|
|
pieces = ["r7_Eleph", "r6_Lion", "r5_Leo", "r4_Wolf", "r3_Fox", "r2_Eag", "r1_Mse",
|
|
|
|
"b7_Eleph", "b6_Lion", "b5_Leo", "b4_Wolf", "b3_Fox", "b2_Eag", "b1_Mse",]
|
|
|
|
"b7_Eleph", "b6_Lion", "b5_Leo", "b4_Wolf", "b3_Fox", "b2_Eag", "b1_Mse",
|
|
|
|
|
|
|
|
]
|
|
|
|
for piece in pieces:#字典的形式存储图片
|
|
|
|
for piece in pieces:#字典的形式存储图片
|
|
|
|
IMAGES[piece] = pg.transform.scale(pg.image.load("./images/" + piece + ".png"), (SIZE, SIZE))
|
|
|
|
IMAGES[piece] = pg.transform.scale(pg.image.load("./Image/pieces/pieces_rb/" + piece + ".png"), (SIZE, SIZE))
|
|
|
|
|
|
|
|
|
|
|
|
screen = pg.display.set_mode((BOARD_WIDTH + MOVE_LOG_PANEL_WIDTH, BOARD_HEIGHT))#设置窗口大小
|
|
|
|
tools = ["trap", "home1","home2"]
|
|
|
|
screen.fill(COLOR_GREEN)
|
|
|
|
for tool in tools:
|
|
|
|
|
|
|
|
IMAGES[tool] = pg.transform.scale(pg.image.load("./Image/tools/" + tool + ".jpg"), (SIZE-10, SIZE-10))
|
|
|
|
|
|
|
|
#screen = pg.display.set_mode((BOARD_WIDTH + MOVE_LOG_PANEL_WIDTH, BOARD_HEIGHT))#设置窗口大小
|
|
|
|
|
|
|
|
#screen.fill(pg.Color("white"))
|
|
|
|
|
|
|
|
|
|
|
|
def drawBoardPieces(screen):#绘制棋盘:格子,河流,陷阱,巢穴 棋子:14个棋子,初始位置固定
|
|
|
|
def drawBoardPieces(screen):#绘制棋盘:格子,河流,陷阱,巢穴 棋子:14个棋子,初始位置固定
|
|
|
|
|
|
|
|
#global colors
|
|
|
|
|
|
|
|
bias_top = 200
|
|
|
|
|
|
|
|
bias_left = 10
|
|
|
|
|
|
|
|
#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):
|
|
|
|
|
|
|
|
pg.draw.rect(screen, pg.Color(10,100,10), pg.Rect(bias_left+column * SIZE, bias_top+row * SIZE, SIZE, SIZE))
|
|
|
|
|
|
|
|
pg.draw.rect(screen, pg.Color(90,150,75), pg.Rect((column * SIZE) + bias_left+3, (row * SIZE) + 3+bias_top, SIZE - 4, SIZE - 4))
|
|
|
|
|
|
|
|
#画河流
|
|
|
|
|
|
|
|
for row in [1,2,4,5]:
|
|
|
|
|
|
|
|
for column in [3,4,5]:
|
|
|
|
|
|
|
|
pg.draw.rect(screen, pg.Color(5,5,100),pg.Rect((column * SIZE) +bias_left+3, (row * SIZE) +bias_top +3, SIZE,SIZE))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#画陷阱
|
|
|
|
|
|
|
|
for row in [2,4]:
|
|
|
|
|
|
|
|
for column in [0,8]:
|
|
|
|
|
|
|
|
screen.blit(IMAGES["trap"], pg.Rect((column * SIZE) +bias_left+6, (row * SIZE) +bias_top +6, SIZE ,SIZE ))
|
|
|
|
|
|
|
|
for column in [1,7]:
|
|
|
|
|
|
|
|
screen.blit(IMAGES["trap"], pg.Rect((column * SIZE) +bias_left+6, (3 * SIZE) +bias_top +6, SIZE ,SIZE ))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#画巢穴
|
|
|
|
|
|
|
|
screen.blit(IMAGES["home1"], pg.Rect((bias_left+6, (3 * SIZE) +bias_top +6, SIZE ,SIZE )))
|
|
|
|
|
|
|
|
screen.blit(IMAGES["home2"], pg.Rect( 8*SIZE+bias_left+6, (3 * SIZE) +bias_top +6, SIZE ,SIZE ))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#画棋子的位置
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def drawValidMoves(screen):#绘制可走的位置
|
|
|
|
def drawValidMoves(screen):#绘制可走的位置
|
|
|
|
for move in validMoves:
|
|
|
|
pass
|
|
|
|
row, column = move
|
|
|
|
|
|
|
|
pg.draw.circle(screen, COLOR_YELLOW, (column * SIZE + SIZE // 2, row * SIZE + SIZE // 2), 15)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def drawMovelog(screen):#绘制移动日志
|
|
|
|
def drawMovelog(screen):#绘制移动日志
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def InitScreen(screen):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def startGamePage():#开始游戏界面,Human/AI
|
|
|
|
def startGamePage():#开始游戏界面,Human/AI
|
|
|
|
startpage = '''
|
|
|
|
startpage = '''
|
|
|
@ -78,13 +107,46 @@ 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 '''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GameOver(screen):#游戏结束,出现的文字以及图像
|
|
|
|
def GameOver(screen):#游戏结束,出现的文字以及图像
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
pg.init()
|
|
|
|
|
|
|
|
screen = pg.display.set_mode((BOARD_WIDTH + MOVE_LOG_PANEL_WIDTH, BOARD_HEIGHT))
|
|
|
|
|
|
|
|
pg.display.set_caption("Safafi Chess Game")
|
|
|
|
|
|
|
|
clock = pg.time.Clock()
|
|
|
|
|
|
|
|
screen.fill(pg.Color("white"))
|
|
|
|
|
|
|
|
loadImages()
|
|
|
|
|
|
|
|
drawBoardPieces(screen)
|
|
|
|
|
|
|
|
pg.display.update()
|
|
|
|
|
|
|
|
startGamePage()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
for e in pg.event.get():
|
|
|
|
|
|
|
|
#接下来处理游戏中的事件
|
|
|
|
|
|
|
|
if e.type == pg.QUIT:
|
|
|
|
|
|
|
|
pg.quit()
|
|
|
|
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif e.type == pg.MOUSEBUTTONDOWN:
|
|
|
|
|
|
|
|
#鼠标点击事件:用于选择棋子,移动棋子
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif e.type == pg.KEYDOWN:
|
|
|
|
|
|
|
|
#设置某些按键用于悔棋,重新开始游戏,机器提示,退出游戏等功能
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clock.tick(60)
|
|
|
|
|
|
|
|
pg.display.flip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
pass
|
|
|
|
print("Loading...")
|
|
|
|
|
|
|
|
print("Initialing game...")
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
|
|
|