| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- # -*-coding:Latin-1 -*
- """combat"""
- import lancer
- from personnage import Personnage
- class Pion():
- """representation d'un personnage sur la carte de combat, PJ ou PNJ"""
- def __init__(self, perso, x, y):
- self.perso = Personnage().charger(perso)
- self.position = (x, y)
- self.hauteur = 0
- self.etat = {}
- self.courage = 0
- def deplacer(self, x, y):
- """deplace le perso au coordonnées (tuple) indiquees"""
- self.position = (x, y)
- class Combat():
- """creer et suivre un combat"""
- def __init__(self):
- self.lstCombattants={}
- self.tour = 1
-
- def tourSuivant(self):
- """passe au tour suivant"""
- self.tour+=1
- def nouveau(self, nomPerso, x, y):
- """ajoute un combattant sur le terrain a un emplacement donne"""
- i=2
- #on vérifie si un combattant portant ce nom existe:
- if nomPerso in self.lstCombattants:
- #si c'est le cas, on renomme le nouveau (en commençant à 2)
- while "{} {}".format(nomPerso,i) in self.lstCombattants:
- i+=1
- identifiant = "{} {}".format(nomPerso,i)
- else:
- identifiant = "{}".format(nomPerso)
-
- print("{} cree".format(identifiant))
- self.lstCombattants[identifiant] = Pion(nomPerso, x, y)
- return identifiant
-
- def PJ(self, nomPerso, position):
- """ cree un pion de joueur"""
- def PNJ(self, nomPerso, position):
- """ cree un pion de non-joueur"""
- identifiant = self.nouveau(nomPerso)
- self.lstCombattants[identifiant].deplacer(position)
- if __name__ == "__main__":
- # si lancement direct:
- c = Combat()
- saisie = ""
- while not saisie == "ok":
- saisie = raw_input("Ajouter un combattant? "\
- "\n - nom;position"\
- "\n - 'ok' pour cesser d'en ajouter \n")
- if saisie != "ok" and saisie != "":
- try:
- nom = saisie.split(";")[0]
- except:
- nom = saisie
-
- try:
- position = saisie.split(";")[1]
- x = position.split(",")[0]
- y = position.split(",")[1]
- except:
- x=1
- y=1
-
- c.nouveau(nom, x, y)
- print("{} combattants sur le terrain: {}".format(len(c.lstCombattants), c.lstCombattants))
-
|