def newThreat(self): """ add a new threat in panel """ self.isFull() if self.Full: # prevent deadlock while if panel full print("WARNING: Attempt New Threat While Panel Full") return #vRandScore = random.randrange(1, 3) vRandScore = random.randrange(VG.ParBrickNewMin, VG.ParBrickNewMax) vRandi = random.randrange(0, self.x) vRandj = random.randrange(0, self.y) while self.Tab2Play[vRandi][vRandj] != 0: #while Tab2Play[vRandi][vRandj].getScore() != 0: vRandScore = random.randrange(VG.ParBrickNewMin, VG.ParBrickNewMax) vRandi = random.randrange(0, self.x) vRandj = random.randrange(0, self.y) self.Tab2Play[vRandi][vRandj] = vRandScore threat1 = threat(image=self.Tab2Play[vRandi][vRandj], x=vRandi, y=vRandj, score=self.Tab2Play[vRandi][vRandj]) self.Tab2PlayThreat[vRandi][vRandj] = threat1
def update(self, fenetre): # used for (sprite.Group).update """ display all Tab2Play panel within fenetre """ self.maxTile = self.checkMaxTile() #print ("maxTile: %s" %(self.maxTile) ) if self.maxTile < 10: #1024: VG.bckGnd = VG.bckGnd0000 elif self.maxTile < 11: #2048: VG.bckGnd = VG.bckGnd1024 elif self.maxTile < 12: #4096: VG.bckGnd = VG.bckGnd2048 elif self.maxTile < 13: #8192: VG.bckGnd = VG.bckGnd4096 else: VG.bckGnd = VG.bckGnd8192 fenetre.blit(VG.bckGnd, (0, 0)) for i in range(0, self.x): for j in range(0, self.y): threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) self.Tab2PlayThreat[i][j] = threat1 fenetre.blit(threat1.getImage(), (threat1.getRectX(), threat1.getRectY())) #fenetre.blit( threat1.getImage(), (i*90, j*90) ) self.updateTexts(fenetre)
def update(self, fenetre): # used for (sprite.Group).update """ display all Tab2Play panel within fenetre """ self.maxTile = self.checkMaxTile() #print ("maxTile: %s" %(self.maxTile) ) if self.maxTile <10: #1024: VG.bckGnd = VG.bckGnd0000 elif self.maxTile <11: #2048: VG.bckGnd = VG.bckGnd1024 elif self.maxTile <12: #4096: VG.bckGnd = VG.bckGnd2048 elif self.maxTile <13: #8192: VG.bckGnd = VG.bckGnd4096 else: VG.bckGnd = VG.bckGnd8192 fenetre.blit(VG.bckGnd,(0,0)) for i in range(0,self.x): for j in range(0,self.y): threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) self.Tab2PlayThreat[i][j] = threat1 fenetre.blit( threat1.getImage(), (threat1.getRectX(), threat1.getRectY()) ) #fenetre.blit( threat1.getImage(), (i*90, j*90) ) self.updateTexts(fenetre)
def __init__(self, x=VG.ParColumns, y=VG.ParRaws): if x < 3: x = 3 if y < 3: y = 3 self.x = x # ParColumns self.y = y # ParRaws #self.Tab2Play = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0] ] self.Tab2Play = [] self.Tab2PlayThreat = [] self.Tab2PlayCanAdd = [] self.Tab2PlayIsMoving = [] self.Tab2PlayDisplayMoving = [] for i in range(0, self.x): self.Tab2Play.append([]) self.Tab2PlayThreat.append([]) self.Tab2PlayCanAdd.append([]) self.Tab2PlayIsMoving.append([]) for j in range(0, self.y): self.Tab2Play[i].append(0) self.Tab2PlayThreat[i].append( threat(image=0, x=i, y=j, score=0)) self.Tab2PlayCanAdd.append(True) self.Tab2PlayIsMoving.append(0) #test #self.Tab2Play = [[2, 4, 6, 8], [0, 12, 11, 13], [1, 3, 9, 5], [9, 1, 2, 9] ] self.howFree = 0 self.Full = False self.hasMoved = False self.score = 0 self.maxTile = 0 self.nbMove = 0 self.scoreP2 = 0 self.whoP1P2 = 1 self.howPlayer = 1 self.player2Human = True
def __init__(self, x=VG.ParColumns, y=VG.ParRaws): if x<3: x=3 if y<3: y=3 self.x = x # ParColumns self.y = y # ParRaws #self.Tab2Play = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0] ] self.Tab2Play = [] self.Tab2PlayThreat = [] self.Tab2PlayCanAdd = [] self.Tab2PlayIsMoving = [] self.Tab2PlayDisplayMoving = [] for i in range(0, self.x): self.Tab2Play.append([]) self.Tab2PlayThreat.append([]) self.Tab2PlayCanAdd.append([]) self.Tab2PlayIsMoving.append([]) for j in range(0, self.y): self.Tab2Play[i].append(0) self.Tab2PlayThreat[i].append( threat( image=0, x=i, y=j, score=0 ) ) self.Tab2PlayCanAdd.append(True) self.Tab2PlayIsMoving.append(0) #test #self.Tab2Play = [[2, 4, 6, 8], [0, 12, 11, 13], [1, 3, 9, 5], [9, 1, 2, 9] ] self.howFree = 0 self.Full = False self.hasMoved = False self.score = 0 self.maxTile = 0 self.nbMove = 0 self.scoreP2 = 0 self.whoP1P2 = 1 self.howPlayer = 1 self.player2Human = True
def newThreat(self): """ add a new threat in panel """ self.isFull() if self.Full: # prevent deadlock while if panel full print ("WARNING: Attempt New Threat While Panel Full") return #vRandScore = random.randrange(1, 3) vRandScore = random.randrange(VG.ParBrickNewMin, VG.ParBrickNewMax) vRandi = random.randrange(0, self.x) vRandj = random.randrange(0, self.y) while self.Tab2Play[vRandi][vRandj] != 0: #while Tab2Play[vRandi][vRandj].getScore() != 0: vRandScore = random.randrange(VG.ParBrickNewMin, VG.ParBrickNewMax) vRandi = random.randrange(0, self.x) vRandj = random.randrange(0, self.y) self.Tab2Play[vRandi][vRandj] = vRandScore threat1 = threat(image=self.Tab2Play[vRandi][vRandj], x=vRandi, y=vRandj, score=self.Tab2Play[vRandi][vRandj]) self.Tab2PlayThreat[vRandi][vRandj] = threat1
def newGame(self, x=VG.ParColumns, y=VG.ParRaws): if x < 3: x = 3 if y < 3: y = 3 self.x = x # ParColumns self.y = y # ParRaws self.Tab2Play = [] self.Tab2PlayThreat = [] self.Tab2PlayCanAdd = [] self.Tab2PlayIsMoving = [] self.Tab2PlayDisplayMoving = [] for i in range(0, self.x): self.Tab2Play.append([]) self.Tab2PlayThreat.append([]) self.Tab2PlayCanAdd.append([]) self.Tab2PlayIsMoving.append([]) for j in range(0, self.y): self.Tab2Play[i].append(0) self.Tab2PlayThreat[i].append( threat(image=0, x=i, y=j, score=0)) self.Tab2PlayCanAdd.append(True) self.Tab2PlayIsMoving.append(0) self.howFree = 0 self.Full = False self.hasMoved = False self.score = 0 self.maxTile = 0 self.nbMove = 0 self.scoreP2 = 0 self.whoP1P2 = 1
def newGame(self, x=VG.ParColumns, y=VG.ParRaws): if x<3: x=3 if y<3: y=3 self.x = x # ParColumns self.y = y # ParRaws self.Tab2Play = [] self.Tab2PlayThreat = [] self.Tab2PlayCanAdd = [] self.Tab2PlayIsMoving = [] self.Tab2PlayDisplayMoving = [] for i in range(0, self.x): self.Tab2Play.append([]) self.Tab2PlayThreat.append([]) self.Tab2PlayCanAdd.append([]) self.Tab2PlayIsMoving.append([]) for j in range(0, self.y): self.Tab2Play[i].append(0) self.Tab2PlayThreat[i].append( threat( image=0, x=i, y=j, score=0 ) ) self.Tab2PlayCanAdd.append(True) self.Tab2PlayIsMoving.append(0) self.howFree = 0 self.Full = False self.hasMoved = False self.score = 0 self.maxTile = 0 self.nbMove = 0 self.scoreP2 = 0 self.whoP1P2 = 1
def loadGame(self): """ Load Game Panel At StartUp """ print("AutoLoad SavedGame.json ...") try: with open("SavedGame.json", "rt") as infile: print("AutoLoad temp ...") temp = json.load(infile) self.Tab2Play = temp[0] print("AutoLoad Tab2Play=%s ..." % (self.Tab2Play)) #self.Tab2PlayThreat = json.load(infile) self.Tab2PlayCanAdd = temp[1] print("AutoLoad Tab2PlayCanAdd=%s ..." % (self.Tab2PlayCanAdd)) self.Tab2PlayIsMoving = temp[2] print("AutoLoad Tab2PlayIsMoving=%s ..." % (self.Tab2PlayIsMoving)) self.Tab2PlayDisplayMoving = temp[3] print("AutoLoad Tab2PlayDisplayMoving=%s ..." % (self.Tab2PlayDisplayMoving)) self.x = temp[4] self.y = temp[5] print("AutoLoad x=%s, y=%s ..." % (self.x, self.y)) self.howFree = temp[6] self.Full = temp[7] self.hasMoved = temp[8] self.score = temp[9] self.nbMove = temp[10] self.scoreP2 = temp[11] self.whoP1P2 = temp[12] self.howPlayer = temp[13] self.player2Human = temp[14] print( "AutoLoad howFree=%s, Full=%s, hasMoved=%s, score=%s ..." % (self.howFree, self.Full, self.hasMoved, self.score)) print("rebuild Tab2PlayThreat ...") self.Tab2PlayThreat = [] for i in range(0, self.x): self.Tab2PlayThreat.append([]) for j in range(0, self.y): self.Tab2PlayThreat[i].append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j])) except: print("WARNING: unable to load SavedGame.json") # reinit panel self.x = VG.ParColumns # ParColumns self.y = VG.ParRaws # ParRaws self.Tab2Play = [] self.Tab2PlayThreat = [] self.Tab2PlayCanAdd = [] self.Tab2PlayIsMoving = [] self.Tab2PlayDisplayMoving = [] for i in range(0, self.x): self.Tab2Play.append([]) self.Tab2PlayThreat.append([]) self.Tab2PlayCanAdd.append([]) self.Tab2PlayIsMoving.append([]) for j in range(0, self.y): self.Tab2Play[i].append(0) self.Tab2PlayThreat[i].append( threat(image=0, x=i, y=j, score=0)) self.Tab2PlayCanAdd.append(True) self.Tab2PlayIsMoving.append(0) #test #self.Tab2Play = [[2, 4, 6, 8], [0, 12, 11, 13], [1, 3, 9, 5], [9, 1, 2, 9] ] self.howFree = 0 self.Full = False self.hasMoved = False self.score = 0 self.scoreP2 = 0 self.whoP1P2 = 1 self.howPlayer = 1 self.player2Human = True self.newThreat() self.newThreat()
def updateMoving(self, fenetre): # used for (sprite.Group).update """ display Tab2Play panel within fenetre """ # increase speed moving to avoid anoying when large panel speedMove = 10 # speedMove sould be 90 multiple if VG.ParSizeActu == 2: speedMove = 15 clock = pygame.time.Clock() threat0 = threat(image=0, x=0, y=0, score=0) #TODO: movement sould be one complete movement (otherwise too long) #self.Tab2PlayDisplayMoving = [] hasMoved2Left = False hasMoved2Right = False hasMoved2Up = False hasMoved2Down = False for i in range(0, self.x): for j in range(0, self.y): if self.Tab2PlayIsMoving[i][j] == 1: hasMoved2Left = True self.hasMoved = True self.Tab2PlayIsMoving[i][j] = 0 if self.Tab2PlayIsMoving[i][j] == 2: hasMoved2Right = True self.hasMoved = True self.Tab2PlayIsMoving[i][j] = 0 if self.Tab2PlayIsMoving[i][j] == 3: hasMoved2Up = True self.hasMoved = True self.Tab2PlayIsMoving[i][j] = 0 if self.Tab2PlayIsMoving[i][j] == 4: hasMoved2Down = True self.hasMoved = True self.Tab2PlayIsMoving[i][j] = 0 if hasMoved2Left: #Left #for f in range (0, 90 + 10, 10): for f in range(0, 90 + speedMove, speedMove): for it in self.Tab2PlayDisplayMoving: #threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) fenetre.blit(VG.bckGnd, (it.getRectX(), it.getRectY()), it.getRect()) fenetre.blit(threat0.getImage(), (it.getRectX(), it.getRectY())) fenetre.blit(it.getImage(), (it.getRectX() - f, it.getRectY())) clock.tick(VG.ParFPS) pygame.display.flip() if hasMoved2Right: #Right #for f in range (0, 90 + 10, 10): for f in range(0, 90 + speedMove, speedMove): for it in self.Tab2PlayDisplayMoving: #threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) fenetre.blit(VG.bckGnd, (it.getRectX(), it.getRectY()), it.getRect()) fenetre.blit(threat0.getImage(), (it.getRectX(), it.getRectY())) fenetre.blit(it.getImage(), (it.getRectX() + f, it.getRectY())) clock.tick(VG.ParFPS) pygame.display.flip() if hasMoved2Up: #Up #for f in range (0, 90 + 10, 10 + speedMove): for f in range(0, 90 + speedMove, speedMove): for it in self.Tab2PlayDisplayMoving: #threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) fenetre.blit(VG.bckGnd, (it.getRectX(), it.getRectY()), it.getRect()) fenetre.blit(threat0.getImage(), (it.getRectX(), it.getRectY())) fenetre.blit(it.getImage(), (it.getRectX(), it.getRectY() - f)) clock.tick(VG.ParFPS) pygame.display.flip() if hasMoved2Down: #Down #for f in range (0, 90 + 10, 10): for f in range(0, 90 + speedMove, speedMove): for it in self.Tab2PlayDisplayMoving: #threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) fenetre.blit(VG.bckGnd, (it.getRectX(), it.getRectY()), it.getRect()) fenetre.blit(threat0.getImage(), (it.getRectX(), it.getRectY())) fenetre.blit(it.getImage(), (it.getRectX(), it.getRectY() + f)) clock.tick(VG.ParFPS) pygame.display.flip()
def move(self, fenetre, sens="left"): """ shift panel from point to new position point left, right, up, down """ #self.Tab2Play = [x0[y0, y1, y2, y3], x1[y0, y1, y2, y3], x2[y0, y1, y2, y3], x3[y0, y1, y2, y3] ] self.Tab2PlayDisplayMoving = [] isMoving = False #stopMoving = [False, False, False, False] #prevent if other raw/column need to continu move if sens == "left": for i in range(1, self.x): for j in range(0, self.y): if (self.Tab2Play[i][j] != 0): #something #print ("found %s @ x=%s, y=%s)" %(self.Tab2Play[i][j], i, j) ) if (self.Tab2Play[i - 1][j] == 0 ): #empty => switch to left print("switch to left x=%s, y=%s, sc=%s" % (i, j, self.Tab2Play[i][j])) self.Tab2PlayIsMoving[i][j] = 1 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j])) #self.updateMoving(fenetre) self.Tab2Play[i - 1][j] = self.Tab2Play[i][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[ i - 1][j] = self.Tab2PlayCanAdd[i][j] self.Tab2PlayCanAdd[i][j] = True isMoving = True elif (self.Tab2Play[i - 1][j] == self.Tab2Play[i][j] ): #same value => add onto one threat if (self.Tab2PlayCanAdd[i][j]) and ( self.Tab2PlayCanAdd[i - 1][j]): print("ADD2LEFT x=%s, y=%s, sc=%s" % (i, j, self.Tab2Play[i][j])) self.Tab2PlayIsMoving[i][j] = 1 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j])) #self.updateMoving(fenetre) self.Tab2Play[i - 1][j] += 1 if self.Tab2Play[i - 1][j] > VG.ParBrickMaxValue: self.Tab2Play[i - 1][j] = VG.ParBrickMaxValue if self.whoP1P2 == 1: self.score += 2**self.Tab2Play[i - 1][j] else: self.scoreP2 += 2**self.Tab2Play[i - 1][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i - 1][j] = False self.Tab2PlayCanAdd[i][j] = True isMoving = True if VG.ParMusicYN: S_Bomb1.play() if sens == "right": for i in range(self.x - 2, -1, -1): for j in range(0, self.y): if (self.Tab2Play[i][j] != 0): #something #print ("found %s @ x=%s, y=%s)" %(self.Tab2Play[i][j], i, j) ) if (self.Tab2Play[i + 1][j] == 0 ): #empty => switch to left print("switch to right x=%s, y=%s, sc=%s" % (i, j, self.Tab2Play[i][j])) self.Tab2PlayIsMoving[i][j] = 2 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j])) #self.updateMoving(fenetre) self.Tab2Play[i + 1][j] = self.Tab2Play[i][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[ i + 1][j] = self.Tab2PlayCanAdd[i][j] self.Tab2PlayCanAdd[i][j] = True isMoving = True elif (self.Tab2Play[i + 1][j] == self.Tab2Play[i][j] ): #same value => add onto one threat if (self.Tab2PlayCanAdd[i][j]) and ( self.Tab2PlayCanAdd[i + 1][j]): print("ADD2RIGHT x=%s, y=%s, sc=%s" % (i, j, self.Tab2Play[i][j])) self.Tab2PlayIsMoving[i][j] = 2 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j])) #self.updateMoving(fenetre) self.Tab2Play[i + 1][j] += 1 if self.Tab2Play[i + 1][j] > VG.ParBrickMaxValue: self.Tab2Play[i + 1][j] = VG.ParBrickMaxValue #self.score += 2**self.Tab2Play[i+1][j] if self.whoP1P2 == 1: self.score += 2**self.Tab2Play[i + 1][j] else: self.scoreP2 += 2**self.Tab2Play[i + 1][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i + 1][j] = False self.Tab2PlayCanAdd[i][j] = True isMoving = True if VG.ParMusicYN: S_Bomb1.play() if sens == "up": for i in range(0, self.x): for j in range(1, self.y): if (self.Tab2Play[i][j] != 0): #something #print ("found %s @ x=%s, y=%s)" %(self.Tab2Play[i][j], i, j) ) if (self.Tab2Play[i][j - 1] == 0 ): #empty => switch to left print("switch to up x=%s, y=%s, sc=%s" % (i, j, self.Tab2Play[i][j])) self.Tab2PlayIsMoving[i][j] = 3 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j])) #self.updateMoving(fenetre) self.Tab2Play[i][j - 1] = self.Tab2Play[i][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i][ j - 1] = self.Tab2PlayCanAdd[i][j] self.Tab2PlayCanAdd[i][j] = True isMoving = True elif (self.Tab2Play[i][j - 1] == self.Tab2Play[i][j] ): #same value => add onto one threat if (self.Tab2PlayCanAdd[i][j]) and ( self.Tab2PlayCanAdd[i][j - 1]): print("ADD2UP x=%s, y=%s, sc=%s" % (i, j, self.Tab2Play[i][j])) self.Tab2PlayIsMoving[i][j] = 3 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j])) #self.updateMoving(fenetre) self.Tab2Play[i][j - 1] += 1 if self.Tab2Play[i][j - 1] > VG.ParBrickMaxValue: self.Tab2Play[i][j - 1] = VG.ParBrickMaxValue #self.score += 2**self.Tab2Play[i][j-1] if self.whoP1P2 == 1: self.score += 2**self.Tab2Play[i][j - 1] else: self.scoreP2 += 2**self.Tab2Play[i][j - 1] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i][j - 1] = False self.Tab2PlayCanAdd[i][j] = True isMoving = True if VG.ParMusicYN: S_Bomb1.play() if sens == "down": for i in range(0, self.x): for j in range(self.y - 2, -1, -1): if (self.Tab2Play[i][j] != 0): #something #print ("found %s @ x=%s, y=%s)" %(self.Tab2Play[i][j], i, j) ) if (self.Tab2Play[i][j + 1] == 0 ): #empty => switch to left print("switch to right x=%s, y=%s, sc=%s" % (i, j, self.Tab2Play[i][j])) self.Tab2PlayIsMoving[i][j] = 4 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j])) #self.updateMoving(fenetre) self.Tab2Play[i][j + 1] = self.Tab2Play[i][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i][ j + 1] = self.Tab2PlayCanAdd[i][j] self.Tab2PlayCanAdd[i][j] = True isMoving = True elif (self.Tab2Play[i][j + 1] == self.Tab2Play[i][j] ): #same value => add onto one threat if (self.Tab2PlayCanAdd[i][j]) and ( self.Tab2PlayCanAdd[i][j + 1]): print("ADD2DOWN x=%s, y=%s, sc=%s" % (i, j, self.Tab2Play[i][j])) self.Tab2PlayIsMoving[i][j] = 4 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j])) #self.updateMoving(fenetre) self.Tab2Play[i][j + 1] += 1 if self.Tab2Play[i][j + 1] > VG.ParBrickMaxValue: self.Tab2Play[i][j + 1] = VG.ParBrickMaxValue #self.score += 2**self.Tab2Play[i][j+1] if self.whoP1P2 == 1: self.score += 2**self.Tab2Play[i][j + 1] else: self.scoreP2 += 2**self.Tab2Play[i][j + 1] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i][j + 1] = False self.Tab2PlayCanAdd[i][j] = True isMoving = True if VG.ParMusicYN: S_Bomb1.play() print(self.Tab2PlayCanAdd) return isMoving
def loadGame(self): """ Load Game Panel At StartUp """ print ("AutoLoad SavedGame.json ...") try: with open("SavedGame.json", "rt") as infile: print ("AutoLoad temp ...") temp = json.load(infile) self.Tab2Play = temp[0] print ("AutoLoad Tab2Play=%s ..." %(self.Tab2Play) ) #self.Tab2PlayThreat = json.load(infile) self.Tab2PlayCanAdd = temp[1] print ("AutoLoad Tab2PlayCanAdd=%s ..." %(self.Tab2PlayCanAdd) ) self.Tab2PlayIsMoving = temp[2] print ("AutoLoad Tab2PlayIsMoving=%s ..." %(self.Tab2PlayIsMoving) ) self.Tab2PlayDisplayMoving = temp[3] print ("AutoLoad Tab2PlayDisplayMoving=%s ..." %(self.Tab2PlayDisplayMoving) ) self.x = temp[4] self.y = temp[5] print ("AutoLoad x=%s, y=%s ..." %(self.x, self.y) ) self.howFree = temp[6] self.Full = temp[7] self.hasMoved = temp[8] self.score = temp[9] self.nbMove = temp[10] self.scoreP2 = temp[11] self.whoP1P2 = temp[12] self.howPlayer = temp[13] self.player2Human = temp[14] print ("AutoLoad howFree=%s, Full=%s, hasMoved=%s, score=%s ..." %(self.howFree, self.Full, self.hasMoved, self.score) ) print ("rebuild Tab2PlayThreat ...") self.Tab2PlayThreat = [] for i in range(0, self.x): self.Tab2PlayThreat.append([]) for j in range(0, self.y): self.Tab2PlayThreat[i].append( threat( image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j] ) ) except: print ("WARNING: unable to load SavedGame.json") # reinit panel self.x = VG.ParColumns # ParColumns self.y = VG.ParRaws # ParRaws self.Tab2Play = [] self.Tab2PlayThreat = [] self.Tab2PlayCanAdd = [] self.Tab2PlayIsMoving = [] self.Tab2PlayDisplayMoving = [] for i in range(0, self.x): self.Tab2Play.append([]) self.Tab2PlayThreat.append([]) self.Tab2PlayCanAdd.append([]) self.Tab2PlayIsMoving.append([]) for j in range(0, self.y): self.Tab2Play[i].append(0) self.Tab2PlayThreat[i].append( threat( image=0, x=i, y=j, score=0 ) ) self.Tab2PlayCanAdd.append(True) self.Tab2PlayIsMoving.append(0) #test #self.Tab2Play = [[2, 4, 6, 8], [0, 12, 11, 13], [1, 3, 9, 5], [9, 1, 2, 9] ] self.howFree = 0 self.Full = False self.hasMoved = False self.score = 0 self.scoreP2 = 0 self.whoP1P2 = 1 self.howPlayer = 1 self.player2Human = True self.newThreat() self.newThreat()
def updateMoving(self, fenetre): # used for (sprite.Group).update """ display Tab2Play panel within fenetre """ # increase speed moving to avoid anoying when large panel speedMove = 10 # speedMove sould be 90 multiple if VG.ParSizeActu == 2: speedMove = 15 clock = pygame.time.Clock() threat0 = threat(image=0, x=0, y=0, score=0) #TODO: movement sould be one complete movement (otherwise too long) #self.Tab2PlayDisplayMoving = [] hasMoved2Left = False hasMoved2Right = False hasMoved2Up = False hasMoved2Down = False for i in range(0,self.x): for j in range(0,self.y): if self.Tab2PlayIsMoving[i][j] == 1: hasMoved2Left = True self.hasMoved = True self.Tab2PlayIsMoving[i][j] = 0 if self.Tab2PlayIsMoving[i][j] == 2: hasMoved2Right = True self.hasMoved = True self.Tab2PlayIsMoving[i][j] = 0 if self.Tab2PlayIsMoving[i][j] == 3: hasMoved2Up = True self.hasMoved = True self.Tab2PlayIsMoving[i][j] = 0 if self.Tab2PlayIsMoving[i][j] == 4: hasMoved2Down = True self.hasMoved = True self.Tab2PlayIsMoving[i][j] = 0 if hasMoved2Left: #Left #for f in range (0, 90 + 10, 10): for f in range (0, 90 + speedMove, speedMove): for it in self.Tab2PlayDisplayMoving: #threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) fenetre.blit( VG.bckGnd, (it.getRectX(), it.getRectY()) , it.getRect() ) fenetre.blit( threat0.getImage(), (it.getRectX(), it.getRectY()) ) fenetre.blit( it.getImage(), (it.getRectX() - f, it.getRectY()) ) clock.tick(VG.ParFPS) pygame.display.flip() if hasMoved2Right: #Right #for f in range (0, 90 + 10, 10): for f in range (0, 90 + speedMove, speedMove): for it in self.Tab2PlayDisplayMoving: #threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) fenetre.blit( VG.bckGnd, (it.getRectX(), it.getRectY()) , it.getRect() ) fenetre.blit( threat0.getImage(), (it.getRectX(), it.getRectY()) ) fenetre.blit( it.getImage(), (it.getRectX() + f, it.getRectY()) ) clock.tick(VG.ParFPS) pygame.display.flip() if hasMoved2Up: #Up #for f in range (0, 90 + 10, 10 + speedMove): for f in range (0, 90 + speedMove, speedMove): for it in self.Tab2PlayDisplayMoving: #threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) fenetre.blit( VG.bckGnd, (it.getRectX(), it.getRectY()) , it.getRect() ) fenetre.blit( threat0.getImage(), (it.getRectX(), it.getRectY()) ) fenetre.blit( it.getImage(), (it.getRectX(), it.getRectY() - f) ) clock.tick(VG.ParFPS) pygame.display.flip() if hasMoved2Down: #Down #for f in range (0, 90 + 10, 10): for f in range (0, 90 + speedMove, speedMove): for it in self.Tab2PlayDisplayMoving: #threat1 = threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) fenetre.blit( VG.bckGnd, (it.getRectX(), it.getRectY()) , it.getRect() ) fenetre.blit( threat0.getImage(), (it.getRectX(), it.getRectY()) ) fenetre.blit( it.getImage(), (it.getRectX(), it.getRectY() + f) ) clock.tick(VG.ParFPS) pygame.display.flip()
def move(self, fenetre, sens="left"): """ shift panel from point to new position point left, right, up, down """ #self.Tab2Play = [x0[y0, y1, y2, y3], x1[y0, y1, y2, y3], x2[y0, y1, y2, y3], x3[y0, y1, y2, y3] ] self.Tab2PlayDisplayMoving = [] isMoving = False #stopMoving = [False, False, False, False] #prevent if other raw/column need to continu move if sens == "left": for i in range(1,self.x): for j in range(0,self.y): if (self.Tab2Play[i][j] != 0): #something #print ("found %s @ x=%s, y=%s)" %(self.Tab2Play[i][j], i, j) ) if (self.Tab2Play[i-1][j] == 0): #empty => switch to left print ("switch to left x=%s, y=%s, sc=%s" %( i, j, self.Tab2Play[i][j]) ) self.Tab2PlayIsMoving[i][j] = 1 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) ) #self.updateMoving(fenetre) self.Tab2Play[i-1][j] = self.Tab2Play[i][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i-1][j] = self.Tab2PlayCanAdd[i][j] self.Tab2PlayCanAdd[i][j] = True isMoving = True elif (self.Tab2Play[i-1][j] == self.Tab2Play[i][j]): #same value => add onto one threat if (self.Tab2PlayCanAdd[i][j]) and (self.Tab2PlayCanAdd[i-1][j]): print ("ADD2LEFT x=%s, y=%s, sc=%s" %( i, j, self.Tab2Play[i][j]) ) self.Tab2PlayIsMoving[i][j] = 1 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) ) #self.updateMoving(fenetre) self.Tab2Play[i-1][j] += 1 if self.Tab2Play[i-1][j] > VG.ParBrickMaxValue: self.Tab2Play[i-1][j] = VG.ParBrickMaxValue if self.whoP1P2 == 1: self.score += 2**self.Tab2Play[i-1][j] else: self.scoreP2 += 2**self.Tab2Play[i-1][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i-1][j] = False self.Tab2PlayCanAdd[i][j] = True isMoving = True if VG.ParMusicYN: S_Bomb1.play() if sens == "right": for i in range(self.x - 2, -1, -1): for j in range(0,self.y): if (self.Tab2Play[i][j] != 0): #something #print ("found %s @ x=%s, y=%s)" %(self.Tab2Play[i][j], i, j) ) if (self.Tab2Play[i+1][j] == 0): #empty => switch to left print ("switch to right x=%s, y=%s, sc=%s" %( i, j, self.Tab2Play[i][j]) ) self.Tab2PlayIsMoving[i][j] = 2 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) ) #self.updateMoving(fenetre) self.Tab2Play[i+1][j] = self.Tab2Play[i][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i+1][j] = self.Tab2PlayCanAdd[i][j] self.Tab2PlayCanAdd[i][j] = True isMoving = True elif (self.Tab2Play[i+1][j] == self.Tab2Play[i][j]): #same value => add onto one threat if (self.Tab2PlayCanAdd[i][j]) and (self.Tab2PlayCanAdd[i+1][j]): print ("ADD2RIGHT x=%s, y=%s, sc=%s" %( i, j, self.Tab2Play[i][j]) ) self.Tab2PlayIsMoving[i][j] = 2 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) ) #self.updateMoving(fenetre) self.Tab2Play[i+1][j] += 1 if self.Tab2Play[i+1][j] > VG.ParBrickMaxValue: self.Tab2Play[i+1][j] = VG.ParBrickMaxValue #self.score += 2**self.Tab2Play[i+1][j] if self.whoP1P2 == 1: self.score += 2**self.Tab2Play[i+1][j] else: self.scoreP2 += 2**self.Tab2Play[i+1][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i+1][j] = False self.Tab2PlayCanAdd[i][j] = True isMoving = True if VG.ParMusicYN: S_Bomb1.play() if sens == "up": for i in range(0,self.x): for j in range(1,self.y): if (self.Tab2Play[i][j] != 0): #something #print ("found %s @ x=%s, y=%s)" %(self.Tab2Play[i][j], i, j) ) if (self.Tab2Play[i][j-1] == 0): #empty => switch to left print ("switch to up x=%s, y=%s, sc=%s" %( i, j, self.Tab2Play[i][j]) ) self.Tab2PlayIsMoving[i][j] = 3 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) ) #self.updateMoving(fenetre) self.Tab2Play[i][j-1] = self.Tab2Play[i][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i][j-1] = self.Tab2PlayCanAdd[i][j] self.Tab2PlayCanAdd[i][j] = True isMoving = True elif (self.Tab2Play[i][j-1] == self.Tab2Play[i][j]): #same value => add onto one threat if (self.Tab2PlayCanAdd[i][j]) and (self.Tab2PlayCanAdd[i][j-1]): print ("ADD2UP x=%s, y=%s, sc=%s" %( i, j, self.Tab2Play[i][j]) ) self.Tab2PlayIsMoving[i][j] = 3 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) ) #self.updateMoving(fenetre) self.Tab2Play[i][j-1] += 1 if self.Tab2Play[i][j-1] > VG.ParBrickMaxValue: self.Tab2Play[i][j-1] = VG.ParBrickMaxValue #self.score += 2**self.Tab2Play[i][j-1] if self.whoP1P2 == 1: self.score += 2**self.Tab2Play[i][j-1] else: self.scoreP2 += 2**self.Tab2Play[i][j-1] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i][j-1] = False self.Tab2PlayCanAdd[i][j] = True isMoving = True if VG.ParMusicYN: S_Bomb1.play() if sens == "down": for i in range(0,self.x): for j in range(self.y - 2, -1, -1): if (self.Tab2Play[i][j] != 0): #something #print ("found %s @ x=%s, y=%s)" %(self.Tab2Play[i][j], i, j) ) if (self.Tab2Play[i][j+1] == 0): #empty => switch to left print ("switch to right x=%s, y=%s, sc=%s" %( i, j, self.Tab2Play[i][j]) ) self.Tab2PlayIsMoving[i][j] = 4 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) ) #self.updateMoving(fenetre) self.Tab2Play[i][j+1] = self.Tab2Play[i][j] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i][j+1] = self.Tab2PlayCanAdd[i][j] self.Tab2PlayCanAdd[i][j] = True isMoving = True elif (self.Tab2Play[i][j+1] == self.Tab2Play[i][j]): #same value => add onto one threat if (self.Tab2PlayCanAdd[i][j]) and (self.Tab2PlayCanAdd[i][j+1]): print ("ADD2DOWN x=%s, y=%s, sc=%s" %( i, j, self.Tab2Play[i][j]) ) self.Tab2PlayIsMoving[i][j] = 4 self.Tab2PlayDisplayMoving.append( threat(image=self.Tab2Play[i][j], x=i, y=j, score=self.Tab2Play[i][j]) ) #self.updateMoving(fenetre) self.Tab2Play[i][j+1] += 1 if self.Tab2Play[i][j+1] > VG.ParBrickMaxValue: self.Tab2Play[i][j+1] = VG.ParBrickMaxValue #self.score += 2**self.Tab2Play[i][j+1] if self.whoP1P2 == 1: self.score += 2**self.Tab2Play[i][j+1] else: self.scoreP2 += 2**self.Tab2Play[i][j+1] self.Tab2Play[i][j] = 0 self.Tab2PlayCanAdd[i][j+1] = False self.Tab2PlayCanAdd[i][j] = True isMoving = True if VG.ParMusicYN: S_Bomb1.play() print (self.Tab2PlayCanAdd) return isMoving