(no commit message)
[asgard.git] / consolecontroller.py
blob79663888d1fee13bf7b33b21a7b165d23d174f69
1 ########################################################
2 #Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors
3 #This file is part of Asgard.
5 #Asgard is free software; you can redistribute it and/or modify
6 #it under the terms of the GNU General Public License as published by
7 #the Free Software Foundation; either version 2 of the License, or
8 #(at your option) any later version.
10 #Asgard is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with Asgard; if not, write to the Free Software
17 #Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 ########################################################
19 from battle import *
21 class ConsoleController:
22 def __init__(self,debug,battle,view):
23 self.__debug = debug
24 self.__battle = battle
25 self.__view = view
27 battle.setController(self)
28 battle.setView(view)
29 view.setController(self)
30 view.setBattle(battle)
32 self.__gameLoop()
34 def getCommand(self,p,f):
36 command = []
38 print "\033[1;34m[SELCT]\033[1;0m Turn:" + f.getName() + "; HP:" + str(f.getHp())
40 self.__view.printEnemySelectMenu(p)
41 n = raw_input("% ")
42 d = p.getFighter(int(n)-1)
44 self.__view.printEventTypeMenu(f)
45 n = raw_input("% ")
46 t = f.getEventTypes()[int(n)-1]
48 return [d,t]
50 def getDebug(self):
51 return self.__debug
53 def setDebug(self,d):
54 self.__debug = d
56 def __gameLoop(self):
57 """Retrieves events from Parties and Executes all Events in queue per iteration"""
59 print "Battle Starts."
60 self.__view.printState()
62 # initialize the event checker boolean
63 wereEvents = False
65 while not self.__battle.isOver():
66 # next iteration
67 wereEvents = self.__battle.nextTurn()
69 # only print out state if something actually happened
70 if wereEvents:
71 self.__view.printState()
73 if self.__battle.getParty1().isAlive():
74 # sum exp from enemy party
75 exp = 0
76 for f in self.__battle.getParty2().getFighters():
77 exp += f.getExp()
79 # hero party gets exp
80 self.__battle.getParty1().giveExp(exp)
82 print "Victory Fanfare. Heros win "+str(exp)+" exp!"
83 else:
84 print "Game Over. Orcs win."