示例#1
0
 def addGrille(self):
     if len(self.grillesToDraw) < 6:
         grille = Grille.Grille(9, 3, 0, 0, 300, 90, Loto_Case)
         LTO.Loto_Party.generateRandomContenuGrille(grille)
         self.grillesToDraw.append(grille)
     else:
         print("[ERROR] Cannot add another grille")
示例#2
0
    def setup(self):
        self.b1 = Bateau.Croiseur(1, 1, True)
        self.b2 = Bateau.Escorteur(2, 5, False)
        self.b3 = Bateau.SousMarin(4, 2, False)  # Sous-Marin en plongée

        self.g1 = Grille(7, 9)

        # On ajoute 3 Bateaux...
        self.g1 += self.b1
        self.g1 += self.b2
        self.g1 += self.b3
示例#3
0
 def __init__(self, width, height):
     self.players = []
     self.width = width
     self.height = height
     self.grille = Grille(width, height)
     self.colors = [
         'red',
         'yellow',
         'green',
         'blue',
         'orange',
         'violet',
         'pink',
     ]
     self.turn = -1
示例#4
0
def main():

    animation = False
    couleur = False

    try:
        if(sys.argv[1] == '-animation'):
            animation = True

        elif(sys.argv[1] == '-couleur'):
            couleur = True
        
        else:
            nb_etapes = int(sys.argv[1])

    except IndexError:
        print("Veuillez entrer un argument avant l'exécution, fin du programme.")
        return

    # Pour les tests      
    #nb_etapes = int(open('arg.txt', 'r').read())

    config = open('config.txt', 'r').read().splitlines()
    regles = open('rules.txt', 'r').read().splitlines()

    hauteur = int(config[0].split(',')[0])
    largeur = int(config[0].split(',')[1])

    grille = Grille(hauteur, largeur)
    grille.initialiser(config)
    regle = Regles(regles)

    if(animation or couleur):
        while(True):
            grille.simulation(regle)
            grille.imprimer(couleur)
            input('\nAppuyez sur la touche <Enter> pour simuler une autre étape ...')
            print('\n\n\n\n\n')

    else:
        for sim in range(nb_etapes):
            grille.simulation(regle)
    
        grille.imprimer(couleur)
示例#5
0
 def victoire(self):#On va vider les cases lorsque l'on touche un bateau sur cette case ainsi on a juste besoin de verifier si la grille est vide ce qui est le cas pour une grille generée par defaut
     if(self.grille.grille == Grille().grille):
         return True
     return False
示例#6
0
from Grille import Grille
import Bateau

b1 = Bateau.Croiseur(1, 1, True)
b2 = Bateau.Escorteur(2, 5, False)
b3 = Bateau.SousMarin(4, 2, False)

g1 = Grille(7, 9)

g1 += b1
g1 += b2
g1 += b3
print(b1.est_touche(1, 1))
print(b1.est_touche(1, 2))
print(b1.est_touche(1, 2))
print(b1.est_touche(1, 3))
print(g1.coup(1, 4))
示例#7
0
    def __init__(self, data):
        self.data = data
        # Création des grilles
        self.grille_J1 = Grille.Grille(10, 10, 145, 100, 495, 450,
                                       Bataille_Navale_Case)
        self.grille_J2 = Grille.Grille(10, 10, 145, -450, 495, -100,
                                       Bataille_Navale_Case)
        # On indique que la grille du joueur 2 ne doit pas montrer les bateaux
        self.grille_J2.unshowShip()
        # Ajout des images des bateaux + redimension de ces images
        self.bateauStr = {
            "Porte-Avion": [
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/Porte-avions_1.png")
                    ).convert_alpha(), (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/Porte-avions_2.png")
                    ).convert_alpha(), (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/Porte-avions_3.png")
                    ).convert_alpha(), (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/Porte-avions_4.png")
                    ).convert_alpha(), (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/Porte-avions_5.png")
                    ).convert_alpha(), (35, 35))
            ],
            "Croiseur": [
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets",
                            "Bataille Navale/croiseur_1.png")).convert_alpha(),
                    (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets",
                            "Bataille Navale/croiseur_2.png")).convert_alpha(),
                    (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets",
                            "Bataille Navale/croiseur_3.png")).convert_alpha(),
                    (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets",
                            "Bataille Navale/croiseur_4.png")).convert_alpha(),
                    (35, 35))
            ],
            "Contre-Torpilleur": [
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets",
                            "Bataille Navale/contre-torpilleur_1.png")).
                    convert_alpha(), (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets",
                            "Bataille Navale/contre-torpilleur_2.png")).
                    convert_alpha(), (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets",
                            "Bataille Navale/contre-torpilleur_3.png")).
                    convert_alpha(), (35, 35))
            ],
            "Sous-marin": [
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/sous-marin_1.png")).
                    convert_alpha(), (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/sous-marin_2.png")).
                    convert_alpha(), (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/sous-marin_3.png")).
                    convert_alpha(), (35, 35))
            ],
            "Torpilleur": [
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/torpilleur_1.png")).
                    convert_alpha(), (35, 35)),
                pygame.transform.scale(
                    pygame.image.load(
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)),
                            "../assets", "Bataille Navale/torpilleur_2.png")).
                    convert_alpha(), (35, 35))
            ]
        }

        # Ajout des images des bateaux + redimension de ces images + rotation a 90 degrés des images
        # Sert pour l'affichage des bateau tournés
        self.bateauStr_H = {
            "Porte-Avion": [
                pygame.transform.rotate(self.bateauStr["Porte-Avion"][0], 90),
                pygame.transform.rotate(self.bateauStr["Porte-Avion"][1], 90),
                pygame.transform.rotate(self.bateauStr["Porte-Avion"][2], 90),
                pygame.transform.rotate(self.bateauStr["Porte-Avion"][3], 90),
                pygame.transform.rotate(self.bateauStr["Porte-Avion"][4], 90)
            ],
            "Croiseur": [
                pygame.transform.rotate(self.bateauStr["Croiseur"][0], 90),
                pygame.transform.rotate(self.bateauStr["Croiseur"][1], 90),
                pygame.transform.rotate(self.bateauStr["Croiseur"][2], 90),
                pygame.transform.rotate(self.bateauStr["Croiseur"][3], 90)
            ],
            "Contre-Torpilleur": [
                pygame.transform.rotate(self.bateauStr["Contre-Torpilleur"][0],
                                        90),
                pygame.transform.rotate(self.bateauStr["Contre-Torpilleur"][1],
                                        90),
                pygame.transform.rotate(self.bateauStr["Contre-Torpilleur"][2],
                                        90)
            ],
            "Sous-marin": [
                pygame.transform.rotate(self.bateauStr["Sous-marin"][0], 90),
                pygame.transform.rotate(self.bateauStr["Sous-marin"][1], 90),
                pygame.transform.rotate(self.bateauStr["Sous-marin"][2], 90)
            ],
            "Torpilleur": [
                pygame.transform.rotate(self.bateauStr["Torpilleur"][0], 90),
                pygame.transform.rotate(self.bateauStr["Torpilleur"][1], 90)
            ]
        }
        # Données de placements sous forme [(bx1, by1), (bx2, by2), (bx3, by3), (bx4, by4), (bx5, by5), grille du joueur n montrée, ID bateau sélectionné, [dirBateau1, dirBateau2, dirBateau3, dirBateau4, dirBateau5]]
        self.placeData = [
            (10, 150), (52, 150), (10, 330), (52, 330), (94, 280), 1, -1,
            ["Verticale", "Verticale", "Verticale", "Verticale", "Verticale"]
        ]
        # Données de jeu sous forme [tour du joueur n, grille du joueur n montrée]
        self.currentPlayData = [1, 1]
        # texture de l'animation de tir
        self.tirTexture = pygame.transform.scale(
            pygame.image.load(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             "../assets",
                             "Bataille Navale/tir.png")).convert_alpha(),
            (35, 35))
        self.tirData = [-1, -1]
        # Timer pour l'animation de tir
        self.tirTimer = 0
        # Variable indiquant le gagnant de la partie
        self.winner = 0

        # Variables dont ont se sert pour la précision
        self.tirTouche = [0, 0]
        self.tirCoule = [0, 0]
        self.tirs = [0, 0]
        self.time = 0
        # Variable contenant l'IA
        self.IA = None
示例#8
0
文件: Game.py 项目: Cassius-P/Sudoku
    def __init__(self, parent=None, size=int, load=[]):
        super().__init__(parent)
        # crée la grille et le bouton de verif

        self.table = QTableWidget(self)
        self.table.itemChanged.connect(self.changeValue)

        #Verification button
        verif = QPushButton("Verifier grille")
        verif.clicked.connect(self.verifButton)
        self.verif = verif

        #Save Game button
        save = QPushButton("Sauvegarder")
        save.clicked.connect(self.saveGame)
        self.save = save

        self.size = size
        self.table.setRowCount(self.size)
        self.table.setColumnCount(self.size)

        # Cache les entêtes horizontale et verticale
        self.table.horizontalHeader().hide()
        self.table.verticalHeader().hide()

        # Définit les cases carrées 50 pixels x 50 pixels
        for row in range(self.size):
            self.table.setRowHeight(row, 50)
            for col in range(self.size):
                self.table.setColumnWidth(col, 50)

        # remplit la grille avec des QTableWidgetItem
        for row in range(self.size):
            for col in range(self.size):
                tableItem = QTableWidgetItem()
                # val= self.testGrid[row][col]
                tableItem.setTextAlignment(QtCore.Qt.AlignHCenter
                                           | QtCore.Qt.AlignVCenter)
                # tableItem.setText(str(val))
                self.table.setItem(row, col, tableItem)

        # définit la police de caractère par défaut de la table
        font = QFont()
        font.setFamily(u"DejaVu Sans")
        font.setPointSize(16)
        self.table.setFont(font)

        # taille de la fenêtre
        self.setFixedSize(52 * self.size + 6, 53 * self.size + 55)

        # positionne la table dans la fenêtre
        posit = QGridLayout()
        posit.addWidget(self.table, 0, 0)
        #posit.addWidget(self.timer, 88 * self.size, 0)
        posit.addWidget(self.verif, 52 * self.size, 0)
        posit.addWidget(self.save, 75 * self.size, 0)

        self.setLayout(posit)

        # Grille test
        self.grilleTest = Grille(self.size)
        print("Load : ", load)

        #Chargement de la grille pour chargée et nouvelle partie
        if len(load) == 0:
            print("New game detected")
            self.full = self.grilleTest.getCompleteGrille()

            self.startMatrix = self.grilleTest.getGrille()
            self.matrix = self.startMatrix
        else:
            print("Loaded game detectd")
            self.full = load[1]
            self.grilleTest.setGrid(load)
            self.startMatrix = load[0]
            self.matrix = load[2]
            print("loaded")

        # intégre le delegate pour lignes en gras et les cases en couleur
        self.delegate = ItemDelegate(self.table)
        self.table.setItemDelegate(self.delegate)

        # redessine les lignes en gras et les cases de couleur
        self.delegate.grilleinit(self.matrix, self.size)

        # affiche la grille courante
        self.showGrille(self.matrix)

        # place le focus
        self.table.setFocus()
        self.table.setCurrentCell(0, 0)