TicTacToe: Refactor new-game handling into existing section.
Also extend storage-update section; all related storage.put calls are now together.
This commit is contained in:
parent
33e8517b87
commit
d10601b554
|
@ -283,14 +283,15 @@ class ticTacToeHandler(object):
|
||||||
if not storage.contains(original_sender):
|
if not storage.contains(original_sender):
|
||||||
storage.put(original_sender, None)
|
storage.put(original_sender, None)
|
||||||
user_board = storage.get(original_sender)
|
user_board = storage.get(original_sender)
|
||||||
if (not user_board) and command == "new":
|
|
||||||
user_board = copy.deepcopy(initial_board)
|
|
||||||
storage.put(original_sender, user_board)
|
|
||||||
user_game = TicTacToeGame(user_board) if user_board else None
|
user_game = TicTacToeGame(user_board) if user_board else None
|
||||||
|
|
||||||
move = None
|
move = None
|
||||||
if command == 'new':
|
if command == 'new':
|
||||||
if user_game and not first_time(user_game.board):
|
if not user_board:
|
||||||
|
user_board = copy.deepcopy(initial_board)
|
||||||
|
user_game = TicTacToeGame(user_board)
|
||||||
|
move = "new"
|
||||||
|
if not first_time(user_game.board):
|
||||||
return_content = "You're already playing a game! Type **@tictactoe help** or **@ttt help** to see valid inputs."
|
return_content = "You're already playing a game! Type **@tictactoe help** or **@ttt help** to see valid inputs."
|
||||||
else:
|
else:
|
||||||
return_content = "Welcome to tic-tac-toe! You'll be x's and I'll be o's. Your move first!\n"
|
return_content = "Welcome to tic-tac-toe! You'll be x's and I'll be o's. Your move first!\n"
|
||||||
|
@ -308,7 +309,7 @@ class ticTacToeHandler(object):
|
||||||
if move is not None:
|
if move is not None:
|
||||||
if any(reset_text in move for reset_text in ("win", "draw", "quit")):
|
if any(reset_text in move for reset_text in ("win", "draw", "quit")):
|
||||||
storage.put(original_sender, None)
|
storage.put(original_sender, None)
|
||||||
elif move is "next_turn":
|
elif any(keep_text == move for keep_text in ("new", "next_turn")):
|
||||||
storage.put(original_sender, user_board)
|
storage.put(original_sender, user_board)
|
||||||
else: # "filled" => no change, user_board remains the same
|
else: # "filled" => no change, user_board remains the same
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue