1 ########################################################
2 # Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors
3 # This file is part of Asgard.
4 # Asgard is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # Asgard is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Asgard; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 ########################################################
19 from os
import listdir
28 self
.__currentTime
= 0
31 ### Creating parties ###
32 # Reading data for parties
33 dir = listdir('./data/party/')
41 lines
= fptr
.readlines()
42 if int(lines
[0]) == 1:
43 self
.__party
1 = Party(lines
[1].strip())
44 elif int(lines
[0]) == 2:
45 self
.__party
2 = Party(lines
[1].strip())
48 ### Creating fighters ###
49 # Reading data for fighters
50 dir = listdir('./data/fighter/')
52 # f cannot be a "." file
55 # Change file into pathname
56 f
= './data/fighter/'+f
57 # Open file f for 'r'eading
59 # Place lines in file f into list
60 lines
= fptr
.readlines()
62 tom
= round((1/float(lines
[4]))*100)
63 equip
= Equiption(lines
[6].strip(),lines
[7].strip(),lines
[8].strip(),lines
[9].strip())
64 # Create fighter(name,hp,str,dex,head,l,r,body)
65 fighter1
= Fighter(lines
[0].strip(),int(lines
[2]),int(lines
[3]),int(lines
[4]),tom
,bool(int(lines
[5])),equip
)
68 # Add fighter to respective party (1 or 2)
69 if int(lines
[10]) == 1:
70 self
.__party
1.addFighter(fighter1
)
71 elif int(lines
[10]) == 2:
72 self
.__party
2.addFighter(fighter1
)
77 """ Is battle over?"""
79 return not self
.__party
1.isAlive() or not self
.__party
2.isAlive()
82 """ Execute next iteration in gameloop."""
88 # execute all available events
89 while self
.executeNextEvent():
90 # if there was at least one event
94 self
.__currentTime
+= 1
98 def executeNextEvent(self
):
99 """ Execute next event in event queue."""
104 # Try to get an event from party1
105 event
= self
.__party
1.getNextEvent(self
.__party
2,self
.__currentTime
,self
.__controller
)
107 # If there was one, execute and return true
109 self
.__view
.printEvent(event
)
113 # Try to get an event from party2
114 event
= self
.__party
2.getNextEvent(self
.__party
1,self
.__currentTime
,self
.__controller
)
116 # If there was one, execute and return true
118 self
.__view
.printEvent(event
)
122 # Otherwise, notify that there are no more events at this time.
125 def getCurrentTime(self
):
126 """ Retrieve current time."""
127 return self
.__currentTime
129 def setCurrentTime(self
,t
):
130 """ Establish current time."""
131 self
.__currentTime
= t
134 """ Retrieve party1."""
138 """ Retrieve party2."""
142 """ Establish view."""
145 def setController(self
,c
):
146 """ Establish controller."""
147 self
.__controller
= c