Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''game.py: This is the main class of the game.'''
- import os
- import random
- import sys
- from blessings import Terminal
- from bureaucrat import Bureaucrat
- from character import Character
- t = Terminal()
- class Game:
- '''The main logic of the game'''
- def __init__(self):
- self.clear_screen()
- print(t.underline('LAM-40 0.3'))
- self.character = Character()
- self.bureaucrat = Bureaucrat()
- while True:
- self.act()
- def act(self):
- '''An action taken by the player.'''
- # the following loop numerically lists all available actions
- for number, action in enumerate(self.character.actions):
- number = str(number + 1)
- print(number + '. ' + action)
- self.action = input('\nWhat will you do? ').lower()
- if self.action == 'q': # quits the game
- self.clear_screen()
- sys.exit('Thank you for playing LAM-40.\n')
- elif self.action == 'w': # creates a new bureaucrat
- self.bureaucrat = Bureaucrat()
- elif self.action in 'abcdefhijklmpstyw':
- self.react() # finds out what type of action was chosen
- self.calculate_odds() # alters the odds of success
- self.evaluate_success() # determines success or failure
- else: # incorrect input is given
- print('\nIncorrect action. Please try again.\n')
- def react(self):
- '''A reaction to the choice of the player.'''
- if self.action == 'bt': # character.py for reference
- self.character.probability_is_low()
- self.character.asc_rank_asc_mood()
- elif self.action in 'cp':
- self.character.probability_is_high()
- self.character.desc_rank_desc_mood()
- elif self.action in 'dm':
- self.character.probability_is_low()
- self.character.desc_rank_desc_mood()
- elif self.action in 'efj':
- self.character.probability_is_high()
- self.character.asc_rank_asc_mood()
- elif self.action in 'hkly':
- self.character.probability_is_low()
- self.character.desc_rank_asc_mood()
- elif self.action in 'is':
- self.character.probability_is_high()
- self.character.asc_rank_desc_mood()
- else: # 'a' (ask)
- self.character.probability_is_high()
- self.character.desc_rank_asc_mood()
- def calculate_odds(self):
- '''Calculates the odds of a successful action.'''
- # odds of success are randomly assigned to be 25-75% at first
- self.odds = float(random.choice(range(25, 76)))
- if self.bureaucrat.rank == 'low':
- if self.character.asc_rank is True: # character.py for reference
- self.odds /= self.character.divisor
- else:
- self.odds *= self.character.multiplier
- elif self.bureaucrat.rank == 'high':
- if self.character.asc_rank is True:
- self.odds *= self.character.multiplier
- else:
- self.odds /= self.character.divisor
- else:
- pass # medium rank doesn't affect the odds
- if self.bureaucrat.mood == 'bad':
- if self.character.asc_mood is True:
- self.odds /= self.character.divisor
- else:
- self.odds *= self.character.multiplier
- elif self.bureaucrat.mood == 'good':
- if self.character.asc_mood is True:
- self.odds *= self.character.multiplier
- else:
- self.odds /= self.character.divisor
- else:
- pass # average mood doesn't affect the odds
- def evaluate_success(self):
- '''Evaluates whether the action is successful or not.'''
- # the higher self.odds value
- # the higher the chance the action will succeed
- self.luck = random.choice(range(0, 101))
- if self.luck > self.odds:
- self.bureaucrat.react_negatively()
- else:
- self.bureaucrat.react_positively()
- def clear_screen(self):
- '''Clears the screen of the terminal.'''
- if os.name == 'nt': # 'nt' equals Windows
- os.system('cls')
- else:
- os.system('clear') # Mac OS and Linux
- Game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement