Advertisement
superpawko

Untitled

Sep 30th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. def playGame(wordList):
  2. hand = {}
  3. user_input = ""
  4. n = HAND_SIZE
  5.  
  6. while user_input != "e":
  7. while True: # checking and reacting on first input
  8. user_input = input("Enter n to deal a new hand, r to replay the last hand, or e to end game: ")
  9. try:
  10. if user_input not in ('n', 'r', 'e'):
  11. raise Exception
  12.  
  13. except Exception:
  14. print("Invalid command.")
  15. print("")
  16. else:
  17.  
  18. try: # What if HAND is empty and it can not REPLAY
  19. if user_input == "r":
  20. if sum(hand.values()) == 0:
  21. raise Exception
  22. except Exception:
  23. print("You have not played a hand yet. Please play a new hand first!")
  24. else:
  25. print("")
  26. break
  27. # Handle exception
  28. if user_input == "e":
  29. break
  30.  
  31. while True: # checking and reacting on second input
  32. user_input2 = input("Enter u to have yourself play, c to have the computer play:")
  33. try:
  34. if user_input2 not in ('c', 'u'):
  35. raise Exception
  36. except Exception:
  37. print("Invalid command.")
  38. print("")
  39. else:
  40. print("")
  41. break
  42.  
  43. # if inputs are correct continue below
  44.  
  45. if user_input == "r":
  46. if user_input2 == 'c':
  47. compPlayHand(hand, wordList, n)
  48. else:
  49. playHand(hand, wordList, n)
  50. if user_input == "n":
  51. hand = dealHand(n)
  52. if user_input2 == 'c':
  53. compPlayHand(hand, wordList, n)
  54. else:
  55. playHand(hand, wordList, n)
  56. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement