Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, sys, time, os
- from colorama import Fore, Back, Style
- from colorama import init
- init()
- def GAME():
- print(Fore.CYAN + """
- ______________________________________
- | Master Mind |
- --------------------------------------
- Hey! Welcome to Mastermind.
- Master Mind is a game where you must
- guess the 4 character secret color code I have
- created. If you guess the secret`
- color code you win. If you fail with
- in 6 guesses, the secret vault will
- explode leaving nothing to spare.
- Remember to use the colors from the list
- """)
- print(Style.RESET_ALL)
- colors = ('R','B','G','P','Y')
- print""
- MixtureC = (str(random.sample(colors, 4)))
- Color1 = (MixtureC[2]) #Color 1 threw 4 choice a random color by choosing from the list "colors"
- Color2 = (MixtureC[7])
- Color3 = (MixtureC[12])
- Color4 = (MixtureC[17])
- Cset = (" " + Fore.RED +"R, " + Fore.BLUE + 'B, '+ Fore.GREEN +"G, "+ Fore.MAGENTA +"P, "+ Fore.YELLOW +"Y, ")
- count = 1
- while True:
- #print (Color1,Color2,Color3,Color4) #Testing Only
- print Cset
- print(Style.RESET_ALL)
- print""
- print " Guess the secret color code!"
- print""
- guess1 = raw_input(" First Color: ") #askes the players to guess what color is first, second, and so on
- guess2 = raw_input(" Second Color: ")
- guess3 = raw_input(" Third Color: ")
- guess4 = raw_input(" Fourth Color: ")
- guess1 = (guess1)
- guess2 = (guess2)
- guess3 = (guess3)
- guess4 = (guess4)
- guesses = (guess1,guess2,guess3,guess4)
- Allcolors = (Color1,Color2,Color3,Color4)
- NC = 0
- if guess1 == "dev":
- print (Color1,Color2,Color3,Color4)
- if guess1 != Color1: # tells if the players has got the correct color to the code and adds it to a variable
- NC += 1 # which tells you how many you have got correct
- if guess2 != Color2:
- NC += 1
- if guess3 != Color3:
- NC += 1
- if guess4 != Color4:
- NC += 1
- ### Print if color is correct or not ###
- if guesses == Allcolors:
- print""
- print Fore.GREEN +" All colors are correct!"
- print(Style.RESET_ALL)
- if guesses != Allcolors:
- print""
- if guess1 == Color1:#tells the player if one of the colors are corect and where.
- print""
- print Fore.GREEN +" Color 1 is correct"
- print(Style.RESET_ALL)
- if guess1 != Color1:
- if guess1 == Color2 or guess1 == Color3 or guess1 == Color4:
- print Fore.YELLOW + " Guess 1 right color wrong positions"
- print(Style.RESET_ALL)
- else:
- print Fore.RED +" Color 1 is incorrect"
- print(Style.RESET_ALL)
- if guess2 == Color2:
- print Fore.GREEN +" Color 2 is correct"
- print(Style.RESET_ALL)
- if guess2 != Color2:
- if guess2 == Color1 or guess2 == Color3 or guess2 == Color4:
- print Fore.YELLOW + " Guess 2 right color wrong positions"
- print(Style.RESET_ALL)
- else:
- print Fore.RED +" Color 2 is incorrect"
- print(Style.RESET_ALL)
- if guess3 == Color3:
- print Fore.GREEN +" Color 3 is correct"
- print(Style.RESET_ALL)
- if guess3 != Color3:
- if guess3 == Color1 or guess3 == Color2 or guess3 == Color4:
- print Fore.YELLOW + " Guess 3 right color wrong positions"
- print(Style.RESET_ALL)
- else:
- print Fore.RED +" Color 3 is incorrect"
- print(Style.RESET_ALL)
- if guess4 == Color4:
- print Fore.GREEN +" Color 4 is correct"
- print(Style.RESET_ALL)
- if guess4 != Color4:
- if guess4 == Color1 or guess4 == Color2 or guess4 == Color3:
- print Fore.YELLOW + " Guess 4 right color wrong positions"
- print(Style.RESET_ALL)
- else:
- print Fore.RED +" Color 4 is incorrect"
- print(Style.RESET_ALL)
- if NC == 0:
- print ""
- print(' It took you ' + str(count) + ' trie(s) to crack the code!')
- print " the code was " + str(Color1) + " " + str(Color2) + " " + str(Color3) + " " + str(Color4)
- break
- else:
- print""
- print(' You got ' + str(4-NC) + ' colors in the proper position.')
- print ""
- print " Please try again."
- count += 1
- if count == 1:
- print " 5 guesses left"
- print""
- if count == 2:
- print " 4 guesses left"
- print""
- if count == 3:
- print " 3 guesses left"
- print""
- if count == 4:
- print " 2 guesses left"
- print""
- if count == 5:
- print " 1 guesses left"
- print""
- if count == 6:
- print" You have reached the maximum guess count!"
- print" 5 seconds till self destruct."
- print""
- print" 5"
- time.sleep(1)
- print" 4"
- time.sleep(1)
- print" 3"
- time.sleep(1)
- print" 2"
- time.sleep(1)
- print" 1"
- time.sleep(1)
- print Fore.RED +" KABOOOM"
- sys.exit()
- def play_again():
- print""
- return raw_input(" Do you want to play agian? yes/no ").lower() == "yes"
- while True:
- GAME()
- if not play_again():break
- print " Goodbye"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement