def CBandStripedReaction(ToDestr,First): #Makes every sweet in TBDestroyed a striped version of that sweet 
    Dir = ["V", "H"]
    Index = random.randint(0,1)
    for sweet in ToDestr:##################################################
        Board[sweet.getBoard()[0]][sweet.getBoard()[1]] = Jar.Striped(sweet.getColour(), sweet.getBoard()[0], sweet.getBoard()[1], Board, Dir[Index])
        Board[sweet.getBoard()[0]][sweet.getBoard()[1]].setMatch()#this should fix it

    if First == True: #if its the first time
        for sweet in ToDestr:
            StripeReaction(sweet) #Every sweet becomes a striped in essesnce
def CheckWrappedMatch(Board):
    #need to fix for xtra matches
    # when they fall you cant compare the first sweet in the list anymore- it has to be the corner one
    WrappedMatch = False
    CompX, CompY = MatchedSweets[0].getBoard()
    for tries in range(2):
        sameX = []
        sameY = []
        for sweet in MatchedSweets:
            if sweet.getBoard()[0] == CompX:
                sameX.append(sweet)
            if sweet.getBoard()[1] == CompY:
                sameY.append(sweet)
        if len(sameX) == len(sameY):
            if sweet.getColour() != "D":
                Board[CompX][CompY] = Jar.Wrapped(sweet.getColour(), CompX, CompY, Board)
                WrappedMatch = True
            else:
                Board[CompX][CompY] = Jar.Wrapped("R" , CompX, CompY, Board)
                WrappedMatch = True
            print("I left a wrapped sweet in : ", CompX, CompY)
    CompX, CompY = MatchedSweets[len(MatchedSweets)-1].getBoard()
    return WrappedMatch
Пример #3
0
    def __enQueue(self):  #Private Function, shouldn't be called in main
        ColourOps = ["P", "B", "G", "O", "R", "Y"]
        Index = random.randint(0, 5)
        Col = ColourOps[Index]

        if self.isFull():
            print("The array is full, cannot append soz")

        elif not self.isFull():
            self.CurrentSize = self.CurrentSize + 1
            self.Q[self.Rear + 1] = Jar.Sweet(Col, self.i, self.j, self.Board)
            self.Rear = self.Rear + 1

            if self.Rear == (self.MaxSize - 1):
                self.Rear = -1

        return self.Q
def Populate(Board, Mode):
    ColourOps = ["P", "B", "G", "O", "R", "Y"]
    #Index = random.randint(0,5)
    xMove = 48
    yMove = 48
    Valid = False

    if Mode == "Normal":
        Normal = open("No Matches Board Colours.txt", "r")
        Index = 1
        FileContents = []
        for line in Normal:
            FileContents.append(line)

        for j in range(9):
            for i in range(9):
                """Index = random.randint(0,5)
                    Col = ColourOps[Index]""" #Original
                Index += 1
                Col = ColourOps[int(FileContents[Index])]
                Board[i][j] = Jar.Sweet(Col, i, j, Board)

    elif Mode == "Random":
        for j in range(9):
            for i in range(9):
                Index = random.randint(0, 5)
                Col = ColourOps[Index]
                Board[i][j] = Jar.Sweet(Col, i, j, Board)

    for a in range(2):
        for j in range(9):
            for i in range(9):
                MatchX = CheckSides(Board[i][j], 0)
                MatchY = CheckSides(Board[i][j], 2)
                if MatchX[0] >= 3 or MatchY[0] >= 3:  #check how many matched
                    Col = Board[i][j].getColour()
                    if Board[i][j].getColour() == Col:
                        Index = random.randint(0, 5)
                        Col = ColourOps[Index]
                        Board[i][j] = Jar.Sweet(Col, i, j, Board)
    Board[i][j] = Jar.ColourBomb("D", i, j, Board)
    Board[i - 1][j] = Jar.Striped("R", i - 1, j, Board, "H")
    Board[i - 2][j] = Jar.Wrapped("B", i - 2, j, Board)
def SortMatchReaction(ListOfMatch, Board):
    StripedMatch = False
    CBMatch = False
    WrappedReact = False
    NumAfterCB = 0
    ToDestr = []  #only used for the colourbomb sweets to be destroyed
    NumOfMatched = len(ListOfMatch)

    for sweet in ListOfMatch:  #From the matched sweets- if striped/colourbomb is one of the matched
        if sweet.getStriped():
            #run matched stripe function
            StripeReaction(sweet)
            StripedMatch = True
        if sweet.getCB():
            CBMatch = True
        if sweet.getWrapped():
            WrappedReact = True
            WrappedReaction(sweet)

    if CBMatch:
        NumAfterCB, ToDestr = CBReaction(P1, P2, ToDestr)

    if NumOfMatched == 2 and StripedMatch and not CBMatch:  #Two Striped Swap
        StripeReaction(ListOfMatch[0])
        StripeReaction(ListOfMatch[1])

    if NumOfMatched == 2 and StripedMatch and CBMatch:  #Swapped Striped with colourB
        CBandStripedReaction(ToDestr, True)

    if NumOfMatched == 5:  #Creates COLOURbOMB if 5 sweets matched
        #added to try and fix background drops of stripes and CBs not happening
        DropX, DropY = ListOfMatch[0].getBoard()

        print("Leave a colourbomb here!!")
        Board[DropX][DropY] = Jar.ColourBomb("D", DropX, DropY, Board)

    if NumOfMatched == 4:
        #added to try and fix background drops of stripes and CBs not happening
        DropX, DropY = ListOfMatch[0].getBoard()

        print("Leaving a striped sweet here!")

        #need to determine whether horiz or vert

        Board[DropX][DropY] = Jar.Striped(Colour, DropX, DropY, Board,
                                          Direction)
        NewStrSwe = Board[DropX][DropY]
        print("COLOUR AND COORDS: ", NewStrSwe.getColour(),
              NewStrSwe.getBoard())

    #MatchFound = True
    #while MatchFound:
    """
    Check = WholeBoardMatch(Board)      
    
    if Check[0]:
        Board = Check[1]
        ExtraMatched = Check[2]
        print(ExtraMatched)
        for sweet in ExtraMatched:
            sweet.smallImg()
            
        print("             Match found elsewhere")
        #MatchFound = Check[0]                        
        
    #Board = PopMatchedSweet(Board)"""
    #StripedMatch, CBMatch, NumAfterCB
    return StripedMatch, CBMatch, NumAfterCB  #REturn if ColourBomb Macth for points