1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
import random
import mysql.connector
global Type
global Nom
global Race
global nom
# Tirage au sort des caractéristiques
class Personnage():
def __init__(self):
self.Nom=nom
self.Type=""
self.Race=""
self.F = random.randint(5, 16)
self.C = random.randint(5, 16)
self.I = random.randint(5, 16)
self.A = random.randint(5, 16)
self.Pv= 80
self.Def= 20
self.Rm= 20
self.Xp=1
self.Ba=0
self.Bd=0
self.Niv=1
def Print_Caract():
print("Force : ",nom.F)
print("Charisme : ",nom.C)
print("Intelligence : ",nom.I)
print("Agilité : ",nom.A)
def Print_Tous():
for attr, value in vars(nom).items():
print(attr, '=', value)
def Sql_Guillemet(val):
for value in val:
value = '"', value,'"'
# modification des caractéristiques en fonction de la classe du personnage
def Type(nom, type):
global Type
#guerrier
if type == 0:
nom.F += 4
nom.C -= 2
nom.I -= 1
nom.A -= 1
nom.Pv += 10
nom.Rm -= 10
nom.Def += 10
nom.Type = "Guerrier"
#Voleur
elif type == 1:
nom.F -= 2
nom.C -= 1
nom.I -= 1
nom.A += 4
nom.Def += 20
nom.Bd += 1
nom.Type = "Voleur"
#Magicien
elif type == 2:
nom.F -= 2
nom.C -= 1
nom.I += 4
nom.A -= 1
nom.Pv -= 10
nom.Rm += 20
nom.Type = "Magicien"
# Choix de la race
def Race(nom, race):
global Race
#Nain
if race == 0:
nom.F += 2
nom.C -= 2
nom.I += 1
nom.A -= 1
nom.Race="Nain"
#Elfe
elif race == 1:
nom.F -= 2
nom.C += 1
nom.I -= 1
nom.A += 2
nom.Race="Elfe"
#humain
elif race == 2:
nom.F = nom.F
nom.C = nom.C
nom.I = nom.I
nom.A = nom.A
nom.Race="Humain"
#Semiorc
elif race == 3:
nom.F += 4
nom.C -= 4
nom.I -= 2
nom.A += 2
nom.Race="DemiOrque"
def Mise_En_Sql(SqlVal):
for value in vars(nom).items():
SqlVal.value = "'",value,"'"
for value in SqlVal: print(value)
def Ajout_MaBase():
# Connexion à la base de donnée
import mysql.connector
from mysql.connector import (connection)
cnx = connection.MySQLConnection(user='root', password='',
host='127.0.0.1',
database='jeu')
cursor = cnx.cursor()
# Ajout de la base de donnée de toutes les valeurs
add_jeu= ("INSERT INTO jeu (Nom, Type, Race, Force, Charisme, Intelligence, Agilite, Pv, Def, Xp, Ba, Bd, Niv, Rm)"
"Values ( %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)")
caract=(nom.Nom, nom.Type, nom.Race, nom.F, nom.C, nom.I, nom.A, nom.Pv, nom.Def, nom.Xp, nom.Ba, nom.Bd, nom.Niv, nom.Rm)
#Sql_Guillemet(caract)
#print (caract)
#Mise_En_Sql(caract)
print (caract)
cursor.execute(add_jeu,caract)
cnx.close()
# défnition du perso Nom + caract
nom = input("Quel nom de personnage veux tu ?")
nom = Personnage()
Print_Caract()
choix="non"
# permet de refaire le tirage indéfiniement
choix = input(
"\n veux tu recommencer le tirage ? tapez oui pour recommencer ou n'importe quoi d'autre pour valider vos caractéristiques : ")
while choix=="oui":
nom = Personnage()
Print_Caract()
choix = input(
"\n veux tu recommencer le tirage ? tapez oui pour recommencer ou n'importe quoi d'autre pour valider vos caractéristiques : "
)
# définition de la classe de perso
choix="non"
while choix != "oui":
print("\nQuelle catégorie de perso souhaitez vous créer ?\n")
print(
" 0 Pour Guerrier / Barbare \n 1 Pour Voleur / Assassin \n 2 Pour Magicien / Clerc\n"
)
type = int(input("\Fais ton choix : "))
if type ==0 or type ==1 or type ==2:
Type(nom, type)
Print_Caract()
choix="oui"
choix="non"
while choix != "oui":
# définition de la race du perso
print("\nQuelle race de perso souhaitez vous créer ?\n")
print(
" 0 Pour Nain (petit mais costaud) \n 1 Pour Elfe (un peu frêle mais adroit) \n 2 Pour Humain (pas de modification de classe \n 3 pour Semi-Orque (intelligence et beauté limitée mais une puissance redoutable \n)"
)
race=int(input("\nFais ton choix : "))
if race ==0 or race ==1 or race ==2 or race==3:
Race(nom, race)
Print_Caract()
choix="oui"
else:
choix="non"
print("Les caractéristiques sont : ")
Print_Tous()
Ajout_MaBase() |
Partager