Hi guys,
New to coding and new to Code Combat - no surprise. I am learning in Python and have had some issues with some of the levels but have always managed to troubleshoot my way through. Unfortunately I have hit a brick wall and simply cannot see what is wrong with the coding.
Firstly, I know the coordinates are slightly off - the left hand X should be 35, 34 however if I set it to that then a munchkin passes me and kills a villager before cleave strikes. The second coordinates for the right X should be 60,31 but I have put them slightly closer to the centre to try and offset the issue which is happening. Here is the issue:
findAndAttackEnemy does not appear to trigger when moving to the right side to fend off 1 munchkin. My hero ignores the munchkin that starts to attack the hero and then as the hero patrols back to the left side the munchkin attacks a villager and I fail the mission.
I have no issues with the coding for cleaving - which is odd as this is user created whereas the “findAndAttackEnemy” definition is already created and seems to be the definition I am having challenges with. I have reloaded and rewritten a few times but I cannot see what the issue is. Assistance PLEASE so I can learn and move on.
# This function attacks the nearest enemy.
def findAndAttackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
# Define a function to cleave enemies (but only when the ability is ready).
def findAndCleaveEnemy():
# Find the nearest enemy:
enemy = hero.findNearestEnemy()
# If an enemy exists:
if enemy:
# And if "cleave" is ready:
if hero.isReady("cleave"):
# It's time to cleave!
hero.cleave(enemy)
pass
# In your main loop, patrol, cleave, and attack.
while True:
# Move to the patrol point, cleave, and attack.
hero.moveXY(38, 34)
findAndCleaveEnemy()
findAndAttackEnemy()
# Move to the other point:
hero.moveXY(56, 30)
# Use findAndCleaveEnemy function:
findAndCleaveEnemy
# Use findAndAttackEnemy function:
findAndAttackEnemy
Thanks so much in advance!