from GUI import MasterMindGUI import random class MasterServiceLayer(object): colours = ('r', 'b', 'g', 'y', 'p', 'o', 'w', 'v') # tuple containing all possible colour values colournames = {'r' : 'Red', 'b' : 'Blue', 'g' : 'Green', 'y' : 'Yellow', 'p' : 'Purple', 'o' : 'Orange', 'w' : 'White', 'v' : 'Violet'} # dictionary to identify colours #---------------------------------------------GETCOLOURS------------------------------------------------------------------------------------------- def getcolours(number): # gets a list of colours depending on how many colours they select at the start return MasterServiceLayer.colours[:number] #--------------------------------------------------ERROR--------------------------------------------------------------------------------- #--------------------------------------------------CALCCOLOURLST-------------------------------------------------------------------------------------------- def colourlst(number): # function used to make a string with the names of all the colours being used for when the program starts colourString = "The colour avaliable are: " # intalise variables names = "" Colourlst = list(MasterServiceLayer.getcolours(number)) # get Colourlst e.g. [r,b,g] for letters in Colourlst: names = MasterServiceLayer.colournames[letters] # refrence dictionary to use key and get the value returned colourString = colourString + names + "," #concatenate the string together names = "" return colourString #---------------------------------------------------CALCULATEPEGS------------------------------------------------------------------------------------ def calculatepegs(NoOfPegs, NoOfColours, peglst): # calculate the pegs to be guessed Colourlst = list(MasterServiceLayer.getcolours(NoOfColours)) # gets the colourlst e.g. [r,b,g] for i in range(NoOfPegs): # for the number of pegs peglst.append(random.choice(Colourlst)) # append a random colour #-------------------------------------------------------STARTSEQUENCE----------------------------------------------------------------------------- def start(NoOfPegs, NoOfColours, peglst): MasterMindGUI.StartGame(MasterServiceLayer.colourlst(NoOfColours)) MasterMindGUI.DrawGUI(NoOfPegs) # draw the text based user interface MasterServiceLayer.calculatepegs(NoOfPegs, NoOfColours, peglst) # calculate the pegs colours to be guessed #------------------------------------------------------USERENTRY----------------------------------------------------------------- #--------------------------------------------------GETGUESS------------------------------------------------------------------ #-------------------------------------------------CHECKGUESS------------------------------------------------------------- #-----------------------------------------------------CHECKWIN--------------------------------------------------------------