<reponame>sha31dev/py_ioc
import py_ioc as ioc
import random
from typing import List


class Gun():
    def __init__(self, bullets: int):
        self.bullets = bullets

    def fire(self):
        self.bullets = self.bullets - 1

    def check_bullets(self):
        return self.bullets


class Soldier():
    def __init__(self, gun: Gun):
        self.gun = gun

    def fire(self):
        self.gun.fire()

    def check_bullets(self):
        return self.gun.check_bullets()

class Army():
    def __init__(self, soldiers: List[Soldier]):
        self.soldiers = soldiers

    def random_fire(self):
        index = random.randint(0, len(self.soldiers) - 1)
        self.soldiers[index].fire()

    def squad_fire(self):
        for soldier in self.soldiers:
            soldier.fire()

    def check_bullets(self):
        for index, soldier in enumerate(self.soldiers):
            print(f'Soldier {index}, Bullets: {soldier.check_bullets()}')


if __name__ == '__main__':
    container = ioc.build([
        './examples/config.yml'
    ])

    army = container.get('army')

    army.random_fire()
    army.check_bullets()

    army.squad_fire()
    army.check_bullets()

    # Can be used to inject dependencies in functions as well.
    uuid = container.get('uuid')
    print(uuid)

import py_ioc as ioc
import random
from typing import List


class Gun():
    def __init__(self, bullets: int):
        self.bullets = bullets

    def fire(self):
        self.bullets = self.bullets - 1

    def check_bullets(self):
        return self.bullets


class Soldier():
    def __init__(self, gun: Gun):
        self.gun = gun

    def fire(self):
        self.gun.fire()

    def check_bullets(self):
        return self.gun.check_bullets()

class Army():
    def __init__(self, soldiers: List[Soldier]):
        self.soldiers = soldiers

    def random_fire(self):
        index = random.randint(0, len(self.soldiers) - 1)
        self.soldiers[index].fire()

    def squad_fire(self):
        for soldier in self.soldiers:
            soldier.fire()

    def check_bullets(self):
        for index, soldier in enumerate(self.soldiers):
            print(f'Soldier {index}, Bullets: {soldier.check_bullets()}')


if __name__ == '__main__':
    container = ioc.build([
        './examples/config.yml'
    ])

    army = container.get('army')

    army.random_fire()
    army.check_bullets()

    army.squad_fire()
    army.check_bullets()

    # Can be used to inject dependencies in functions as well.
    uuid = container.get('uuid')
    print(uuid)
# Can be used to inject dependencies in functions as well.