Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
修正了部分错误的时间逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Llonvne committed May 2, 2022
1 parent 41438cc commit c4bb7a5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
7 changes: 2 additions & 5 deletions src/events/handler/EventHandler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import abc

import pygame

from src import events
from src.GameData import GameData
from src.events.events import *

Expand All @@ -15,15 +12,15 @@ class EventHandler:

def __init__(self, data: GameData):
"""
构造方法,默认构造
构造方法,默认构造data到事件处理库
:param data:
"""
self.data = data

@abc.abstractmethod
def event(self, event: pygame.event.Event):
"""
事件处理抽象方法
提供抽象接口
:param event:
:return:
"""
Expand Down
7 changes: 3 additions & 4 deletions src/events/handler/GameControllerEventHandler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from src.GameData import GameData
from src.events.handler.EventHandler import EventHandler

from src.events.events import *
from src.events.handler.EventHandler import EventHandler
from src.round import Round


Expand Down Expand Up @@ -31,14 +30,14 @@ def event(self, event: pygame.event.Event):

# 处理回合开始事件
elif self.get_sub_type(event) == Round_Start:
self.roundCount += 1
self.roundCount += 12
self.data.round = Round(self.data.scoreBoards)
displayInfoEvent()
RollStartEvent()

# 处理回合结束事件
elif self.get_sub_type(event) == Round_End:
if self.roundCount == 12:
if self.roundCount >= 12:
EndGameEvent()
else:
RoundStartEvent()
12 changes: 8 additions & 4 deletions src/events/handler/RollEventHandler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from src import music
from src.GameData import GameData
from src.events.events import *
from src.events.handler.EventHandler import EventHandler
Expand All @@ -10,9 +11,9 @@ def __init__(self, data: GameData):

def event(self, event: pygame.event.Event):
if self.get_sub_type(event) == Roll:
# 接收到 Roll 事件后开始 Roll 操作
self.data.round.diceGroup.rollNotRemaining()
if event.__dict__['times'] > 0:
# 接收到 Roll 事件后开始 Roll 操作
self.data.round.diceGroup.rollNotRemaining()
# 显示背景事件
displayBackgroundEvent()
# 显示骰子
Expand All @@ -25,6 +26,8 @@ def event(self, event: pygame.event.Event):
wait(300)
# 推入下一个事件
RollEvent(event.__dict__['times'] - 1)
else:
RollEndEvent()

# 接收到保留 第 K 个骰子事件
elif self.get_sub_type(event) == RemainEvent:
Expand All @@ -40,5 +43,6 @@ def event(self, event: pygame.event.Event):
self.data.round.roll()

# 接收到Roll结束事件
elif self.get_sub_type(event) == Round_End:
pass
elif self.get_sub_type(event) == Roll_End:
music.pause()
pass
7 changes: 1 addition & 6 deletions src/round.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pygame.event

from src.events import events
from src.GameItem import ScoreBoard
from src.GameItem.DiceGroup import DiceGroup

from src.events import events


class Round:
Expand Down Expand Up @@ -59,15 +58,11 @@ def roll(self):
if self.chance1 > 0:
# 引发 RollEvent 事件
events.RollEvent(5)
# 引发 RollEnd 事件
events.RollEndEvent()
self.chance1 -= 1
else:
if self.chance2 > 0:
# 引发 RollEvent 事件
events.RollEvent(5)
# 引发 RollEnd 事件
events.RollEndEvent()
self.chance2 -= 1
pass

Expand Down

0 comments on commit c4bb7a5

Please sign in to comment.