class TypePartieScene(Scene): ''' Une scene pour le chargement des données ''' def __init__(self, l): ''' Constructeur de la class LoadScene ''' self.width = pygame.display.get_surface().get_width() self.height = pygame.display.get_surface().get_height() self.loader = l l.clearAnimation() l.addAnimationByPath('bg', '../img/background.jpg', level=0) l.addAnimationByPath('normal', '../img/normal.png', self.width / 2 - 140, 100, level=1) l.addAnimationByPath('union', '../img/union.png', self.width / 2 - 140, 100, level=1) l.addAnimationByPath('back', '../img/back.png', self.width / 2 - 140, 100, level=1) self.createButton(l) self.resizeWindow(l, self.width, self.height) self.ReturnScene = self texts = l.getFont('mainTitle') if len(texts) > 0: sprite = Sprite(texts[0].render("Partie solo :", 1, (255, 255, 0))) animation = Animation(sprite) animation.newPos((self.width / 2 - sprite.w / 2), 30, sprite.w, sprite.h, 0) l.removeAnimation('title') l.addAnimation('title', animation) def createButton(self, l): ''' @param l: le chargeur d'image ''' normal = l.getAnimation('normal') if len(normal) > 0: normal[0].newPos(self.width / 2 - 140, 100, 280, 50, 20) self.btnNormal = Button('normal', '../img/normal.png', '../img/normal_select.png', self.normalCallBack) self.btnNormal.loadButton(self.width / 2 - 140, 100, 280, 50, self.width, self.height) union = l.getAnimation('union') if len(union) > 0: union[0].newPos(self.width / 2 - 140, 200, 280, 50, 20) self.btnUnion = Button('union', '../img/union.png', '../img/union_select.png', self.callbackButton) self.btnUnion.loadButton(self.width / 2 - 140, 200, 280, 50, self.width, self.height) back = l.getAnimation('back') if len(back) > 0: back[0].newPos(self.width / 2 - 140, 300, 280, 50, 20) self.btnBack = Button('back', '../img/back.png', '../img/back_select.png', self.retourCallBack) self.btnBack.loadButton(self.width / 2 - 140, 300, 280, 50, self.width, self.height) def callbackButton(self, nom): print('Nom : ' + nom) def normalCallBack(self, nom): from scene.GameScene import GameScene self.ReturnScene = GameScene(self.loader) def retourCallBack(self, nom): from scene.MainScene import MainScene self.ReturnScene = MainScene(self.loader) def update(self, e, l): ''' @param e: le gestionnaire d'événement @param l: le gestionnaire d'image @return: Scene à renvoyer ''' self.btnNormal.update(e, l) self.btnUnion.update(e, l) self.btnBack.update(e, l) if (e.quit): self.quitterCallBack('') return self.ReturnScene def resizeWindow(self, l, w, h): ''' Au redimensionnement de la fenêtre @param l: le chargeur de ressources @param w: la nouvelle largeur @param h: la nouvelle hauteur ''' self.width = w self.height = h backgrounds = l.getAnimation('bg') if len(backgrounds) > 0: backgrounds[0].newPos(0, 0, self.width, self.height, 0) self.btnNormal.resizeWindow(l, w, h) self.btnUnion.resizeWindow(l, w, h) self.btnBack.resizeWindow(l, w, h) animation = l.getAnimation('title') if len(animation) > 0: animation[0].newPos((self.width / 2 - animation[0].sprite.w / 2), 30, animation[0].sprite.w, animation[0].sprite.h, 0)
class GameScene(Scene): ''' Une scene pour le chargement des données ''' def __init__(self, l): ''' Constructeur de la class LoadScene ''' self.width = pygame.display.get_surface().get_width() self.height = pygame.display.get_surface().get_height() self.loader = l self.action = 0 self.actionCallBack = False self.nt = False self.tour = 1 self.pioche = Pioche() deckPlayer1 = Deck("deck1", self.pioche.getDecks("deck1")) deckPlayer2 = Deck("deck2", self.pioche.getDecks("deck2")) self.player1 = Player(1, "Egor", deckPlayer1) self.player2 = Player(2, "Quentin", deckPlayer2) self.lastAnimCard = None l.clearAnimation() l.addAnimationByPath('bg', '../img/background.jpg') l.addAnimationByPath('showCard', '../img/card/spellCard.jpg', self.width / 2 - 75, self.height / 2 - 105, level=4) l.addAnimationByPath('pioche1', '../img/card/backSpellCard.jpg', level=1) l.addAnimationByPath('pioche2', '../img/card/backSpellCard.jpg', level=1) l.addAnimationByPath('passerTourJoueur', '../img/passer.png', self.width / 2 - 140, self.height / 2 - 50, level=1) self.btnPasser = Button('passerTourJoueur', '../img/passer.png', '../img/passer_select.png', self.partieSolo) self.btnPasser.loadButton(self.width / 2 - 140, self.height / 2 - 50, 280, 50, self.width, self.height) selection = l.getAnimation('pioche1') if len(selection) > 0: selection[0].newPos(self.width - 200, self.height / 2 - 105 - 110, 75, 105, 0, None) selection = l.getAnimation('pioche2') if len(selection) > 0: selection[0].newPos(self.width - 200, self.height / 2 + 105, 75, 105, 0, None) self.levelMaxPlayer = 3 self.levelMaxEnemy = 3 self.cardPlayer = [] for i in range(5, 8): self.cardPlayer.append(CardInfo(l, self.player1.deck.getCarte(), i)) self.cardEnemy = [] for i in range(5, 8): self.cardEnemy.append(CardInfo(l, self.player2.deck.getCarte(), i)) self.resizeWindow(l, self.width, self.height) self.ReturnScene = self self.changeText(l, "INFO") def asyncAnimDeckPlayerFinal(self, anim): if not (self.lastAnimCard == None): self.actionCallBack = False self.lastAnimCard = None def asyncAnimDeckPlayer(self, anim): if not (self.lastAnimCard == None): self.lastAnimCard.setResize(self.width - 5 - (80 * len(self.cardPlayer)), self.height - 115, 75, 105, 40, self.asyncAnimDeckPlayerFinal) def animDeckPlayer(self): self.levelMaxPlayer += 1 card = CardInfo(self.loader, self.player1.deck.getCarte(), self.levelMaxPlayer) card.setResize(self.width - 163 , self.height / 2 + 152, 0, 0, 0, None) card.setResize(self.width - 200, self.height / 2 + 105, 75, 105, 20, self.asyncAnimDeckPlayer) self.cardPlayer.append(card) self.lastAnimCard = card def asyncAnimDeckEnemyFinal(self, anim): if not (self.lastAnimCard == None): self.actionCallBack = False self.lastAnimCard = None def asyncAnimDeckEnemy(self, anim): if not (self.lastAnimCard == None): self.lastAnimCard.setResize(-70 + (80 * len(self.cardPlayer)), 10, 75, 105, 40, self.asyncAnimDeckEnemyFinal) def animDeckEnemy(self): self.levelMaxPlayer += 1 card = CardInfo(self.loader, self.player2.deck.getCarte(), self.levelMaxPlayer) card.setResize(self.width - 163 , self.height / 2 - 53 - 110, 0, 0, 0, None) card.setResize(self.width - 200, self.height / 2 - 105 - 110, 75, 105, 20, self.asyncAnimDeckEnemy) self.cardEnemy.append(card) self.lastAnimCard = card def asyncChangeText(self, anim): anim.newPos((self.width / 2), (self.height / 2), 0, 0, 50, None) self.actionCallBack = False def changeText(self, l, message): texts = l.getFont('mainTitle') if len(texts) > 0: sprite = Sprite(texts[0].render(message, 1, (255, 255, 0))) animation = Animation(sprite) animation.newPos((self.width / 2 - sprite.w / 2), (self.height / 2 - sprite.h / 2) + 60, sprite.w, sprite.h, 0) animation.newPos((self.width / 2 - sprite.w / 2), (self.height / 2 - sprite.h / 2) + 60, sprite.w, sprite.h, 50, self.asyncChangeText) l.removeAnimation('info') l.addAnimation('info', animation) def partieSolo(self, e): self.nt = True def statusText(self, l): texts = l.getFont('mainTitle') # PLayer 1 ( Down ) if len(texts) > 0: sprite = Sprite(texts[0].render("VIE: " + str(self.player1.health) + "/30", 1, (255, 255, 0))) spriteBis = Sprite(texts[0].render("MANA: " + str(self.player1.mana) + "/10", 1, (255, 255, 0))) spriteTer = Sprite(texts[0].render("" + str(self.player1.name) + "", 1, (255, 255, 0))) animation = Animation(sprite) animationBis = Animation(spriteBis) animationTer = Animation(spriteTer) animation.newPos(self.width - (sprite.w / 2) - 10, (self.height / 2 - sprite.h / 2) - 10 - (sprite.h / 2), sprite.w / 2, sprite.h / 2, 0) animationBis.newPos(self.width - (sprite.w / 2) - 10, (self.height / 2 - sprite.h / 2), sprite.w / 2, sprite.h / 2, 0) animationTer.newPos(self.width - (sprite.w / 2) - 10, (self.height / 2 - sprite.h / 2) - (10 - (sprite.h / 2) * 2), sprite.w / 2, sprite.h / 2, 0) l.removeAnimation('infoVieP1') l.addAnimation('infoVieP1', animation, level=5) l.removeAnimation('infoManaP1') l.addAnimation('infoManaP1', animationBis, level=5) l.removeAnimation('infoNameP1') l.addAnimation('infoNameP1', animationTer, level=5) # PLayer 1 ( UP ) if len(texts) > 0: sprite = Sprite(texts[0].render("VIE: " + str(self.player2.health) + "/30", 1, (255, 255, 0))) spriteBis = Sprite(texts[0].render("MANA: " + str(self.player2.mana) + "/10", 1, (255, 255, 0))) spriteTer = Sprite(texts[0].render("" + str(self.player2.name) + "", 1, (255, 255, 0))) animation = Animation(sprite) animationBis = Animation(spriteBis) animationTer = Animation(spriteTer) animation.newPos(10, (self.height / 2 - sprite.h / 2) - 10 - (sprite.h / 2), sprite.w / 2, sprite.h / 2, 0) animationBis.newPos(10, (self.height / 2 - sprite.h / 2), sprite.w / 2, sprite.h / 2, 0) animationTer.newPos(10, (self.height / 2 - sprite.h / 2) - (10 - (sprite.h / 2) * 2), sprite.w / 2, sprite.h / 2, 0) l.removeAnimation('infoVieP2') l.addAnimation('infoVieP2', animation, level=5) l.removeAnimation('infoManaP2') l.addAnimation('infoManaP2', animationBis, level=5) l.removeAnimation('infoNameP2') l.addAnimation('infoNameP2', animationTer, level=5) selection = l.getAnimation('pioche1') if len(selection) > 0: selection[0].newPos(self.width - 200, self.height / 2 - 105 - 110, 75, 105, 0, None) selection = l.getAnimation('pioche2') if len(selection) > 0: selection[0].newPos(self.width - 200, self.height / 2 + 105, 75, 105, 0, None) def quitterCallBack(self, nom): self.ReturnScene = None def retourCallBack(self, nom): from scene.MainScene import MainScene self.ReturnScene = MainScene(self.loader) def updateMain(self, e, l): x = 10 y = 10 for cardUpdateEnemy in self.cardEnemy: if self.lastAnimCard != cardUpdateEnemy: cardUpdateEnemy.update(e, l) cardUpdateEnemy.updateResize(self.width, self.height) cardUpdateEnemy.setPosition(x, y, 0) x += cardUpdateEnemy.width + 5 x = self.width - 85 y = self.height - 115 for cardUpdatePlayer in self.cardPlayer: if self.lastAnimCard != cardUpdatePlayer: cardUpdatePlayer.update(e, l) cardUpdatePlayer.updateResize(self.width, self.height) cardUpdatePlayer.setPosition(x, y, 0) x -= cardUpdatePlayer.width + 5 self.statusText(l) def update(self, e, l): ''' @param e: le gestionnaire d'événement @param l: le gestionnaire d'image @return: Scene à renvoyer ''' self.btnPasser.update(e, l) if (e.keyboard[pygame.K_ESCAPE]): e.keyboard[pygame.K_ESCAPE] = False self.retourCallBack('') self.loader.clearFont() if self.action == 0: #Get name and random begin print("Choix du nom ...") print("Choix du joueur commençant ...") self.changeText(l, "" + self.player1.name + " à vous !") self.actionCallBack = True self.action = 1 elif self.action == 1: if self.actionCallBack == False: self.animDeckPlayer() self.action = 2 self.actionCallBack = True elif self.action == 2: if self.actionCallBack == False: self.action = 10 elif self.action == 10: # Joueur 1 sur joueur 2 if e.keyboard[pygame.K_v] or self.nt: self.nt = False e.keyboard[pygame.K_v] = False self.changeText(l, "" + self.player2.name + " à vous !") self.action = 11 self.actionCallBack = True elif self.action == 11: if self.actionCallBack == False: self.animDeckEnemy() self.action = 12 self.actionCallBack = True elif self.action == 12: if self.actionCallBack == False: self.action = 20 elif self.action == 20: # Joueur 2 sur joueur 1 if e.keyboard[pygame.K_v] or self.nt: self.nt = False e.keyboard[pygame.K_v] = False self.changeText(l, "" + self.player1.name + " à vous !") self.actionCallBack = True self.action = 30 elif self.action == 30: # reset self.tour += 1 print("Tour passé : " + str(self.tour)) self.player1.nextTour(self.tour) self.player2.nextTour(self.tour) self.changeText(l, "" + self.player1.name + " à vous !") self.actionCallBack = True self.action = 1 elif self.action == 40: # Fin de partie pass elif self.action == 50: self.retourCallBack('') self.updateMain(e, l) if (e.quit): e.quit = True self.retourCallBack('') self.loader.clearFont() return self.ReturnScene def resizeWindow(self, l, w, h): self.width = w self.height = h backgrounds = l.getAnimation('bg') if len(backgrounds) > 0: backgrounds[0].newPos(0, 0, self.width, self.height, 0) self.btnPasser.resizeWindow(l, w, h) animation = l.getAnimation('title') if len(animation) > 0: animation[0].newPos((self.width / 2 - animation[0].sprite.w / 2), 30, animation[0].sprite.w, animation[0].sprite.h, 0) self.updateMain(None, l)
class MainScene(Scene): ''' Une scene pour le chargement des données ''' def __init__(self, l): ''' Constructeur de la class LoadScene ''' self.width = pygame.display.get_surface().get_width() self.height = pygame.display.get_surface().get_height() self.loader = l l.clearAnimation() l.addAnimationByPath('bg', '../img/background.jpg', level=0) l.addAnimationByPath('solo', '../img/solo.png', self.width / 2 - 140, 100, level=1) l.addAnimationByPath('multi', '../img/multi.png', self.width / 2 - 140, 100, level=1) l.addAnimationByPath('options', '../img/option.png', self.width / 2 - 140, 100, level=1) l.addAnimationByPath('quitter', '../img/quitter.png', self.width / 2 - 140, 100, level=1) self.createButton(l) self.resizeWindow(l, self.width, self.height) self.ReturnScene = self texts = l.getFont('mainTitle') if len(texts) > 0: sprite = Sprite(texts[0].render("Menu principale :", 1, (255, 255, 0))) animation = Animation(sprite) animation.newPos((self.width / 2 - sprite.w / 2), 30, sprite.w, sprite.h, 0) l.removeAnimation('title') l.addAnimation('title', animation) def createButton(self, l): solo = l.getAnimation('solo') if len(solo) > 0: solo[0].newPos(self.width / 2 - 140, 100, 280, 50, 20) self.btnSolo = Button('solo', '../img/solo.png', '../img/solo_select.png', self.partieSolo) self.btnSolo.loadButton(self.width / 2 - 140, 100, 280, 50, self.width, self.height) multi = l.getAnimation('multi') if len(multi) > 0: multi[0].newPos(self.width / 2 - 140, 200, 280, 50, 20) self.btnMulti = Button('multi', '../img/multi.png', '../img/multi_select.png', self.callbackButton) self.btnMulti.loadButton(self.width / 2 - 140, 200, 280, 50, self.width, self.height) options = l.getAnimation('options') if len(options) > 0: options[0].newPos(self.width / 2 - 140, 300, 280, 50, 20) self.btnOptions = Button('options', '../img/option.png', '../img/option_select.png', self.callbackButton) self.btnOptions.loadButton(self.width / 2 - 140, 300, 280, 50, self.width, self.height) quitter = l.getAnimation('quitter') if len(quitter) > 0: quitter[0].newPos(self.width / 2 - 140, 400, 280, 50, 20) self.btnQuitter = Button('quitter', '../img/quitter.png', '../img/quitter_select.png', self.quitterCallBack) self.btnQuitter.loadButton(self.width / 2 - 140, 400, 280, 50, self.width, self.height) def callbackButton(self, nom): print('Nom : ' + nom) def quitterCallBack(self, nom): self.ReturnScene = None def partieSolo(self, nom): from scene.TypePartieScene import TypePartieScene self.ReturnScene = TypePartieScene(self.loader) def update(self, e, l): ''' @param e: le gestionnaire d'événement @param l: le gestionnaire d'image @return: Scene à renvoyer ''' self.btnSolo.update(e, l) self.btnMulti.update(e, l) self.btnOptions.update(e, l) self.btnQuitter.update(e, l) if (e.quit): self.quitterCallBack('') return self.ReturnScene def resizeWindow(self, l, w, h): self.width = w self.height = h backgrounds = l.getAnimation('bg') if len(backgrounds) > 0: backgrounds[0].newPos(0, 0, self.width, self.height, 0) self.btnSolo.resizeWindow(l, w, h) self.btnMulti.resizeWindow(l, w, h) self.btnOptions.resizeWindow(l, w, h) self.btnQuitter.resizeWindow(l, w, h) animation = l.getAnimation('title') if len(animation) > 0: animation[0].newPos((self.width / 2 - animation[0].sprite.w / 2), 30, animation[0].sprite.w, animation[0].sprite.h, 0)