|
@ -5,7 +5,7 @@ import time |
|
|
#Création de la table Personnage |
|
|
#Création de la table Personnage |
|
|
conn = sqlite3.connect('JeuDeRole.db') |
|
|
conn = sqlite3.connect('JeuDeRole.db') |
|
|
c = conn.cursor() |
|
|
c = conn.cursor() |
|
|
c.execute('''CREATE TABLE if not exists Perso(num_joueur INT, nom TEXT, pdv INT, exp INT, categorie TEXT)''') |
|
|
c.execute('''CREATE TABLE if not exists Perso (nom TEXT PRIMARY KEY, pdv INT, exp INT, categorie TEXT)''') |
|
|
conn.commit() |
|
|
conn.commit() |
|
|
|
|
|
|
|
|
class Personnage: |
|
|
class Personnage: |
|
@ -79,17 +79,23 @@ P1 = Personnage(nomP1, catP1) |
|
|
P2 = Personnage(nomP2, catP2) |
|
|
P2 = Personnage(nomP2, catP2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
J1 = (1, nomP1, 20, 1, catP1) |
|
|
J1_1 = (20, 1, catP1, nomP1) |
|
|
J2 = (2, nomP2, 20, 1, catP2) |
|
|
J2_1 = (20, 1, catP2, nomP2) |
|
|
|
|
|
J1_2 = (nomP1, 20, 1, catP1) |
|
|
|
|
|
J2_2 = (nomP2, 20, 1, catP2) |
|
|
liste = c.execute("SELECT nom FROM Perso") |
|
|
liste = c.execute("SELECT nom FROM Perso") |
|
|
if nomP1 in liste : |
|
|
conn.commit() |
|
|
|
|
|
if (nomP1,) in liste : |
|
|
c.execute("UPDATE Perso SET num_joueur = (?), nom = (?), pdv = (?), exp = (?), categorie = (?)", J1) |
|
|
c.execute("UPDATE Perso SET pdv = (?), exp = (?), categorie = (?) WHERE nom = (?)", J1_1) |
|
|
c.execute("UPDATE Perso SET num_joueur = (?), nom = (?), pdv = (?), exp = (?), categorie = (?)", J2) |
|
|
else: |
|
|
|
|
|
c.execute("INSERT INTO Perso VALUES (?, ?, ?, ?)", J1_2) |
|
|
|
|
|
conn.commit() |
|
|
|
|
|
if (nomP2,) in liste: |
|
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?), exp = (?), categorie = (?) WHERE nom = (?)", J2_1) |
|
|
else: |
|
|
else: |
|
|
c.execute("INSERT INTO Perso VALUES (?, ?, ?, ?, ?)", J1) |
|
|
c.execute("INSERT or REPLACE INTO Perso VALUES (?, ?, ?, ?)", J2_2) |
|
|
c.execute("INSERT INTO Perso VALUES (?, ?, ?, ?, ?)", J2) |
|
|
|
|
|
conn.commit() |
|
|
conn.commit() |
|
|
|
|
|
#https://stackoverflow.com/questions/35415469/sqlite3-unique-constraint-failed-error |
|
|
|
|
|
|
|
|
print("-----------------------------") |
|
|
print("-----------------------------") |
|
|
while P1.pdv > 0 and P2.pdv > 0: |
|
|
while P1.pdv > 0 and P2.pdv > 0: |
|
@ -101,24 +107,24 @@ while P1.pdv > 0 and P2.pdv > 0: |
|
|
print(nomP1, "attaque", nomP2, "!!!", nomP2,"vient de perdre", -perte_pdv, "point(s) de vie.") |
|
|
print(nomP1, "attaque", nomP2, "!!!", nomP2,"vient de perdre", -perte_pdv, "point(s) de vie.") |
|
|
P2.change_pdv(perte_pdv) |
|
|
P2.change_pdv(perte_pdv) |
|
|
if P2.pdv > 0: |
|
|
if P2.pdv > 0: |
|
|
pdv2 = (P2.pdv) |
|
|
pdv2 = (P2.pdv, nomP2,) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE num_joueur = 2", (pdv2,)) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv2) |
|
|
conn.commit() |
|
|
conn.commit() |
|
|
else: |
|
|
else: |
|
|
pdv2 = 0 |
|
|
pdv2 = (0, nomP2,) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE num_joueur = 2", (pdv2,)) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv2) |
|
|
conn.commit() |
|
|
conn.commit() |
|
|
else: |
|
|
else: |
|
|
perte_pdv = -randint(1,4) |
|
|
perte_pdv = -randint(1,4) |
|
|
print(nomP2, "arrive à se défendre de l'attaque de", nomP1,"!!!", nomP1,"vient de perdre", -perte_pdv, "point(s) de vie.") |
|
|
print(nomP2, "arrive à se défendre de l'attaque de", nomP1,"!!!", nomP1,"vient de perdre", -perte_pdv, "point(s) de vie.") |
|
|
P1.change_pdv(perte_pdv) |
|
|
P1.change_pdv(perte_pdv) |
|
|
if P1.pdv > 0: |
|
|
if P1.pdv > 0: |
|
|
pdv1 = (P1.pdv) |
|
|
pdv1 = (P1.pdv, nomP1,) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE num_joueur = 1", (pdv1,)) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv1) |
|
|
conn.commit() |
|
|
conn.commit() |
|
|
else: |
|
|
else: |
|
|
pdv1 = 0 |
|
|
pdv1 = (0, nomP1,) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE num_joueur = 1", (pdv1,)) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv1) |
|
|
conn.commit() |
|
|
conn.commit() |
|
|
P1.affiche_caracteristiques() |
|
|
P1.affiche_caracteristiques() |
|
|
P2.affiche_caracteristiques() |
|
|
P2.affiche_caracteristiques() |
|
@ -126,9 +132,6 @@ while P1.pdv > 0 and P2.pdv > 0: |
|
|
if P1.pdv > 0 and P2.pdv <= 0: |
|
|
if P1.pdv > 0 and P2.pdv <= 0: |
|
|
P1.change_exp(1) |
|
|
P1.change_exp(1) |
|
|
print("Le joueur", nomP1, "a gagné.") |
|
|
print("Le joueur", nomP1, "a gagné.") |
|
|
valeur = 0 |
|
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE num_joueur = 1", (valeur,)) |
|
|
|
|
|
conn.commit() |
|
|
|
|
|
break |
|
|
break |
|
|
elif P1.pdv <= 0 and P2.pdv > 0: |
|
|
elif P1.pdv <= 0 and P2.pdv > 0: |
|
|
P2.change_exp(1) |
|
|
P2.change_exp(1) |
|
@ -136,9 +139,10 @@ while P1.pdv > 0 and P2.pdv > 0: |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("-----------------------------") |
|
|
print("-----------------------------------") |
|
|
if P1.pdv > 0 and P2.pdv > 0: |
|
|
if P1.pdv > 0 and P2.pdv > 0: |
|
|
input("~~~Veuillez appuyer sur Entrée~~~") |
|
|
input("~~~Veuillez appuyer sur Entrée~~~") |
|
|
|
|
|
print("-----------------------------------") |
|
|
print(" ") |
|
|
print(" ") |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -150,24 +154,24 @@ while P1.pdv > 0 and P2.pdv > 0: |
|
|
print(nomP2, "attaque", nomP1, "!!!", nomP1,"vient de perdre", -perte_pdv, "point(s) de vie.") |
|
|
print(nomP2, "attaque", nomP1, "!!!", nomP1,"vient de perdre", -perte_pdv, "point(s) de vie.") |
|
|
P1.change_pdv(perte_pdv) |
|
|
P1.change_pdv(perte_pdv) |
|
|
if P1.pdv > 0: |
|
|
if P1.pdv > 0: |
|
|
pdv1 = (P1.pdv) |
|
|
pdv1 = (P1.pdv, nomP1,) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE num_joueur = 1", (pdv1,)) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv1) |
|
|
conn.commit() |
|
|
conn.commit() |
|
|
else: |
|
|
else: |
|
|
pdv1 = 0 |
|
|
pdv1 = (0, nomP1,) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE num_joueur = 1", (pdv1,)) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv1) |
|
|
conn.commit() |
|
|
conn.commit() |
|
|
else: |
|
|
else: |
|
|
perte_pdv = -randint(1,4) |
|
|
perte_pdv = -randint(1,4) |
|
|
print(nomP1, "arrive à se défendre de l'attaque de", nomP2, "!!!", nomP2,"vient de perdre", -perte_pdv, "point(s) de vie.") |
|
|
print(nomP1, "arrive à se défendre de l'attaque de", nomP2, "!!!", nomP2,"vient de perdre", -perte_pdv, "point(s) de vie.") |
|
|
P2.change_pdv(perte_pdv) |
|
|
P2.change_pdv(perte_pdv) |
|
|
if P2.pdv > 0: |
|
|
if P2.pdv > 0: |
|
|
pdv2 = (P2.pdv) |
|
|
pdv2 = (P2.pdv, nomP2,) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE num_joueur = 2", (pdv2,)) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv2) |
|
|
conn.commit() |
|
|
conn.commit() |
|
|
else: |
|
|
else: |
|
|
pdv2 = 0 |
|
|
pdv2 = (0, nomP2,) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE num_joueur = 2", (pdv2,)) |
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv2) |
|
|
conn.commit() |
|
|
conn.commit() |
|
|
P1.affiche_caracteristiques() |
|
|
P1.affiche_caracteristiques() |
|
|
P2.affiche_caracteristiques() |
|
|
P2.affiche_caracteristiques() |
|
@ -178,9 +182,10 @@ while P1.pdv > 0 and P2.pdv > 0: |
|
|
P2.change_exp(1) |
|
|
P2.change_exp(1) |
|
|
print("Le joueur", nomP2, "a gagné.") |
|
|
print("Le joueur", nomP2, "a gagné.") |
|
|
|
|
|
|
|
|
print("-----------------------------") |
|
|
print("-----------------------------------") |
|
|
if P1.pdv > 0 and P2.pdv > 0: |
|
|
if P1.pdv > 0 and P2.pdv > 0: |
|
|
input("~~~Veuillez appuyer sur Entrée~~~") |
|
|
input("~~~Veuillez appuyer sur Entrée~~~") |
|
|
|
|
|
print("-----------------------------------") |
|
|
print(" ") |
|
|
print(" ") |
|
|
|
|
|
|
|
|
conn.close() |
|
|
conn.close() |