class Player(Turtle): def __init__(self, maxMana, maxHealth, shapeNumber, canvas, x, y): RawTurtle.__init__(self, canvas) self.speed(0) self.penup() self.goto(x, y) self.mana = maxMana self.health = maxHealth self.weapon = Weapon(canvas, 50, 200, 30, 5, 1, self.xcor(), self.ycor()) #self.shape("Player" + str(shapeNumber)) def decreaseHealth(self, damage): self.health = self.health - damage def attack(self): if self.weapon.canActivate(self.mana): self.weapon.disaMove(self.xcor(), self.ycor()) self.weapon.activate() self.addMana(-self.weapon.getManaCost()) def addMana(self, manaAdd): self.mana += manaAdd def getWeapon(self): return self.weapon def goUp(self): if self.ycor() + 5 > 500: return self.goto(self.xcor(), self.ycor() + 5) if not self.weapon.isActivated(): self.weapon.disaMove(self.xcor(), self.ycor()) def goDown(self): if self.ycor() - 5 < 0: return self.goto(self.xcor(), self.ycor() - 5) if not self.weapon.isActivated(): self.weapon.disaMove(self.xcor(), self.ycor()) def goLeft(self): if self.xcor() - 5 < 0: return self.goto(self.xcor() - 5, self.ycor()) if not self.weapon.isActivated(): self.weapon.disaMove(self.xcor(), self.ycor()) def goRight(self): if self.xcor() + 5 > 500: return self.goto(self.xcor() + 5, self.ycor()) if not self.weapon.isActivated(): self.weapon.disaMove(self.xcor(), self.ycor())
class Enemy(Turtle): def __init__(self, canvas, x, y): RawTurtle.__init__(self, canvas) self.speed(0) self.penup() self.goto(x, y) self.shape("turtle") self.dx = 5 self.dy = 5 self.health = 100 self.mana = 100 self.attack1 = Weapon(canvas, 10, 20, 30, 0, 2, self.xcor(), self.ycor()) def moveUp(self): x = self.xcor() y = self.ycor() + self.dy self.goto(x, y) def moveDown(self): x = self.xcor() y = self.ycor() - self.dy self.goto(x, y) def moveRight(self): x = self.xcor() + self.dx y = self.ycor() self.goto(x, y) def moveLeft(self): x = self.xcor() - self.dx y = self.ycor() self.goto(x, y) def checkIfPlayerIsInRange(self, player): if self.ycor() + self.attack1.getAttackDistanceY() - player.ycor( ) > 0 and self.xcor() + self.attack1.getAttackDistanceX( ) - player.xcor() > 0: return True return False def attack(self, player): if self.checkIfPlayerIsInRange(player) and self.attack1.canActivate( self.mana): self.attack1.activate() player.decreaseHealth(self.attack1.getDamage()) self.addMana(-self.attack1.getManaCost()) def decreaseHealth(self, damage): self.health -= damage def addMana(self, manaAdd): self.mana += manaAdd def artificialIntelegence(self, player): while (True): self.attack(player) if player.xcor() > self.xcor(): self.moveRight() elif player.xcor() < self.xcor(): self.moveLeft() if player.ycor() > self.ycor(): self.moveUp() elif player.ycor() < self.ycor(): self.moveDown() for x in range(1, 1000000): x + 1 def isDead(self): if self.health < 0: return True return False def kill(self): self.hideturtle()