Created
May 1, 2012 01:07
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Battle: | |
#============================================= | |
# El constructor | |
#============================================= | |
def __init__(self): | |
pass | |
#=========== def build(self, level) =========== | |
# Recibe el nivel del enemigo. | |
# Prepara un objeto Arduino. | |
# Verifica si hay conexion. | |
# Establece un nivel de batalla. | |
# Si hay conexion, entonces creamos al jugador | |
# y al enemigo. | |
# Si no hay conexion, regresamos un cero para | |
# avisar. | |
#============================================= | |
def build(self, level): | |
arduino = ArduinoEEG(9600) | |
isConnected = arduino.connect() | |
self.level = level | |
if(isConnected == 0): | |
self.player = Player(arduino) | |
self.enemy = Enemy(self.level) | |
else: | |
self.level = 0 | |
#============= def start(self) ============== | |
# Solo imprime mensajes de aviso y la magia | |
# inicial de los participantes. | |
# La batalla comienza al presionar la tecla | |
# 'F'. | |
#============================================ | |
def start(self): | |
print '>> Starting battle...' | |
print '\nLEVEL => ' + str(self.level) | |
print 'Focus your magic ...' | |
print 'And press F when you are focused' | |
print '\nPlayer Magic = ' + str(self.player.magic) | |
print 'Enemy Magic = ' + str(self.enemy.magic) | |
#============= def fight(self) ============== | |
# Se encarga de llamar a los metodos de | |
# de recarga de energia de cada uno de los | |
# participantes, durante 5 segundos. | |
# Compara para seleccionar el ganador. | |
#============================================ | |
def fight(self): | |
for i in range(10): | |
self.player.recharge() | |
#self.player.randRecharge() | |
self.enemy.recharge() | |
time.sleep(0.5) | |
winner = self.compare() | |
#============ def compare(self) ============= | |
# Compara la magia final de los participantes | |
# para seleccionar el ganador. | |
# Imprime el ganador en pantalla. | |
#============================================ | |
def compare(self): | |
if(self.player.magic >= self.enemy.magic): | |
print 'Player wins :)' | |
return 1 | |
else: | |
print 'Player loses :(' | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment