combat.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # -*-coding:Latin-1 -*
  2. """combat"""
  3. import lancer
  4. from personnage import Personnage
  5. class Pion():
  6. """representation d'un personnage sur la carte de combat, PJ ou PNJ"""
  7. def __init__(self, perso, x, y):
  8. self.perso = Personnage().charger(perso)
  9. self.position = (x, y)
  10. self.hauteur = 0
  11. self.etat = {}
  12. self.courage = 0
  13. def deplacer(self, x, y):
  14. """deplace le perso au coordonnées (tuple) indiquees"""
  15. self.position = (x, y)
  16. class Combat():
  17. """creer et suivre un combat"""
  18. def __init__(self):
  19. self.lstCombattants={}
  20. self.tour = 1
  21. def tourSuivant(self):
  22. """passe au tour suivant"""
  23. self.tour+=1
  24. def nouveau(self, nomPerso, x, y):
  25. """ajoute un combattant sur le terrain a un emplacement donne"""
  26. i=2
  27. #on vérifie si un combattant portant ce nom existe:
  28. if nomPerso in self.lstCombattants:
  29. #si c'est le cas, on renomme le nouveau (en commençant à 2)
  30. while "{} {}".format(nomPerso,i) in self.lstCombattants:
  31. i+=1
  32. identifiant = "{} {}".format(nomPerso,i)
  33. else:
  34. identifiant = "{}".format(nomPerso)
  35. print("{} cree".format(identifiant))
  36. self.lstCombattants[identifiant] = Pion(nomPerso, x, y)
  37. return identifiant
  38. def PJ(self, nomPerso, position):
  39. """ cree un pion de joueur"""
  40. def PNJ(self, nomPerso, position):
  41. """ cree un pion de non-joueur"""
  42. identifiant = self.nouveau(nomPerso)
  43. self.lstCombattants[identifiant].deplacer(position)
  44. if __name__ == "__main__":
  45. # si lancement direct:
  46. c = Combat()
  47. saisie = ""
  48. while not saisie == "ok":
  49. saisie = raw_input("Ajouter un combattant? "\
  50. "\n - nom;position"\
  51. "\n - 'ok' pour cesser d'en ajouter \n")
  52. if saisie != "ok" and saisie != "":
  53. try:
  54. nom = saisie.split(";")[0]
  55. except:
  56. nom = saisie
  57. try:
  58. position = saisie.split(";")[1]
  59. x = position.split(",")[0]
  60. y = position.split(",")[1]
  61. except:
  62. x=1
  63. y=1
  64. c.nouveau(nom, x, y)
  65. print("{} combattants sur le terrain: {}".format(len(c.lstCombattants), c.lstCombattants))