Skip to content

Commit 3bc7d36

Browse files
committed
update gomoku demo
1 parent 06217af commit 3bc7d36

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

demos/gomoku_game.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pywebio
44
from pywebio.output import *
5-
from pywebio.session import *
5+
from pywebio import session
66

77
goboard_size = 15
88
# -1 -> none, 0 -> black, 1 -> white
@@ -44,18 +44,16 @@ def main():
4444
session_id += 1
4545
player_count[my_turn] += 1
4646

47-
@defer_call
47+
@session.defer_call
4848
def player_exit():
4949
player_count[my_turn] -= 1
5050

51-
set_env(output_animation=False)
51+
session.set_env(output_animation=False)
5252
put_html("""<style> table th, table td { padding: 0px !important;} button {padding: .75rem!important; margin:0!important} </style>""") # Custom styles to make the board more beautiful
5353

5454
put_markdown(f"""# Online Shared Gomoku Game
55-
All online players are assigned to two groups (black and white) and share this game. \nYou can open this page in multiple tabs of your browser to simulate multiple users.
56-
This application uses less than 100 lines of code, the source code is [here](https://github.com/wang0618/PyWebIO/blob/dev/demos/gomoku_game.py)
57-
Currently online player: {player_count[0]} for ⚫, {player_count[1]} for ⚪.
58-
Your role is {my_chess}.
55+
All online players are assigned to two groups (black and white) and share this game. You can open this page in multiple tabs of your browser to simulate multiple users. This application uses less than 100 lines of code, the source code is [here](https://github.com/wang0618/PyWebIO/blob/dev/demos/gomoku_game.py)
56+
Currently online player: {player_count[0]} for ⚫, {player_count[1]} for ⚪. Your role is {my_chess}.
5957
""")
6058

6159
def set_stone(pos):
@@ -86,7 +84,7 @@ def show_goboard():
8684
put_text("It's your turn!")
8785
else:
8886
put_row([put_text("Your opponent's turn, waiting... "), put_loading().style('width:1.5em; height:1.5em')], size='auto 1fr')
89-
while current_turn == current_turn_copy: # wait for next move
87+
while current_turn == current_turn_copy and not session.get_current_session().closed(): # wait for next move
9088
time.sleep(0.2)
9189
show_goboard()
9290
with use_scope('msg', clear=True):

0 commit comments

Comments
 (0)