Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tom Pillot
Thymio Game
Commits
04e86098
Commit
04e86098
authored
Jul 03, 2020
by
Tom Pillot
Browse files
Stop broadcasting start message after MAX_START_SENT message are sent
parent
21e8d12a
Changes
1
Hide whitespace changes
Inline
Side-by-side
game/scoreboard.py
View file @
04e86098
...
...
@@ -11,6 +11,7 @@ class ScoreWindow(ScoreWindowUi):
SEND_TIME
=
500
WEBCAM_REFRESH_TIME
=
50
PORT
=
42563
MAX_START_SENT
=
5
def
__init__
(
self
,
teams
):
super
().
__init__
()
...
...
@@ -29,6 +30,7 @@ class ScoreWindow(ScoreWindowUi):
self
.
scoreboard_timer
=
qtc
.
QTimer
()
self
.
webcam_timer
=
qtc
.
QTimer
()
self
.
send_timer
=
qtc
.
QTimer
()
self
.
start_sent
=
0
# Number of start message sent
self
.
start_join_button
.
clicked
.
connect
(
self
.
start_stop_activity
)
...
...
@@ -157,6 +159,7 @@ class ScoreWindow(ScoreWindowUi):
self
.
join_started
=
False
# Run all Thymios at the same time
self
.
start_sent
=
0
reconnect
(
self
.
send_timer
.
timeout
,
self
.
send_start_broadcast
)
self
.
send_timer
.
start
(
self
.
SEND_TIME
)
...
...
@@ -170,13 +173,20 @@ class ScoreWindow(ScoreWindowUi):
def
send_join_broadcast
(
self
):
""" Send a message to all Thymios so they can join the activity """
print
(
"Broadcasting join message ..."
)
self
.
socket
.
sendto
(
"join"
.
encode
(),
self
.
socket_dest
)
self
.
send_timer
.
start
(
self
.
SEND_TIME
)
def
send_start_broadcast
(
self
):
""" Send a message to all Thymios to run at the same time """
self
.
socket
.
sendto
(
"start"
.
encode
(),
self
.
socket_dest
)
self
.
send_timer
.
start
(
self
.
SEND_TIME
)
""" Send a message to all Thymios to run at the same time. After MAX_START_SENT, stop sending these message """
if
self
.
start_sent
<
self
.
MAX_START_SENT
:
print
(
"Broadcasting start message ..."
)
self
.
start_sent
+=
1
self
.
socket
.
sendto
(
"start"
.
encode
(),
self
.
socket_dest
)
self
.
send_timer
.
start
(
self
.
SEND_TIME
)
else
:
self
.
start_sent
=
0
self
.
send_timer
.
stop
()
def
reconnect
(
signal
,
new_handler
=
None
,
old_handler
=
None
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment