def init(self): self.settingtime = AccessSettings.getGameSettings("pointto", 1) self.settingnb = AccessSettings.getGameSettings("pointto", 0) self.window = gameWindow.GameWindow(self, self.settingnb, self.settingtime) self.game = pointToCardGameWindow(self.window.gameArea, self.cartesJouees[0:self.settingnb]) self.window.show() self.window.resetSignal.connect(self.reset) self.window.leaveSignal.connect(self.endOfGame) self.game.error.connect(self.window.incrementErrorCount) self.game.success.connect(self.window.incrementSuccessCount) self.window.gameWon.connect(self.game.victoryWidget.show) self.window.timeIsOut.connect(self.timeIsOut)
def update(self): allGameNames = AccessSettings.getAllGameNames() # modification dans le xml de parametres AccessSettings.changeLangage(str(self.editlangue.text())) AccessSettings.changeUser(str(self.edituser.text())) for rank, GameName in enumerate(allGameNames): AccessSettings.changeNbCards(str(self.nbcardsEdit[rank].text()), GameName) AccessSettings.changeChrono(str(self.chronoEdit[rank].text()), GameName) self.updated.emit() self.close()
def __init__(self, bigWindow, CardsPlayed, width, height): self.setting = AccessSettings.getGameSettings("memory", 0) ## les flashcards en jeu self.cardslist = CardsPlayed ## la fenetre ( widget avec scroll bar) super(MemoryGame, self).__init__(bigWindow) bigWindow.setWindowTitle("Memory") self.setGeometry(QtCore.QRect(0, 0, width, height)) self.setStyleSheet("background-image: url(:/fond/wood.jpg);") self.setWidgetResizable(True) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.plateau = QWidget(self) self.plateau.setGeometry( QtCore.QRect(20, 20, 670, 120 * ceil(2 * len(self.cardslist) / 5))) self.plateau.setStyleSheet("background-image: url(:/fond/wood.jpg);") self.gridLayout = QGridLayout(self.plateau) self.gridLayout.setContentsMargins(20, 20, 20, 20) # creation des cartes de jeu a raison de 2 par flashcard en jeu self.mycards = list(range(2 * self.setting)) playingcard = self.cardslist[0:self.setting] shuffle(playingcard) for i, carte in enumerate(playingcard): self.mycards[2 * i] = PlayingCard(carte, 0, self.plateau) self.mycards[2 * i + 1] = PlayingCard(carte, 1, self.plateau) # on mélange les cartes shuffle(self.mycards) # affichage des cartes for i in range(len(self.mycards)): # 5 cartes par ligne row = i / 5 column = i % 5 self.gridLayout.addWidget(self.mycards[i], row, column, 1, 1) self.setWidget(self.plateau) # nombre et donnes des cartes retournees (au max 2 donc 0 ou 1 ou 2) global yellowcards yellowcards = [] # le message de victoire self.victoryButton = QPushButton(self) self.victoryButton.setGeometry(QtCore.QRect(230, 130, 251, 221)) self.victoryButton.setStyleSheet( "background-image: url(:/icons/win.png);\n" "background-color: rgba(255, 255, 255, 0);") self.victoryButton.setVisible(False) # le message de defaite self.defeatButton = QPushButton(self) self.defeatButton.setGeometry(QtCore.QRect(230, 130, 221, 221)) self.defeatButton.setStyleSheet( "background-image: url(:/icons/gameover2.png);\n" "background-color: rgba(255, 255, 255, 0);") self.defeatButton.setVisible(False) # connection slots et signaux for i in range(len(self.mycards)): self.mycards[i].clicked.connect(self.mycards[i].flip) self.mycards[i].clicked.connect(self.checkAnswer)
def init(self): self.cartesJouees=[] self.settingtime = AccessSettings.getGameSettings("dragdrop", 1) self.settingnb = AccessSettings.getGameSettings("dragdrop", 0) while (len(self.cartesJouees)<self.settingnb): i=randrange(0, len(self.cartesJouables)) if (self.cartesJouables[i] not in self.cartesJouees): self.cartesJouees.append(self.cartesJouables[i]) self.window=gameWindow.GameWindow(self, len(self.cartesJouees), self.settingtime) self.game=dragDropGameWindow(self.window.gameArea, self.cartesJouees) self.window.show() self.window.resetSignal.connect(self.reset) self.window.leaveSignal.connect(self.endOfGame) self.game.error.connect(self.window.incrementErrorCount) self.game.success.connect(self.window.incrementSuccessCount) self.window.gameWon.connect(self.game.victoryWidget.show) self.window.timeIsOut.connect(self.timeIsOut)
def init(self): self.cartesJouees = [] self.settingtime = AccessSettings.getGameSettings("hotcold", 1) self.settingnb = AccessSettings.getGameSettings("hotcold", 0) while (len(self.cartesJouees) < self.settingnb and not len(self.cartesJouees) == len(self.cartesJouables)): i = randrange(0, len(self.cartesJouables)) if (self.cartesJouables[i] not in self.cartesJouees): self.cartesJouees.append(self.cartesJouables[i]) self.window = gameWindow.GameWindow(self, len(self.cartesJouees), self.settingtime) self.game = hotColdGameWindow(self.window.gameArea, self.cartesJouees[0]) self.currentCardNb = 0 self.window.show() self.window.resetSignal.connect(self.reset) self.window.leaveSignal.connect(self.endOfGame) self.game.error.connect(self.onFailure) self.game.success.connect(self.onSuccess) self.window.timeIsOut.connect(self.game.onDefeat)
def __init__(self, givenWindow, cardsPlayed): super(MemoryGameWindow, self).__init__(givenWindow) self.setting = AccessSettings.getGameSettings("memory", 1) self.resize(givenWindow.frameSize()) self.cardslist = cardsPlayed self.nbCharsDisplayed = 0 self.window = gameWindow.GameWindow(self, len(self.cardslist), self.setting) self.game = MemoryGame(self.window.gameArea, self.cardslist, self.window.gameArea.width(), self.window.gameArea.height()) self.window.show() self.window.resetSignal.connect(self.reset) self.window.leaveSignal.connect(self.endOfGame) self.game.success.connect(self.game.onVictory) self.window.timeIsOut.connect(self.game.onDefeat)
def __init__(self, parent): super().__init__(parent) ## la fenetre self.setObjectName("Current Settings") self.setFixedSize(497, 492) ## le layout du haut self.whatWidget = QWidget(self) self.whatWidget.setGeometry(QtCore.QRect(10, 10, 451, 31)) self.togivename = QHBoxLayout(self.whatWidget) self.togivename.setContentsMargins(0, 0, 0, 0) self.explain = QLabel(self.whatWidget) self.explain.setObjectName("explain") self.explain.setText( " Vous pouvez mettre à jous les paramètres de l'application ci-dessous :" ) self.togivename.addWidget(self.explain) ## le layout de la grille centrale self.gridWidget = QWidget(self) self.gridWidget.setGeometry(QtCore.QRect(10, 50, 451, 341)) self.answergrid = QGridLayout(self.gridWidget) self.answergrid.setContentsMargins(0, 0, 0, 0) ## the current Settings currentSettings = AccessSettings.getAllSettings() # ligne 1 : langue par défaut self.langue = QLabel(self.gridWidget) self.answergrid.addWidget(self.langue, 1, 0, 1, 3) self.langue.setText("Language par défault :") self.editlangue = QLineEdit(self.gridWidget) self.answergrid.addWidget(self.editlangue, 1, 2, 1, 2) self.editlangue.setText(currentSettings[0]) # ligne 2 : user par défaut self.user = QLabel(self.gridWidget) self.answergrid.addWidget(self.user, 2, 0, 1, 3) self.user.setText("Utilisateur en cours : ") self.edituser = QLineEdit(self.gridWidget) self.answergrid.addWidget(self.edituser, 2, 2, 1, 2) self.edituser.setText(currentSettings[1]) # tableau 2x5 sur un bloc 3x6 pour les parametre des jeux # pour la forme self.notvisible = QLineEdit(self.gridWidget) self.answergrid.addWidget(self.notvisible, 3, 0, 1, 1) #self.notvisible.setVisible(False) # les caractéristiques self.nbcards = QLabel(self.gridWidget) self.answergrid.addWidget(self.nbcards, 4, 0, 1, 1) self.nbcards.setText("Nombre de cartes") self.chrono = QLabel(self.gridWidget) self.answergrid.addWidget(self.chrono, 5, 0, 1, 1) self.chrono.setText("Temps de jeu") # les jeux allGameNames = AccessSettings.getAllGameNames() self.gamelabel = allGameNames.copy() self.nbcardsEdit = allGameNames.copy() self.chronoEdit = allGameNames.copy() for rank, GameName in enumerate(allGameNames): self.gamelabel[rank] = QLabel(self.gridWidget) self.answergrid.addWidget(self.gamelabel[rank], 3, rank + 1, 1, 1) self.gamelabel[rank].setText(GameName) self.nbcardsEdit[rank] = QLineEdit(self.gridWidget) self.answergrid.addWidget(self.nbcardsEdit[rank], 4, rank + 1, 1, 1) self.nbcardsEdit[rank].setText(currentSettings[2][rank]) self.chronoEdit[rank] = QLineEdit(self.gridWidget) self.answergrid.addWidget(self.chronoEdit[rank], 5, rank + 1, 1, 1) self.chronoEdit[rank].setText(currentSettings[3][rank]) ## le bouton du bas self.updateButton = QPushButton(u"Update", self.gridWidget) self.quitButton = QPushButton(u"Quit", self.gridWidget) self.answergrid.addWidget(self.updateButton, 6, 0, 1, 3) self.answergrid.addWidget(self.quitButton, 6, 3, 1, 3) ## gestion des slots et signaux self.updateButton.clicked.connect(self.update) self.quitButton.clicked.connect(self.quit)