daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def save_game(board, user, whose_turn):
  2.     file = open("game.txt", mode="w")
  3.     for cell in game_board:
  4.         file.write(cell)
  5.         file.write('\n')
  6.     file.write('\n')
  7.     file.write(user)
  8.     file.write('\n')
  9.     file.write(whose_turn)
  10.     file.close()
  11.  
  12. def load_game():
  13.     file = open("game.txt", mode="r")
  14.     parts = file.read().splitlines()
  15.     board = parts[0:9]
  16.     user = parts[10]
  17.     turn = parts[11]
  18.     return [board, user, turn]
  19.  
  20.  
  21. ### Example
  22.  
  23. game_board = ['X', 'O', 'O', 'O', 'X', 'O',' ', 'O', 'X']
  24. user = 'X'
  25. computer = 'O'
  26. whose_turn = 'user'
  27.  
  28. game_board, user, whose_turn = load_game()
  29.  
  30. print(whose_turn)
  31.  
  32. # save_game(game_board, user, whose_turn)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top