'''game.py: This is the main class of the game.'''
import os
import sys
from blessings import Terminal
from bureaucrat import Bureaucrat
t = Terminal()
class Game:
'''The main logic of the game'''
def __init__(self):
self.clear_screen()
print(t.underline('LAM-40 0.2'))
self.bureaucrat = Bureaucrat()
self.bureaucrat.greet()
while True:
self.act()
if self.bureaucrat.negative is False:
self.bureaucrat = Bureaucrat()
self.bureaucrat.greet()
def clear_screen(self):
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
def act(self):
'''An action taken by the player.'''
self.actions = ['[A]sk', '[B]ribe', '[E]ntreat',
'[P]ress', '[T]hreaten',
'[W]ait', '[Q]uit']
for number, action in enumerate(self.actions):
number = str(number + 1)
print(number + '. ' + action)
self.action = input('\nWhat will you do? ').lower()
if self.action == 'q' or self.action == '7':
self.clear_screen()
print('Thank you for playing LAM-40.\n')
sys.exit()
elif self.action == 'w' or self.action == '6':
self.bureaucrat.negative = False
else:
self.react()
def react(self):
'''A reaction to the choice of the player.'''
if self.bureaucrat.mood == 'good' and self.bureaucrat.rank == 'low':
if self.action == 'a' or self.action == '1':
self.bureaucrat.react_positively()
else:
self.bureaucrat.react_negatively()
elif self.bureaucrat.mood == 'good' and self.bureaucrat.rank == 'high':
if self.action == 'b' or self.action == '2':
self.bureaucrat.react_positively()
else:
self.bureaucrat.react_negatively()
elif self.bureaucrat.mood == 'average' and self.bureaucrat.rank == 'high':
if self.action == 'e' or self.action == '3':
self.bureaucrat.react_positively()
else:
self.bureaucrat.react_negatively()
elif self.bureaucrat.mood == 'average' and self.bureaucrat.rank == 'low':
if self.action == 'p' or self.action == '4':
self.bureaucrat.react_positively()
else:
self.bureaucrat.react_negatively()
elif self.bureaucrat.mood == 'bad' and self.bureaucrat.rank == 'low':
if self.action == 't' or self.action == '5':
self.bureaucrat.react_positively()
else:
self.bureaucrat.react_negatively()
else:
self.bureaucrat.react_negatively()
Game()