diff --git a/Media/Pic/1.png b/Media/Pic/1.png new file mode 100644 index 0000000..b038624 Binary files /dev/null and b/Media/Pic/1.png differ diff --git a/Media/Pic/2.png b/Media/Pic/2.png new file mode 100644 index 0000000..d812a63 Binary files /dev/null and b/Media/Pic/2.png differ diff --git a/Media/Pic/3.png b/Media/Pic/3.png new file mode 100644 index 0000000..c29f2db Binary files /dev/null and b/Media/Pic/3.png differ diff --git a/Media/Pic/4.png b/Media/Pic/4.png new file mode 100644 index 0000000..6868d90 Binary files /dev/null and b/Media/Pic/4.png differ diff --git a/Media/Pic/5.png b/Media/Pic/5.png new file mode 100644 index 0000000..b7d4467 Binary files /dev/null and b/Media/Pic/5.png differ diff --git a/Media/Pic/6.png b/Media/Pic/6.png new file mode 100644 index 0000000..964134d Binary files /dev/null and b/Media/Pic/6.png differ diff --git a/src/SpeedboatDice.py b/src/SpeedboatDice.py index bf9c88c..ff823f1 100644 --- a/src/SpeedboatDice.py +++ b/src/SpeedboatDice.py @@ -1,10 +1,10 @@ import pygame.event -from src.GameData import GameData +from src.data.GameData import GameData from src.events.handler.GameControllerEventHandler import GameControllerEventHandler from src.events.handler.RollEventHandler import RollEventHandler from src.events.handler.ScreenEventHandler import ScreenController -from src.userInput import * +from src.tools.userInput import * # Debug event_debug = True @@ -71,13 +71,13 @@ def run(self): if event.__dict__.get(sub_type) == WaitEvent: pygame.time.wait(event.__dict__.get('ms')) # 选择 第 K 个分数 - elif event.type == ChooseK: - # 立刻停止用户输入 - BlockUserInput() - # 清除队列中用户事件 - ClearAllUserEventsInQueue() - # 调用 Round 处理用户事件 - data.round.choose(event['no']) + elif event.__dict__.get(event_type) == ChooseEvent: + if event.__dict__.get(sub_type) == ChooseKEvent: + data.round.choose(event.__dict__.get("no")) + displayBackgroundEvent() + displayDicesEvent() + displayInfoEvent() + screenRefreshEvent() elif event.type == ChooseKEnd: AllowUserInput() # 由 processUserInput 处理鼠标的事件 diff --git a/src/music.py b/src/VideoMusicControl/music.py similarity index 100% rename from src/music.py rename to src/VideoMusicControl/music.py diff --git a/src/video.py b/src/VideoMusicControl/video.py similarity index 100% rename from src/video.py rename to src/VideoMusicControl/video.py diff --git a/src/GameItem/Dice.py b/src/data/Dice.py similarity index 89% rename from src/GameItem/Dice.py rename to src/data/Dice.py index 04cf633..d4a465f 100644 --- a/src/GameItem/Dice.py +++ b/src/data/Dice.py @@ -2,19 +2,19 @@ import pygame -from src.GameItem.GameItem import GameItem +from src.data.GameItem import GameItem import random """ DicePics """ -DicePics: list = [pygame.image.load(os.path.join('Media', 'Pic', 'one.png')), - pygame.image.load(os.path.join('Media', 'Pic', 'two.png')), - pygame.image.load(os.path.join('Media', 'Pic', 'three.png')), - pygame.image.load(os.path.join('Media', 'Pic', 'four.png')), - pygame.image.load(os.path.join('Media', 'Pic', 'five.png')), - pygame.image.load(os.path.join('Media', 'Pic', 'six.png'))] +DicePics: list = [pygame.image.load(os.path.join('Media', 'Pic', '1.png')), + pygame.image.load(os.path.join('Media', 'Pic', '2.png')), + pygame.image.load(os.path.join('Media', 'Pic', '3.png')), + pygame.image.load(os.path.join('Media', 'Pic', '4.png')), + pygame.image.load(os.path.join('Media', 'Pic', '5.png')), + pygame.image.load(os.path.join('Media', 'Pic', '6.png'))] class Dice(GameItem): diff --git a/src/GameItem/DiceGroup.py b/src/data/DiceGroup.py similarity index 99% rename from src/GameItem/DiceGroup.py rename to src/data/DiceGroup.py index ad94c33..1f8d55f 100644 --- a/src/GameItem/DiceGroup.py +++ b/src/data/DiceGroup.py @@ -1,6 +1,6 @@ import pygame -from src.GameItem.Dice import Dice +from src.data.Dice import Dice class DiceGroup: diff --git a/src/GameData.py b/src/data/GameData.py similarity index 61% rename from src/GameData.py rename to src/data/GameData.py index a08627e..5d75c14 100644 --- a/src/GameData.py +++ b/src/data/GameData.py @@ -1,6 +1,6 @@ -from src.GameItem import ScoreBoard -from src.round import Round -from src.tools.disChoice import disChoice +from src.data import ScoreBoard +from src.data.round import Round +from src.tools.disChoice import disChoice, disChoosed class GameData: @@ -16,3 +16,6 @@ def __init__(self, screen): def displayScore(self): disChoice(self.round, self.screen) + + def displayChoosed(self, userNo): + disChoosed(userNo, self.scoreBoards[userNo], self.screen) diff --git a/src/GameItem/GameItem.py b/src/data/GameItem.py similarity index 100% rename from src/GameItem/GameItem.py rename to src/data/GameItem.py diff --git a/src/GameItem/ScoreBoard.py b/src/data/ScoreBoard.py similarity index 96% rename from src/GameItem/ScoreBoard.py rename to src/data/ScoreBoard.py index 3ab56bb..1c2871f 100644 --- a/src/GameItem/ScoreBoard.py +++ b/src/data/ScoreBoard.py @@ -1,6 +1,6 @@ import pygame -from src.GameItem.GameItem import GameItem +from src.data.GameItem import GameItem class Scoreboard(GameItem): diff --git a/src/round.py b/src/data/round.py similarity index 97% rename from src/round.py rename to src/data/round.py index 4e865c3..1959633 100644 --- a/src/round.py +++ b/src/data/round.py @@ -1,7 +1,7 @@ import pygame.event -from src.GameItem import ScoreBoard -from src.GameItem.DiceGroup import DiceGroup +from src.data import ScoreBoard +from src.data.DiceGroup import DiceGroup from src.events import events diff --git a/src/events/events.py b/src/events/events.py index 29a6a5d..66027aa 100644 --- a/src/events/events.py +++ b/src/events/events.py @@ -24,6 +24,9 @@ rewardUpdatedEvent = '奖励分更新事件' totalUpdateEvent = '总分更新事件' +ChooseKEvent = "选择第K个分数事件" +ChooseKEndEvent = '选择第K个分数结束事件' + ScreenControlEvent = "屏幕控制事件" ScreenRefreshEvent = "屏幕刷新事件" DisplayBackgroundEvent = "显示背景事件" @@ -42,12 +45,20 @@ ChooseKEnd = pygame.USEREVENT + 13 +def chooseKEvent(k: int): + pygame.event.post( + pygame.event.Event(pygame.USEREVENT + 12, {event_type: ChooseEvent, sub_type: ChooseKEvent, "no": k}) + ) + + def StartGameEvent(): - pygame.event.post(pygame.event.Event(pygame.USEREVENT + 1, {event_type: GameControllerEvent, sub_type: Game_Start})) + pygame.event.post( + pygame.event.Event(pygame.USEREVENT + 1, {event_type: GameControllerEvent, sub_type: Game_Start})) def EndGameEvent(): - pygame.event.post(pygame.event.Event(pygame.USEREVENT + 2, {event_type: GameControllerEvent, sub_type: Game_End})) + pygame.event.post( + pygame.event.Event(pygame.USEREVENT + 2, {event_type: GameControllerEvent, sub_type: Game_End})) def RoundStartEvent(): @@ -56,20 +67,24 @@ def RoundStartEvent(): def RoundEndEvent(): - pygame.event.post(pygame.event.Event(pygame.USEREVENT + 3, {event_type: GameControllerEvent, sub_type: Round_End})) + pygame.event.post( + pygame.event.Event(pygame.USEREVENT + 3, {event_type: GameControllerEvent, sub_type: Round_End})) def RollEvent(k: int): - rollEvent = pygame.event.Event(pygame.USEREVENT + 4, {event_type: RollControllerEvent, sub_type: Roll, 'times': k}) + rollEvent = pygame.event.Event(pygame.USEREVENT + 4, + {event_type: RollControllerEvent, sub_type: Roll, 'times': k}) pygame.event.post(rollEvent) def RollStartEvent(): - pygame.event.post(pygame.event.Event(pygame.USEREVENT + 6, {event_type: RollControllerEvent, sub_type: Roll_Start})) + pygame.event.post( + pygame.event.Event(pygame.USEREVENT + 6, {event_type: RollControllerEvent, sub_type: Roll_Start})) def RollEndEvent(): - pygame.event.post(pygame.event.Event(pygame.USEREVENT + 7, {event_type: RollControllerEvent, sub_type: Roll_End})) + pygame.event.post( + pygame.event.Event(pygame.USEREVENT + 7, {event_type: RollControllerEvent, sub_type: Roll_End})) def remainEvent(k: int) -> None: @@ -108,7 +123,8 @@ def screenRefreshEvent() -> None: def displayBackgroundEvent() -> None: pygame.event.post( - pygame.event.Event(pygame.USEREVENT + 18, {event_type: ScreenControlEvent, sub_type: DisplayBackgroundEvent}) + pygame.event.Event(pygame.USEREVENT + 18, + {event_type: ScreenControlEvent, sub_type: DisplayBackgroundEvent}) ) diff --git a/src/events/handler/EventHandler.py b/src/events/handler/EventHandler.py index 329aa93..a018b96 100644 --- a/src/events/handler/EventHandler.py +++ b/src/events/handler/EventHandler.py @@ -1,6 +1,6 @@ import abc -from src.GameData import GameData +from src.data.GameData import GameData from src.events.events import * diff --git a/src/events/handler/GameControllerEventHandler.py b/src/events/handler/GameControllerEventHandler.py index 7233135..9b946a6 100644 --- a/src/events/handler/GameControllerEventHandler.py +++ b/src/events/handler/GameControllerEventHandler.py @@ -1,7 +1,7 @@ -from src.GameData import GameData +from src.data.GameData import GameData from src.events.events import * from src.events.handler.EventHandler import EventHandler -from src.round import Round +from src.data.round import Round class GameControllerEventHandler(EventHandler): @@ -30,10 +30,10 @@ def event(self, event: pygame.event.Event): # 处理回合开始事件 elif self.get_sub_type(event) == Round_Start: - self.roundCount += 12 + RollEvent(1) + self.roundCount += 1 self.data.round = Round(self.data.scoreBoards) displayInfoEvent() - RollStartEvent() # 处理回合结束事件 elif self.get_sub_type(event) == Round_End: diff --git a/src/events/handler/RollEventHandler.py b/src/events/handler/RollEventHandler.py index f6fd19a..9af3c58 100644 --- a/src/events/handler/RollEventHandler.py +++ b/src/events/handler/RollEventHandler.py @@ -1,5 +1,5 @@ -from src import music -from src.GameData import GameData +from src.VideoMusicControl import music +from src.data.GameData import GameData from src.events.events import * from src.events.handler.EventHandler import EventHandler @@ -44,5 +44,5 @@ def event(self, event: pygame.event.Event): # 接收到Roll结束事件 elif self.get_sub_type(event) == Roll_End: - music.pause() - pass \ No newline at end of file + chooseKEvent(0) + pass diff --git a/src/events/handler/ScreenEventHandler.py b/src/events/handler/ScreenEventHandler.py index d0f5b8d..8518a95 100644 --- a/src/events/handler/ScreenEventHandler.py +++ b/src/events/handler/ScreenEventHandler.py @@ -27,22 +27,28 @@ def event(self, event: pygame.event.Event): # 显示背景事件 if self.get_sub_type(event) == DisplayBackgroundEvent: self.disBGandRoll() - # 显示分数事件 + # 显示分数事件 if self.get_sub_type(event) == DisplayInfoEvent: # 显示选择的小分 + self.data.displayChoosed(1 - self.data.round.userNo) self.data.displayScore() - # 显示奖励分 - if self.data.scoreBoards[self.data.round.userNo].isReward() >= 63: - displaytext(self.data.screen, (7, self.data.round.userNo), 35, True) - else: - displaytext(self.data.screen, (7, self.data.round.userNo), 0, True) - # 显示小记 - displaytext(self.data.screen, (6, self.data.round.userNo), - self.data.scoreBoards[self.data.round.userNo].totalScoreofNumber(), True) + for userNo in range(2): + # 显示奖励分 + if self.data.scoreBoards[userNo].isReward() >= 63: + displaytext(self.data.screen, (7, userNo), 35, True) + else: + displaytext(self.data.screen, (7, userNo), 0, True) + # 显示小记 + displaytext(self.data.screen, (6, userNo), + self.data.scoreBoards[userNo].totalScoreofNumber(), True) + # 显示总分 + displaytext(self.data.screen, (14, userNo), + self.data.scoreBoards[userNo].totalScore(), True) # 调用屏幕刷新事件,刷新屏幕 screenRefreshEvent() elif self.get_sub_type(event) == DisplayDicesEvent: self.data.round.diceGroup.displayDices(self.data.screen) + screenRefreshEvent() def disBGandRoll(self): disBg(self.data.screen) diff --git a/src/setup.py b/src/setup.py index fcd4721..fa9d461 100644 --- a/src/setup.py +++ b/src/setup.py @@ -3,7 +3,7 @@ import pygame from SpeedboatDice import SpeedboatDice -from src import video, music +from src.VideoMusicControl import video, music # 初始化 pygame 设置 diff --git a/src/tools/disChoice.py b/src/tools/disChoice.py index ef73fc0..e6fdd43 100644 --- a/src/tools/disChoice.py +++ b/src/tools/disChoice.py @@ -1,9 +1,10 @@ import pygame -from src.round import Round + +from src.data.round import Round from src.tools.text import displaytext -def disChoice(round:Round, screen: pygame.Surface) -> None: +def disChoice(round: Round, screen: pygame.Surface) -> None: """ Display the choice of dice to be kept. :param diceGroup: @@ -75,3 +76,50 @@ def disChoice(round:Round, screen: pygame.Surface) -> None: displaytext(screen, (13, userNo), scoreBoard.speedboat(), True) else: displaytext(screen, (13, userNo), diceGroup.speedboat(), False) + + +def disChoosed(userNo: int, scoreBoard,screen) -> None: + """ + Display the choice of dice to be kept. + :param diceGroup: + :param scoreBoard: + :param userNo: + :param screen: + :return: + """ + # 显示 1 + if scoreBoard.one > 0: + displaytext(screen, (0, userNo), scoreBoard.one, True) + # 显示 2 + if scoreBoard.two > 0: + displaytext(screen, (1, userNo), scoreBoard.two, True) + # 显示 3 + if scoreBoard.three > 0: + displaytext(screen, (2, userNo), scoreBoard.three, True) + # 显示 4 + if scoreBoard.four > 0: + displaytext(screen, (3, userNo), scoreBoard.four, True) + # 显示 5 + if scoreBoard.five > 0: + displaytext(screen, (4, userNo), scoreBoard.five, True) + # 显示 6 + if scoreBoard.six > 0: + displaytext(screen, (5, userNo), scoreBoard.six, True) + # 显示全选 + if scoreBoard.total > 0: + displaytext(screen, (8, userNo), scoreBoard.total, True) + # 显示四骰同花 + if scoreBoard.fourSame > 0: + displaytext(screen, (9, userNo), scoreBoard.fourSame(), True) + # 显示葫芦 + if scoreBoard.calabash > 0: + displaytext(screen, (10, userNo), scoreBoard.calabash(), True) + # 显示小顺 + if scoreBoard.smallStraights > 0: + displaytext(screen, (11, userNo), scoreBoard.smallStraights(), True) + # 显示大顺 + if scoreBoard.largeStraights > 0: + displaytext(screen, (12, userNo), scoreBoard.largeStraights(), True) + # 显示快艇 + if scoreBoard.speedboat > 0: + displaytext(screen, (13, userNo), scoreBoard.speedboat(), True) diff --git a/src/userInput.py b/src/tools/userInput.py similarity index 90% rename from src/userInput.py rename to src/tools/userInput.py index 8dde2a0..20b6a8f 100644 --- a/src/userInput.py +++ b/src/tools/userInput.py @@ -1,9 +1,8 @@ import pygame.event from pygame.event import Event as Event +from src.data.round import Round from src.events.events import * -from round import Round -from src import events def BlockUserInput(): @@ -37,7 +36,7 @@ def remainingK(k: int) -> None: 如果用户选择保留/不保留 第 K 个骰子,请立刻触发该事件 :return: """ - events.remainEvent(k) + remainEvent(k) def chooseKScore(k: int) -> None: @@ -46,7 +45,7 @@ def chooseKScore(k: int) -> None: :param k: :return: """ - events.chooseEvent(k) + chooseKEvent(k) def roll() -> None: @@ -54,7 +53,7 @@ def roll() -> None: 如果用户决定开始投骰子,请触发该函数 :return: """ - events.RollStartEvent() + RollStartEvent() def processUserInput(event: Event, round: Round):