Skip to content

Instantly share code, notes, and snippets.

@TakesTheBiscuit
Created October 22, 2018 21:49
Show Gist options
  • Save TakesTheBiscuit/3150a025fc8f0820e68cdd5d7e072690 to your computer and use it in GitHub Desktop.
Save TakesTheBiscuit/3150a025fc8f0820e68cdd5d7e072690 to your computer and use it in GitHub Desktop.
Python example of a class, picture a terrible version of GTA - yeah, this isn't it
class PoliceMan:
def __init__(self, health, attack, speed):
self.health = health
self.attack = attack
self.speed = speed
self.name = 'PoliceManDEPT101'
# slow fat one has 100 hp, 10 attack, and moves at 25 speed
SlowFatOne = PoliceMan(100.00,10.00,25.00)
print( 'SlowFatOne, moves at ' + repr(SlowFatOne.speed));
# FastOne has 100 hp, 10 attack, and moves at 500 speed !
FastOne = PoliceMan(100.00,10.00,500.00)
print( 'FastOne, moves at ' + repr(FastOne.speed));
# give SlowFatOne a donut and..
SlowFatOne.speed = 250.00;
print( 'SlowFatOne ate a donut, now moves at ' + repr(SlowFatOne.speed));
# give FastOne a big lunch and..
FastOne.speed -= 100.00;
print( 'FastOne had a big lunch, now moves at ' + repr(FastOne.speed));
# give FastOne lots of vodka, and.. he can't aim
FastOne.attack = 1.00;
print( 'FastOne had loads of vodka, now cannot aim ' + repr(FastOne.attack));
# make lots of police!
squad = {'Murtaza': 100, 'Sjoerd': 200, 'Jack': 500, 'Dcab': 220}
for name, speed in squad.items():
print(name + ' moves at ' + repr(speed))
# name our fast one so we can see his name
FastOne.name = 'TakesTheBiscuit'
# lets have the police chase after the FastOne and see if they win
for name, speed in squad.items():
wins = (1 if speed > FastOne.speed else 0)
if (wins):
print('** ' + name + ' wins against ' + FastOne.name + '!')
else:
print(FastOne.name + ' beats ' + name + '!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment