def fightImplementation(self): # [0] is knightHp, [1] is knightLevel, [2] is knightRingSign, [3] is journeyList knight = Knight(self.knightTuple[0], self.knightTuple[1], self.knightTuple[2], self.knightTuple[3]) # Get knight ring sign list knightRingSignList = knight.getRingSignList() index = 1 for journey in knight.getJourneyList(): #Get knight Hp knightHp = knight.getKnightHp() # If knight Hp <= 0 => Lose the game if knightHp <= 0: break # Get index of the journey indexJourney = index # Increase index index += 1 # Create event object # print(str(journey) + " " + str(indexJourney)) eventObj = Event(journey, indexJourney) # [0] is code, [1] is levelO, [2] is ringSignO eventTuple = eventObj.processEvent() # Get Event event = eventTuple[0] # Case finish journey if event == 0: print("Knight finish the competition !") break # Case pass journey elif event == -1: continue knightRingSignList, knightHp = self.processBattleCase( event, knightHp, knight.getKnightMaxHp(), knight.getKnightLevel(), knightRingSignList, eventObj.getLevelO(), eventObj.getRingSignO()) knight.setKnightHp(knightHp) # print(knight.getRingSignList()) stringRingSignList = [str(x) for x in knightRingSignList] stringRingSignList = "".join(stringRingSignList) return stringRingSignList, knight.getKnightHp()
def battle(self): # Set knight attribute knight = Knight(self.knightTuple[0], self.knightTuple[1], self.knightTuple[2], self.knightTuple[3]) knightRingSignList = knight.getRingSignList() index = 1 for journey in knight.getJourneyList(): knightHp = knight.getKnightHP() # If knight Hp <= 0 => Lose the game if knightHp <= 0: print("Knight lose") break # Get journey index indexJourney = index index += 1 # print(str(journey) + " " + str(indexJourney)) eventObj = Event(journey, indexJourney) eventTuple = eventObj.checkEventCode() event = eventTuple[0] if event == 0: print("Knight win") break elif event == -1: continue knightRingSignList, knightHp = self.battleCase( event, knightHp, knight.getKnightMaxHp(), knight.getKnightLevel(), knightRingSignList, eventObj.getLevelO(), eventObj.getRingSignO()) knight.setKnightHp(knightHp) # print(knight.getRingSignList()) stringRingSignList = [str(x) for x in knightRingSignList] stringRingSignList = "".join(stringRingSignList) return stringRingSignList, knight.getKnightHP()