Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.17 KB | None | 0 0
  1. import random, sys, time, os
  2. from colorama import Fore, Back, Style
  3. from colorama import init
  4. init()
  5. def GAME():
  6. print(Fore.CYAN + """
  7. ______________________________________
  8. | Master Mind |
  9. --------------------------------------
  10. Hey! Welcome to Mastermind.
  11. Master Mind is a game where you must
  12. guess the 4 character secret color code I have
  13. created. If you guess the secret`
  14. color code you win. If you fail with
  15. in 6 guesses, the secret vault will
  16. explode leaving nothing to spare.
  17. Remember to use the colors from the list
  18.  
  19. """)
  20. print(Style.RESET_ALL)
  21. colors = ('R','B','G','P','Y')
  22. print""
  23.  
  24. MixtureC = (str(random.sample(colors, 4)))
  25. Color1 = (MixtureC[2]) #Color 1 threw 4 choice a random color by choosing from the list "colors"
  26. Color2 = (MixtureC[7])
  27. Color3 = (MixtureC[12])
  28. Color4 = (MixtureC[17])
  29. Cset = (" " + Fore.RED +"R, " + Fore.BLUE + 'B, '+ Fore.GREEN +"G, "+ Fore.MAGENTA +"P, "+ Fore.YELLOW +"Y, ")
  30. count = 1
  31.  
  32. while True:
  33. #print (Color1,Color2,Color3,Color4) #Testing Only
  34. print Cset
  35. print(Style.RESET_ALL)
  36. print""
  37. print " Guess the secret color code!"
  38. print""
  39. guess1 = raw_input(" First Color: ") #askes the players to guess what color is first, second, and so on
  40. guess2 = raw_input(" Second Color: ")
  41. guess3 = raw_input(" Third Color: ")
  42. guess4 = raw_input(" Fourth Color: ")
  43. guess1 = (guess1)
  44. guess2 = (guess2)
  45. guess3 = (guess3)
  46. guess4 = (guess4)
  47. guesses = (guess1,guess2,guess3,guess4)
  48. Allcolors = (Color1,Color2,Color3,Color4)
  49. NC = 0
  50. if guess1 == "dev":
  51. print (Color1,Color2,Color3,Color4)
  52. if guess1 != Color1: # tells if the players has got the correct color to the code and adds it to a variable
  53. NC += 1 # which tells you how many you have got correct
  54. if guess2 != Color2:
  55. NC += 1
  56. if guess3 != Color3:
  57. NC += 1
  58. if guess4 != Color4:
  59. NC += 1
  60.  
  61. ### Print if color is correct or not ###
  62. if guesses == Allcolors:
  63. print""
  64. print Fore.GREEN +" All colors are correct!"
  65. print(Style.RESET_ALL)
  66. if guesses != Allcolors:
  67. print""
  68.  
  69. if guess1 == Color1:#tells the player if one of the colors are corect and where.
  70. print""
  71. print Fore.GREEN +" Color 1 is correct"
  72. print(Style.RESET_ALL)
  73. if guess1 != Color1:
  74. if guess1 == Color2 or guess1 == Color3 or guess1 == Color4:
  75. print Fore.YELLOW + " Guess 1 right color wrong positions"
  76. print(Style.RESET_ALL)
  77. else:
  78. print Fore.RED +" Color 1 is incorrect"
  79. print(Style.RESET_ALL)
  80. if guess2 == Color2:
  81. print Fore.GREEN +" Color 2 is correct"
  82. print(Style.RESET_ALL)
  83. if guess2 != Color2:
  84. if guess2 == Color1 or guess2 == Color3 or guess2 == Color4:
  85. print Fore.YELLOW + " Guess 2 right color wrong positions"
  86. print(Style.RESET_ALL)
  87. else:
  88. print Fore.RED +" Color 2 is incorrect"
  89. print(Style.RESET_ALL)
  90.  
  91. if guess3 == Color3:
  92. print Fore.GREEN +" Color 3 is correct"
  93. print(Style.RESET_ALL)
  94. if guess3 != Color3:
  95. if guess3 == Color1 or guess3 == Color2 or guess3 == Color4:
  96. print Fore.YELLOW + " Guess 3 right color wrong positions"
  97. print(Style.RESET_ALL)
  98. else:
  99. print Fore.RED +" Color 3 is incorrect"
  100. print(Style.RESET_ALL)
  101.  
  102. if guess4 == Color4:
  103. print Fore.GREEN +" Color 4 is correct"
  104. print(Style.RESET_ALL)
  105. if guess4 != Color4:
  106. if guess4 == Color1 or guess4 == Color2 or guess4 == Color3:
  107. print Fore.YELLOW + " Guess 4 right color wrong positions"
  108. print(Style.RESET_ALL)
  109. else:
  110. print Fore.RED +" Color 4 is incorrect"
  111. print(Style.RESET_ALL)
  112.  
  113.  
  114. if NC == 0:
  115. print ""
  116. print(' It took you ' + str(count) + ' trie(s) to crack the code!')
  117. print " the code was " + str(Color1) + " " + str(Color2) + " " + str(Color3) + " " + str(Color4)
  118. break
  119. else:
  120. print""
  121. print(' You got ' + str(4-NC) + ' colors in the proper position.')
  122. print ""
  123. print " Please try again."
  124. count += 1
  125.  
  126. if count == 1:
  127. print " 5 guesses left"
  128. print""
  129. if count == 2:
  130. print " 4 guesses left"
  131. print""
  132. if count == 3:
  133. print " 3 guesses left"
  134. print""
  135. if count == 4:
  136. print " 2 guesses left"
  137. print""
  138. if count == 5:
  139. print " 1 guesses left"
  140. print""
  141.  
  142. if count == 6:
  143. print" You have reached the maximum guess count!"
  144. print" 5 seconds till self destruct."
  145. print""
  146.  
  147. print" 5"
  148. time.sleep(1)
  149. print" 4"
  150. time.sleep(1)
  151. print" 3"
  152. time.sleep(1)
  153. print" 2"
  154. time.sleep(1)
  155. print" 1"
  156. time.sleep(1)
  157. print Fore.RED +" KABOOOM"
  158. sys.exit()
  159. def play_again():
  160. print""
  161. return raw_input(" Do you want to play agian? yes/no ").lower() == "yes"
  162.  
  163. while True:
  164. GAME()
  165. if not play_again():break
  166. print " Goodbye"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement