2017-10-04 00:01:49 +03:00
|
|
|
"""`FactoryAggregate` providers example."""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2017-10-04 01:28:31 +03:00
|
|
|
import dependency_injector.providers as providers
|
2017-10-04 00:01:49 +03:00
|
|
|
|
|
|
|
from games import Chess, Checkers, Ludo
|
|
|
|
|
|
|
|
|
2020-07-18 07:40:14 +03:00
|
|
|
game_factory = providers.FactoryAggregate(
|
|
|
|
chess=providers.Factory(Chess),
|
|
|
|
checkers=providers.Factory(Checkers),
|
|
|
|
ludo=providers.Factory(Ludo),
|
|
|
|
)
|
2017-10-04 00:01:49 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
game_type = sys.argv[1].lower()
|
2017-10-13 07:55:29 +03:00
|
|
|
player1 = sys.argv[2].capitalize()
|
|
|
|
player2 = sys.argv[3].capitalize()
|
2017-10-04 01:28:31 +03:00
|
|
|
|
2017-10-13 07:55:29 +03:00
|
|
|
selected_game = game_factory(game_type, player1, player2)
|
2017-10-04 00:01:49 +03:00
|
|
|
selected_game.play()
|
|
|
|
|
2017-10-13 07:55:29 +03:00
|
|
|
# $ python example.py chess John Jane
|
|
|
|
# John and Jane are playing chess
|
|
|
|
#
|
|
|
|
# $ python example.py checkers John Jane
|
|
|
|
# John and Jane are playing checkers
|
|
|
|
#
|
|
|
|
# $ python example.py ludo John Jane
|
|
|
|
# John and Jane are playing ludo
|