diff --git a/cli/Bank.py b/cli/Bank.py new file mode 100644 index 0000000..9a92428 --- /dev/null +++ b/cli/Bank.py @@ -0,0 +1,21 @@ +class Bank(Target): + def __init__(self, targets): + self.targets = targets + self.__register_targets__() + + def __target_hit__(self, target): + if all(target.is_hit for target in self.targets): + self.__all_targets_hit__() + + def __all_targets_hit__(self): + self.__reset_all_targets__() + super.hit() + pass + + def __reset_all_targets__(self): + for target in self.targets: + target.reset() + + def __register_targets__(self): + for target in self.targets: + target.on(target.hit_key, self.__target_hit__) \ No newline at end of file diff --git a/cli/BankTarget.py b/cli/BankTarget.py new file mode 100644 index 0000000..238b44c --- /dev/null +++ b/cli/BankTarget.py @@ -0,0 +1,15 @@ +from Target import Target + + +class BankTarget(Target): + def __init__(self, points): + super(points) + self.is_hit = False + + def hit(self): + self.is_hit = True + super.hit() + #notify Bank + + def reset(self): + self.is_hit = False \ No newline at end of file diff --git a/cli/FlippR_Networking.py b/cli/FlippR_Networking.py index 95d1c9d..fb1a6b4 100644 --- a/cli/FlippR_Networking.py +++ b/cli/FlippR_Networking.py @@ -46,4 +46,10 @@ class Networking: self.get("/displays" + display + "/write_score/" + str(score)) def getInputEvent(self): - return self.input_socket.recvmsg(4096) + header = '' + while b'2' not in header: + header += self.input_socket.recv() + + length = int(header[:-1]) + + return self.input_socket.recv(length) diff --git a/cli/Main.puml b/cli/Main.puml new file mode 100644 index 0000000..1881008 --- /dev/null +++ b/cli/Main.puml @@ -0,0 +1,71 @@ +@startuml +class Observable { + trigger(string event) + on(string event, function fun) +} + +class FlippR + +class Game + +Game --* Cabinet : isAchievementStrategy ? +Game --* State : observes > +Game "1" --* "*" TargetStrategy + +class TargetStrategy +Target "1" o-- "1" TargetStrategy : observe < +State o-- TargetStrategy : changes < + +class State { + int ballsLeft + int currentBall +} + +State --* BallState + +class BallState { + int score + int globalMultiplier + addScore(int points) +} + +class UpperPlayFieldTimer { + int timeLeft = 0 + start() + stop() +} + +BallState --* UpperPlayFieldTimer +class Cabinet { +} + +Observable <|-- Cabinet +Cabinet "1" --* "*" Target + +Observable <|-- Target +abstract class Target { + int points + string name + hit() +} + +class AchievementTarget { + +} + +Target *-- AchievementTarget +Target <|-- AchievementTarget + +class BankTarget { + bool isHit + hit() + reset() +} +Target <|-- BankTarget + +class Bank + +Target <|-- Bank +Bank "1" --* "1..*" BankTarget : observe > + +@enduml \ No newline at end of file diff --git a/cli/Target.py b/cli/Target.py new file mode 100644 index 0000000..9ae693d --- /dev/null +++ b/cli/Target.py @@ -0,0 +1,10 @@ +class Target(Observable): + def __init__(self, points, name): + self.points = points + self.name = name + self.hit_key = "hit" + + def hit(self): + #notify Observers + #notify Gamestate + self.trigger(self.hit_key, self) \ No newline at end of file