Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. '''game.py: This is the main class of the game.'''
  2.  
  3. import os
  4. import random
  5. import sys
  6. from blessings import Terminal
  7.  
  8. from bureaucrat import Bureaucrat
  9. from character import Character
  10.  
  11. t = Terminal()
  12.  
  13.  
  14. class Game:
  15.     '''The main logic of the game'''
  16.     def __init__(self):
  17.         self.clear_screen()
  18.         print(t.underline('LAM-40 0.3'))
  19.         self.character = Character()
  20.         self.bureaucrat = Bureaucrat()
  21.         while True:
  22.             self.act()
  23.  
  24.     def act(self):
  25.         '''An action taken by the player.'''
  26.         # the following loop numerically lists all available actions
  27.         for number, action in enumerate(self.character.actions):
  28.             number = str(number + 1)
  29.             print(number + '. ' + action)
  30.         self.action = input('\nWhat will you do? ').lower()
  31.         if self.action == 'q':  # quits the game
  32.             self.clear_screen()
  33.             sys.exit('Thank you for playing LAM-40.\n')
  34.         elif self.action == 'w':  # creates a new bureaucrat
  35.             self.bureaucrat = Bureaucrat()
  36.         elif self.action in 'abcdefhijklmpstyw':
  37.             self.react()  # finds out what type of action was chosen
  38.             self.calculate_odds()  # alters the odds of success
  39.             self.evaluate_success()  # determines success or failure
  40.         else:  # incorrect input is given
  41.             print('\nIncorrect action. Please try again.\n')
  42.  
  43.     def react(self):
  44.         '''A reaction to the choice of the player.'''
  45.         if self.action == 'bt':  # character.py for reference
  46.             self.character.probability_is_low()
  47.             self.character.asc_rank_asc_mood()
  48.         elif self.action in 'cp':
  49.             self.character.probability_is_high()
  50.             self.character.desc_rank_desc_mood()
  51.         elif self.action in 'dm':
  52.             self.character.probability_is_low()
  53.             self.character.desc_rank_desc_mood()
  54.         elif self.action in 'efj':
  55.             self.character.probability_is_high()
  56.             self.character.asc_rank_asc_mood()
  57.         elif self.action in 'hkly':
  58.             self.character.probability_is_low()
  59.             self.character.desc_rank_asc_mood()
  60.         elif self.action in 'is':
  61.             self.character.probability_is_high()
  62.             self.character.asc_rank_desc_mood()
  63.         else:  # 'a' (ask)
  64.             self.character.probability_is_high()
  65.             self.character.desc_rank_asc_mood()
  66.  
  67.     def calculate_odds(self):
  68.         '''Calculates the odds of a successful action.'''
  69.         # odds of success are randomly assigned to be 25-75% at first
  70.         self.odds = float(random.choice(range(25, 76)))
  71.         if self.bureaucrat.rank == 'low':
  72.             if self.character.asc_rank is True:  # character.py for reference
  73.                 self.odds /= self.character.divisor
  74.             else:
  75.                 self.odds *= self.character.multiplier
  76.         elif self.bureaucrat.rank == 'high':
  77.             if self.character.asc_rank is True:
  78.                 self.odds *= self.character.multiplier
  79.             else:
  80.                 self.odds /= self.character.divisor
  81.         else:
  82.             pass  # medium rank doesn't affect the odds
  83.         if self.bureaucrat.mood == 'bad':
  84.             if self.character.asc_mood is True:
  85.                 self.odds /= self.character.divisor
  86.             else:
  87.                 self.odds *= self.character.multiplier
  88.         elif self.bureaucrat.mood == 'good':
  89.             if self.character.asc_mood is True:
  90.                 self.odds *= self.character.multiplier
  91.             else:
  92.                 self.odds /= self.character.divisor
  93.         else:
  94.             pass  # average mood doesn't affect the odds
  95.  
  96.     def evaluate_success(self):
  97.         '''Evaluates whether the action is successful or not.'''
  98.         # the higher self.odds value
  99.         # the higher the chance the action will succeed
  100.         self.luck = random.choice(range(0, 101))
  101.         if self.luck > self.odds:
  102.             self.bureaucrat.react_negatively()
  103.         else:
  104.             self.bureaucrat.react_positively()
  105.  
  106.     def clear_screen(self):
  107.         '''Clears the screen of the terminal.'''
  108.         if os.name == 'nt':  # 'nt' equals Windows
  109.             os.system('cls')
  110.         else:
  111.             os.system('clear')  # Mac OS and Linux
  112.  
  113. Game()