(no commit message)
[asgard.git] / consolecontroller.py
blobca07f8c5ec77e29379497a61f8a9bd4958608804
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 battle import *
21 class ConsoleController:
22 def __init__(self,battle,view,debug):
23 self.__battle = battle
24 self.__view = view
25 self.__debug = debug
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 print "Victory Fanfare. Heros win."
75 else:
76 print "Game Over. Orcs win."