/[ambar]/ambar/profesion.py
ViewVC logotype

Diff of /ambar/profesion.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2.0 by pabloruiz, Sat Aug 17 21:11:09 2002 UTC revision 2.1 by pabloruiz, Tue Nov 5 22:58:22 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/env python  #!/usr/bin/env python
2  #  #
3  #Minë. Mundo Interactivo-Narrativo en Español [Tierra-Media]  #Minë. Mundo Interactivo-Narrativo en Español [Tierra-Media]
4  #Copyright (C) 2002  Pablo Ruiz Múzquiz  #Copyright (C) 2002  Pablo Ruiz Múzquiz
5  #  #
6  #  #
7  #This program is free software; you can redistribute it and/or modify  #This program is free software; you can redistribute it and/or modify
8  #it under the terms of the GNU General Public License as published by  #it under the terms of the GNU General Public License as published by
9  #the Free Software Foundation; either version 2 of the License, or  #the Free Software Foundation; either version 2 of the License, or
10  #(at your option) any later version.  #(at your option) any later version.
11  #  #
12  #This program is distributed in the hope that it will be useful,  #This program is distributed in the hope that it will be useful,
13  #but WITHOUT ANY WARRANTY; without even the implied warranty of  #but WITHOUT ANY WARRANTY; without even the implied warranty of
14  #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  #GNU General Public License for more details.  #GNU General Public License for more details.
16  #  #
17  #You should have received a copy of the GNU General Public License  #You should have received a copy of the GNU General Public License
18  #along with this program; if not, write to the Free Software  #along with this program; if not, write to the Free Software
19  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  #  #
21  #Fichero: profesion.py  #Fichero: profesion.py
22    
23  """Clase Profesion."""  """Clase Profesion."""
24    
25    
26  class Profesion:  class Profesion:
27      """Información sobre cualquiera de las profesiones que pueden tener los personajes.      """Información sobre cualquiera de las profesiones que pueden tener los personajes.
28            
29      Una profesion se caracteriza por:      Una profesion se caracteriza por:
30          - nombre (string): identificador de la profesion          - nombre (string): identificador de la profesion
31          - modif_atrib ({String: int}): modificadores a los atributos según la profesión          - modif_atrib ({String: int}): modificadores a los atributos según la profesión
32    
33      Invariantes:      Invariantes:
34        nombre != None        nombre != None
35        modif_atrib != None        modif_atrib != None
36        len(modif_atrib) == 6        len(modif_atrib) == 6
37      """      """
38    
39      def __init__(self, nombre, modif_atrib):      def __init__(self, nombre, modif_atrib):
40          """Crea una nueva instancia de Profesion.          """Crea una nueva instancia de Profesion.
41    
42          No está permitido instanciar más profesiones aparte de las existentes          No está permitido instanciar más profesiones aparte de las existentes
43          dentro de Profesion_lista.          dentro de Profesion_lista.
44    
45          Requiere:          Requiere:
46            nombre != None            nombre != None
47            modif_atrib != None            modif_atrib != None
48            len(modif_atrib) == 6            len(modif_atrib) == 6
49          """          """
50          self.nombre = nombre          self.nombre = nombre
51          self.modif_atrib = modif_atrib          self.modif_atrib = modif_atrib
52    
53            
54  # Lista de todas las profesiones definidas  # Lista de todas las profesiones definidas
55  Profesion_lista = [ Profesion("guerrero",  Profesion_lista = [ Profesion("guerrero",
56                                {"fuerza": +2,                                {"fuerza": +2,
57                                 "destreza": +1,                                 "destreza": +1,
58                                 "constitucion": +1,                                 "constitucion": +1,
59                                 "inteligencia": -1,                                 "inteligencia": -1,
60                                 "sabiduria": -2,                                 "sabiduria": -2,
61                                 "carisma": -1}),                                 "carisma": -1}),
62    
63                      Profesion("explorador",                      Profesion("explorador",
64                                {"fuerza": -1,                                {"fuerza": -1,
65                                 "destreza": +1,                                 "destreza": +1,
66                                 "constitucion": +1,                                 "constitucion": +1,
67                                 "inteligencia": +2,                                 "inteligencia": +2,
68                                 "sabiduria": -2,                                 "sabiduria": -2,
69                                 "carisma": -1}),                                 "carisma": -1}),
70    
71                      Profesion("montaraz",                      Profesion("montaraz",
72                                {"fuerza": -1,                                {"fuerza": -1,
73                                 "destreza": +1,                                 "destreza": +1,
74                                 "constitucion": +1,                                 "constitucion": +1,
75                                 "inteligencia": +1,                                 "inteligencia": +1,
76                                 "sabiduria": +0,                                 "sabiduria": +0,
77                                 "carisma": -2}),                                 "carisma": -2}),
78    
79                      Profesion("bribon",                      Profesion("bribon",
80                                {"fuerza": -1,                                {"fuerza": -1,
81                                 "destreza": +2,                                 "destreza": +2,
82                                 "constitucion": -1,                                 "constitucion": -1,
83                                 "inteligencia": +1,                                 "inteligencia": +1,
84                                 "sabiduria": -2,                                 "sabiduria": -2,
85                                 "carisma": +1}),                                 "carisma": +1}),
86    
87                      Profesion("bardo",                      Profesion("bardo",
88                                {"fuerza": -2,                                {"fuerza": -2,
89                                 "destreza": +0,                                 "destreza": +0,
90                                 "constitucion": -1,                                 "constitucion": -1,
91                                 "inteligencia": +1,                                 "inteligencia": +1,
92                                 "sabiduria": +0,                                 "sabiduria": +0,
93                                 "carisma": +2}),                                 "carisma": +2}),
94    
95                      Profesion("animista",                      Profesion("animista",
96                                {"fuerza": -2,                                {"fuerza": -2,
97                                 "destreza": +0,                                 "destreza": +0,
98                                 "constitucion": -1,                                 "constitucion": -1,
99                                 "inteligencia": +1,                                 "inteligencia": +1,
100                                 "sabiduria": +2,                                 "sabiduria": +2,
101                                 "carisma": +0}) ]                                 "carisma": +0}) ]
102    
103    
104  def Profesion_buscar(nombre):  def Profesion_buscar(nombre):
105      """Obtiene un profesion a partir de su nombre, o None si no existe.      """Obtiene un profesion a partir de su nombre, o None si no existe.
106            
107      Requiere:      Requiere:
108        nombre != None        nombre != None
109      """      """
110      for profesion in Profesion_lista:      for profesion in Profesion_lista:
111          if profesion.nombre == nombre:          if profesion.nombre == nombre:
112              return profesion              return profesion
113      return None      return None
114    
115    
116  # Código para pruebas unitarias del módulo.  # Código para pruebas unitarias del módulo.
117    
118  if (__name__ == '__main__'):  if (__name__ == '__main__'):
119      profesion = Profesion_buscar("guerrero")      profesion = Profesion_buscar("guerrero")
120      print profesion.nombre, profesion.modif_atrib      print profesion.nombre, profesion.modif_atrib
121      profesion = Profesion_buscar("explorador")      profesion = Profesion_buscar("explorador")
122      print profesion.nombre, profesion.modif_atrib      print profesion.nombre, profesion.modif_atrib
123      profesion = Profesion_buscar("montaraz")      profesion = Profesion_buscar("montaraz")
124      print profesion.nombre, profesion.modif_atrib      print profesion.nombre, profesion.modif_atrib
125      profesion = Profesion_buscar("bribon")      profesion = Profesion_buscar("bribon")
126      print profesion.nombre, profesion.modif_atrib      print profesion.nombre, profesion.modif_atrib
127      profesion = Profesion_buscar("bardo")      profesion = Profesion_buscar("bardo")
128      print profesion.nombre, profesion.modif_atrib      print profesion.nombre, profesion.modif_atrib
129      profesion = Profesion_buscar("animista")      profesion = Profesion_buscar("animista")
130      print profesion.nombre, profesion.modif_atrib      print profesion.nombre, profesion.modif_atrib
131    

Legend:
Removed from v.2.0  
changed lines
  Added in v.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26