Skip to content

Solution set 2 #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
class Player():
def __init__(self,w,x,y,z):
self.name = ""
self.age = w
self.movement_speed = x
self.health = y
self.money = z

def move(self,speed):
if self.health < 0:
print (self.name + "is dead")
else:
self.movement_speed += speed
print (self.name + " is moving at " + str(self.movement_speed))

def stop(self):
if self.health < 0:
print (self.name + " is dead")
else:
self.movement_speed = 0
print ("Movement speed of " + self.name + " is 0, it has stopped")

def take_damage(self,damage):
self.health -= damage
if self.health <= 0:
print (self.name + " is dead")
else:
print ("Health of " + self.name + " is " + str(self.health))

def heal(self,hp):
self.health += hp
print ("Health of " + self.name + " is " + str(self.health))

def make_money(self,cash):
if self.health < 0:
print (self.name + " is dead")
else:
self.money += cash
print ("money of " + self.name + " is " + str(self.money))

def spend_money(self,cheque):
if self.health < 0:
print (self.name + " is dead")
else:
q = self.money - cheque
if q < 0:
print ("cant pay")
else:
self.money -= cheque
print ("money of " + self.name + " is " + str(self.money))

def stats(self):
if self.health < 0:
print (self.name + " is dead")
else:
print("age is " + str(self.age))
print("health is " + str(self.health))
print("speed is " + str(self.movement_speed))
print("money is " + str(self.money))


class Enemy():
def __init__(self,w,x,y,z):
self.name = ""
self.age = w
self.movement_speed = x
self.health = y
self.attack_power = z

def move(self,speed):
if self.health < 0:
print (self.name + " is dead")
else:
self.movement_speed += speed
print (self.name + " is moving at " + str(self.movement_speed))

def stop(self):
if self.health < 0:
print (self.name + " is dead")
else:
self.movement_speed = 0
print ("Movement speed of " + self.name + " is 0, it has stopped")

def heal(self,hp):
self.health += hp
print ("health of " + self.name + " is " + str(self.health))

def booster(self,ammo):
if self.health < 0:
print (self.name + " is dead")
else:
self.attack_power += ammo
print ("attack power of " + self.name + " is " + str(self.attack_power))

def lessen_ammo(self,empty_ammo):
if self.health < 0:
print (self.name + " is dead")
else:
q = self.attack_power - empty_ammo
if q <= 0:
print ("ammo finished")
self.attack_power = 0
print ("ammo gone")
else:
self.attack_power -= empty_ammo
print ("attack power of " + self.name + " is " + str(self.attack_power))

def stats(self):
if self.health < 0:
print (self.name + " is dead")
else:
print("age is " + str(self.age))
print("health is " + str(self.health))
print("speed is " + str(self.movement_speed))
print("attack power is " + str(self.attack_power))

def take_damage(self,damage):
self.health -= damage
if self.health <= 0:
print (self.name + " is dead")
else:
print ("Health of " + self.name + " is " + str(self.health))

def attack(self,Player):
if self.health < 0:
print (self.name + " is dead")
else:
if Player = self.name:
print("Can't suicide")
else:
Player.take_damage(self.attack_power)

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import main_classes as mc

Modi = mc.Player(20,30,40,50)
Modi.move(30)
Modi.stop()
Modi.take_damage(50)
Modi.heal(50)
Modi.spend_money(60)
Modi.make_money(100)
Modi.stats()

Rahul = mc.Enemy(20,30,40,50)
Rahul.move(30)
Rahul.stop()
Rahul.take_damage(50)
Rahul.heal(50)
Rahul.booster(60)
Rahul.lessen_ammo(100)
Rahul.stats()
Rahul.attack(Modi)