diff --git a/Image/MenuBg.jpg b/Image/MenuBg.jpg new file mode 100644 index 0000000..78e8542 Binary files /dev/null and b/Image/MenuBg.jpg differ diff --git a/SafariChess_Classes.py b/SafariChess_Classes.py new file mode 100644 index 0000000..f6e305d --- /dev/null +++ b/SafariChess_Classes.py @@ -0,0 +1,22 @@ +""" + SafariChess_Classes.py + Classes for button and keyboard events +""" + +class Button: + def _init_(self, image, position, callback=None): + self.image = image + self.rect = image.get_rect(topleft=position) + self.callback = callback + + def on_click(self, mouse_pos): + if self.rect.collidepoint(mouse_pos): + if self.callback: + self.callback() + return True + return False + + +#class DropDown(): +#下拉选择框 + diff --git a/SarafiChess_Gamev1.0.py b/SarafiChess_Gamev1.0.py index a252234..e5b22f7 100644 --- a/SarafiChess_Gamev1.0.py +++ b/SarafiChess_Gamev1.0.py @@ -14,12 +14,17 @@ from json import load import pygame as pg import sys from time import process_time +import SafariChess_backend as backend +import SafariChess_Classes as classes + #设置棋盘的参数 WIDTH = 800 HEIGHT = 1000 BOARD_WIDTH = 600 BOARD_HEIGHT = 800 +SCREEN_WIDTH = 600 +SCREEN_HEIGHT = 800 MOVE_LOG_PANEL_WIDTH = 0 MOVE_LOG_PANEL_HEIGHT = BOARD_HEIGHT DIMENSION = 8 @@ -27,6 +32,8 @@ DIMENSION_ROWS = 7 DIMENSION_COLUMNS = 9 SIZE = 64 IMAGES = {} +bias_top = 200 #棋盘的上边距 +bias_left = 10 #棋盘的左边距 def loadImages():#加载图片,a,b双方分别有象狮豹狼狐鹰鼠七个角色 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")) def drawBoard(screen):#绘制棋盘:格子,河流,陷阱,巢穴 - #global colors - bias_top = 200 - bias_left = 10 + + #colors = [(255, 255, 255), (0, 0, 0)] for row in range(DIMENSION_ROWS): for column in range(DIMENSION_COLUMNS): @@ -73,18 +79,37 @@ def drawPieces(screen,board): piece = board[row][column] if piece != "--": 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):#绘制移动日志 pass -def InitScreen(screen): - pass def startGamePage():#开始游戏界面,Human/AI startpage = ''' @@ -112,13 +137,51 @@ Please type one of the numbers below to choose a playing mode: ''' print(startpage) # 选择游戏模式 - #not_selected = True - #p1 , p2 = 0, 0 - #while ''' + not_selected = True + p1 , p2 = 0, 0 + 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 GameOver(screen):#游戏结束,出现的文字以及图像 - pass +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 main(): pg.init() @@ -155,4 +218,6 @@ if __name__ == '__main__': print("Loading...") print("Initialing game...") main() + + \ No newline at end of file