|
|
|
from random import randint
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
#Création de la table Personnage
|
|
|
|
conn = sqlite3.connect('JeuDeRole.db')
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute('''CREATE TABLE if not exists Perso (nom TEXT PRIMARY KEY, pdv INT, exp INT, categorie TEXT)''')
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
class Personnage:
|
|
|
|
def __init__(self, nom, cat):
|
|
|
|
self.nom = nom
|
|
|
|
self.pdv = 20
|
|
|
|
self.exp = 1
|
|
|
|
self.cat = cat
|
|
|
|
if self.cat == "guerrier":
|
|
|
|
self.inv = "épée"
|
|
|
|
elif self.cat == "magicien":
|
|
|
|
self.inv = "bâton"
|
|
|
|
elif self.cat == "voleur":
|
|
|
|
self.inv = "dague"
|
|
|
|
elif self.cat == "elfe":
|
|
|
|
self.inv = "arc"
|
|
|
|
elif self.cat == "orc":
|
|
|
|
self.inv = "masse"
|
|
|
|
elif self.cat == "invocateur":
|
|
|
|
self.inv = "livre d'invocation"
|
|
|
|
elif self.cat == "loup-garou":
|
|
|
|
self.inv = "griffes"
|
|
|
|
|
|
|
|
def jet_attaque(self):
|
|
|
|
attaque = randint(1,20)
|
|
|
|
if self.cat == "guerrier":
|
|
|
|
attaque = attaque + self.exp*7
|
|
|
|
elif self.cat == "mage":
|
|
|
|
attaque = attaque + self.exp*7
|
|
|
|
elif self.cat == "voleur":
|
|
|
|
attaque = attaque + self.exp*3
|
|
|
|
elif self.cat == "elfe":
|
|
|
|
attaque = attaque + self.exp*5
|
|
|
|
elif self.cat == "orc":
|
|
|
|
attaque = attaque + self.exp*9
|
|
|
|
elif self.cat == "invocateur":
|
|
|
|
attaque = attaque + self.exp*6
|
|
|
|
elif self.cat == "loup-garou":
|
|
|
|
attaque = attaque + self.exp*8
|
|
|
|
return attaque
|
|
|
|
|
|
|
|
def jet_defense(self):
|
|
|
|
defense = randint(1,20)
|
|
|
|
if self.cat == "guerrier":
|
|
|
|
defense = defense + self.exp*6
|
|
|
|
elif self.cat == "mage":
|
|
|
|
defense = defense + self.exp*8
|
|
|
|
elif self.cat == "voleur":
|
|
|
|
defense = defense + self.exp*4
|
|
|
|
elif self.cat == "elfe":
|
|
|
|
defense = defense + self.exp*5
|
|
|
|
elif self.cat == "orc":
|
|
|
|
defense = defense + self.exp*6
|
|
|
|
elif self.cat == "invocateur":
|
|
|
|
defense = defense + self.exp*5
|
|
|
|
elif self.cat == "loup-garou":
|
|
|
|
defense = defense + self.exp*6
|
|
|
|
return defense
|
|
|
|
|
|
|
|
def change_pdv(self, nb_pdv):
|
|
|
|
self.pdv += nb_pdv
|
|
|
|
|
|
|
|
def change_exp(self, nb_exp):
|
|
|
|
self.exp += nb_exp
|
|
|
|
|
|
|
|
def affiche_caracteristiques(self): #Permet d'afficher les caracteristiques de votre personnage
|
|
|
|
print(" ")
|
|
|
|
print("Le nom de votre personnage est:", self.nom,".")
|
|
|
|
print("Votre personnage est un(e):", self.cat,".")
|
|
|
|
if self.pdv < 0:
|
|
|
|
print("Votre personnage possède 0 points de vie.")
|
|
|
|
else:
|
|
|
|
print("Votre personnage possède", self.pdv, "points de vie.")
|
|
|
|
print("Votre personnage possède", self.exp, "d'experience.")
|
|
|
|
|
|
|
|
def affiche_inventaire(self): #Permet d'afficher l'inventaire du personnage
|
|
|
|
print("Inventaire de votre personnage:", self.inv)
|
|
|
|
|
|
|
|
|
|
|
|
nomP1 = input("Joueur 1, quel est votre nom ?: ")
|
|
|
|
nomP2 = input("Joueur 2, quel est votre nom ?: ")
|
|
|
|
catP1 = input("Joueur 1, choisissez votre catégorie entre guerrier, mage, voleur, elfe, orc, invocateur et loup-garou: ")
|
|
|
|
while not catP1 in ["guerrier", "mage", "voleur","elfe", "orc","invocateur", "loup-garou"]:
|
|
|
|
catP1 = input("Joueur 1, choisissez votre catégorie entre guerrier, mage, voleur, elfe, orc, invocateur et loup-garou: ")
|
|
|
|
catP2 = input("Joueur 2, choisissez votre catégorie entre guerrier, mage, voleur, elfe, orc, invocateur et loup-garou :")
|
|
|
|
while not catP2 in ["guerrier", "mage", "voleur","elfe", "orc", "invocateur", "loup-garou"]:
|
|
|
|
catP2 = input("Joueur 2, choisissez votre catégorie entre guerrier, mage, voleur, elfe, orc, invocateur et loup-garou: ")
|
|
|
|
P1 = Personnage(nomP1, catP1)
|
|
|
|
P2 = Personnage(nomP2, catP2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
J1 = (nomP1, 20, 1, catP1)
|
|
|
|
J2 = (nomP2, 20, 1, catP2)
|
|
|
|
c.execute("INSERT or REPLACE INTO Perso VALUES (?, ?, ?, ?)", J1)
|
|
|
|
c.execute("INSERT or REPLACE INTO Perso VALUES (?, ?, ?, ?)", J2)
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
print("-----------------------------")
|
|
|
|
while P1.pdv > 0 and P2.pdv > 0:
|
|
|
|
print("---Phase 1 du tour (", nomP1,"attaque)---")
|
|
|
|
atkP1 = P1.jet_attaque()
|
|
|
|
defP2 = P2.jet_defense()
|
|
|
|
if atkP1 > defP2:
|
|
|
|
perte_pdv = -randint(1,8)
|
|
|
|
print(nomP1, "attaque", nomP2, "!!!", nomP2,"vient de perdre", -perte_pdv, "point(s) de vie.")
|
|
|
|
P2.change_pdv(perte_pdv)
|
|
|
|
if P2.pdv > 0:
|
|
|
|
pdv2 = (P2.pdv, nomP2,)
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv2)
|
|
|
|
conn.commit()
|
|
|
|
else:
|
|
|
|
pdv2 = (0, nomP2,)
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv2)
|
|
|
|
conn.commit()
|
|
|
|
else:
|
|
|
|
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.")
|
|
|
|
P1.change_pdv(perte_pdv)
|
|
|
|
if P1.pdv > 0:
|
|
|
|
pdv1 = (P1.pdv, nomP1,)
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv1)
|
|
|
|
conn.commit()
|
|
|
|
else:
|
|
|
|
pdv1 = (0, nomP1,)
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv1)
|
|
|
|
conn.commit()
|
|
|
|
P1.affiche_caracteristiques()
|
|
|
|
P2.affiche_caracteristiques()
|
|
|
|
print("")
|
|
|
|
if P1.pdv > 0 and P2.pdv <= 0:
|
|
|
|
P1.change_exp(1)
|
|
|
|
print("Le joueur", nomP1, "a gagné.")
|
|
|
|
break
|
|
|
|
elif P1.pdv <= 0 and P2.pdv > 0:
|
|
|
|
P2.change_exp(1)
|
|
|
|
print("Le joueur", nomP2, "a gagné.")
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
print("-----------------------------------")
|
|
|
|
if P1.pdv > 0 and P2.pdv > 0:
|
|
|
|
input("~~~Veuillez appuyer sur Entrée~~~")
|
|
|
|
print("-----------------------------------")
|
|
|
|
print(" ")
|
|
|
|
|
|
|
|
|
|
|
|
print("---Phase 2 du tour (", nomP2,"attaque)---")
|
|
|
|
defP1 = P1.jet_defense()
|
|
|
|
atkP2 = P2.jet_attaque()
|
|
|
|
if atkP2 > defP1:
|
|
|
|
perte_pdv = -randint(1,8)
|
|
|
|
print(nomP2, "attaque", nomP1, "!!!", nomP1,"vient de perdre", -perte_pdv, "point(s) de vie.")
|
|
|
|
P1.change_pdv(perte_pdv)
|
|
|
|
if P1.pdv > 0:
|
|
|
|
pdv1 = (P1.pdv, nomP1,)
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv1)
|
|
|
|
conn.commit()
|
|
|
|
else:
|
|
|
|
pdv1 = (0, nomP1,)
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv1)
|
|
|
|
conn.commit()
|
|
|
|
else:
|
|
|
|
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.")
|
|
|
|
P2.change_pdv(perte_pdv)
|
|
|
|
if P2.pdv > 0:
|
|
|
|
pdv2 = (P2.pdv, nomP2,)
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv2)
|
|
|
|
conn.commit()
|
|
|
|
else:
|
|
|
|
pdv2 = (0, nomP2,)
|
|
|
|
c.execute("UPDATE Perso SET pdv = (?) WHERE nom = (?)", pdv2)
|
|
|
|
conn.commit()
|
|
|
|
P1.affiche_caracteristiques()
|
|
|
|
P2.affiche_caracteristiques()
|
|
|
|
if P1.pdv > 0 and P2.pdv <= 0:
|
|
|
|
P1.change_exp(1)
|
|
|
|
print("Le joueur", nomP1, "a gagné.")
|
|
|
|
elif P1.pdv <= 0 and P2.pdv > 0:
|
|
|
|
P2.change_exp(1)
|
|
|
|
print("Le joueur", nomP2, "a gagné.")
|
|
|
|
|
|
|
|
print("-----------------------------------")
|
|
|
|
if P1.pdv > 0 and P2.pdv > 0:
|
|
|
|
input("~~~Veuillez appuyer sur Entrée~~~")
|
|
|
|
print("-----------------------------------")
|
|
|
|
print(" ")
|
|
|
|
|
|
|
|
conn.close()
|