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

Commit

Permalink
处理chooseK事件
Browse files Browse the repository at this point in the history
  • Loading branch information
Llonvne committed May 2, 2022
1 parent c4bb7a5 commit f7de594
Show file tree
Hide file tree
Showing 23 changed files with 128 additions and 56 deletions.
Binary file added Media/Pic/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Media/Pic/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Media/Pic/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Media/Pic/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Media/Pic/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Media/Pic/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions src/SpeedboatDice.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 处理鼠标的事件
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions src/GameItem/Dice.py → src/data/Dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/GameItem/DiceGroup.py → src/data/DiceGroup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame

from src.GameItem.Dice import Dice
from src.data.Dice import Dice


class DiceGroup:
Expand Down
9 changes: 6 additions & 3 deletions src/GameData.py → src/data/GameData.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
File renamed without changes.
2 changes: 1 addition & 1 deletion src/GameItem/ScoreBoard.py → src/data/ScoreBoard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame

from src.GameItem.GameItem import GameItem
from src.data.GameItem import GameItem


class Scoreboard(GameItem):
Expand Down
4 changes: 2 additions & 2 deletions src/round.py → src/data/round.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
30 changes: 23 additions & 7 deletions src/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
rewardUpdatedEvent = '奖励分更新事件'
totalUpdateEvent = '总分更新事件'

ChooseKEvent = "选择第K个分数事件"
ChooseKEndEvent = '选择第K个分数结束事件'

ScreenControlEvent = "屏幕控制事件"
ScreenRefreshEvent = "屏幕刷新事件"
DisplayBackgroundEvent = "显示背景事件"
Expand All @@ -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():
Expand All @@ -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:
Expand Down Expand Up @@ -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})
)


Expand Down
2 changes: 1 addition & 1 deletion src/events/handler/EventHandler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc

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


Expand Down
8 changes: 4 additions & 4 deletions src/events/handler/GameControllerEventHandler.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/events/handler/RollEventHandler.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -44,5 +44,5 @@ def event(self, event: pygame.event.Event):

# 接收到Roll结束事件
elif self.get_sub_type(event) == Roll_End:
music.pause()
pass
chooseKEvent(0)
pass
24 changes: 15 additions & 9 deletions src/events/handler/ScreenEventHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pygame

from SpeedboatDice import SpeedboatDice
from src import video, music
from src.VideoMusicControl import video, music

# 初始化 pygame 设置

Expand Down
52 changes: 50 additions & 2 deletions src/tools/disChoice.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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)
9 changes: 4 additions & 5 deletions src/userInput.py → src/tools/userInput.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -37,7 +36,7 @@ def remainingK(k: int) -> None:
如果用户选择保留/不保留 第 K 个骰子,请立刻触发该事件
:return:
"""
events.remainEvent(k)
remainEvent(k)


def chooseKScore(k: int) -> None:
Expand All @@ -46,15 +45,15 @@ def chooseKScore(k: int) -> None:
:param k:
:return:
"""
events.chooseEvent(k)
chooseKEvent(k)


def roll() -> None:
"""
如果用户决定开始投骰子,请触发该函数
:return:
"""
events.RollStartEvent()
RollStartEvent()


def processUserInput(event: Event, round: Round):
Expand Down

0 comments on commit f7de594

Please sign in to comment.