def value_bar(self, usr_data): if self.index == 1: print(fonts.font_dark('red') + fonts.bold() + 'HEALTH :', end='' + fonts.default()) elif self.index == 2: print(fonts.font_dark('yellow') + fonts.bold() + 'ATTACK :', end='' + fonts.default()) elif self.index == 8: print(fonts.font_light('blue') + fonts.bold() + 'COMPUTER HEALTH :', end='' + fonts.default()) if int(usr_data[self.index]) < 4: color1 = fonts.bar_dark('red') color2 = fonts.font_dark('red') elif 4 <= int(usr_data[self.index]) <= 7: color1 = fonts.bar_dark('blue') color2 = fonts.font_dark('blue') elif int(usr_data[self.index]) > 7: color1 = fonts.bar_dark('green') color2 = fonts.font_dark('green') else: color1 = fonts.default() color2 = fonts.default() print(color2, '( %d ) ' % int(usr_data[self.index]), end='') for x in range(0, int(usr_data[self.index])): print(color1, end='') print('=', end='') print(fonts.default(), end='') for x in range(int(usr_data[self.index]), 10): print(fonts.bold() + '-', end='') print(fonts.default(), end='')
def menu(): system('clear') print("+----------------------------+") print("|" + fonts.bar_dark('red') + fonts.bold() + fonts.font_dark('grey') + " LUCKY SKILLS " + fonts.default() + "|") print("+----------------------------+\n") print(" 1. " + fonts.font_light('green') + "NEW GAME" + fonts.default()) if path.isfile(war.dir_path + 'saved_game.txt'): print(" 2. " + fonts.font_light('yellow') + "LOAD SAVED GAME" + fonts.default()) print(" 3. " + fonts.font_light('blue') + "HIGH SCORE" + fonts.default()) print(" 4. " + fonts.font_dark('purple') + "STORY" + fonts.default()) print(" 5. " + fonts.font_light('white') + "INSTRUCTIONS" + fonts.default()) print(" 6. " + fonts.font_light('red') + "EXIT" + fonts.default()) print() choice = int(input(">>> ")) else: print(" 2. " + fonts.font_light('red') + "EXIT" + fonts.default()) print() choice = int(input(">>> ")) if choice == 2: choice = 6 return choice
def inputs(self): """ This function checks for a correct input from user and TRA! :return: None """ # User input self.usr_input = int(input(fonts.font_dark('green') + "Your Chance: " + fonts.default())) while self.usr_input > 9 or self.usr_input <= 0: print(fonts.bar_dark('red') + '* Please enter correctly *' + fonts.default()) self.usr_input = int(input(fonts.font_dark('green') + "Your Chance: " + fonts.default())) while self.usr_input in self.usr_data[9]: print(fonts.font_dark('red') + '* Number Locked *' + fonts.default()) self.usr_input = int(input(fonts.font_dark('green') + "Your Chance: " + fonts.default())) self.usr_data[9].append(self.usr_input - 1) self.usr_data[9].append(self.usr_input) self.usr_data[9].append(self.usr_input + 1) if self.usr_data[7] >= 3: self.usr_data[9].pop(0) self.usr_data[9].pop(1) self.usr_data[9].pop(2) # computer input tra_input_temp = int(randint(1, 90) % 20) or randint(1, 19) while self.tra_input == tra_input_temp: tra_input_temp = int(randint(1, 90) % 20) or randint(1, 19) self.tra_input = tra_input_temp self.io.speech_tra('I took %d' % self.tra_input, 1)
def display_resource(self): """ Displays the current resource list: Magic cards, Health Point and Attack Point and Score :return: None """ # Bar 1 print(fonts.bar_dark('white')) self.io.print_spaces(90) print(fonts.default()) print() # Player Name print(' ', end='') print(fonts.font_dark('aqua') + fonts.bold() + "PLAYER : " + fonts.default(), end='') print(self.usr_data[0].upper()) # Magic Cards print(' ', end='') self.mc.display_card_resource(self.usr_data) # Player Health Point print(' ', end='') self.hp.value_bar(self.usr_data) # Break self.io.print_spaces(8) print('|', end='') self.io.print_spaces(8) # Computer Health Point self.chp.value_bar(self.usr_data) print() # Attack Point print(' ', end='') self.ap.value_bar(self.usr_data) # Break self.io.print_spaces(8) print('|', end='') self.io.print_spaces(8) # Score print(fonts.font_light('purple') + fonts.bold() + fonts.underline() + 'SCORE: ', self.usr_data[3]) print(fonts.default()) # Any active Magic Card if int(self.usr_data[4]) >= 0: # print(fonts.bar_light('grey'), ' ' + fonts.default() + ' ', end='') print(fonts.font_dark(self.mc.color_code[self.mc.card_list[self.usr_data[4]]]) + fonts.underline() + fonts.bold() + '* ' + self.mc.card_list[self.usr_data[4]], '*' + fonts.font_dark('grey') + ' is active!' + fonts.default()) # print(fonts.bar_light('grey'), ' ', end='') # Bar 2 (zebra) self.io.zebra_bar('grey', 'white', 96) print('\n')
def display_card_resource(self, usr_data): """ This function displays the current status of Magic Cards. Each card has a color code. :return:None """ index = 0 print(fonts.font_dark("green") + fonts.bold() + "MAGIC CARDS : ", end='') for card in self.card_list: print(fonts.font_dark(self.color_code[card]) + fonts.bold() + card + fonts.default() + ': %2d' % (usr_data[5][index]), end=' ', flush=stdout) index += 1 print()
def one_time_card(self, usr_data, card_no): """ This module implements the usage of One-Time-Magics-Cards. There are two OTMCs : Canon and Medipack. They are like use-and-through cards, independent of any future rounds. :param usr_data: the list of current game data :param card_no: The Magic Card number; 1: Canon, 2: Medipack :return: a list of updated game data """ print( fonts.font_dark(self.color_code[self.card_list[card_no]]) + fonts.underline() + fonts.bold() + '* ' + self.card_list[card_no] + ' is being deployed *' + fonts.default()) # Canon Card if card_no == 1: if usr_data[8] > 0: usr_data[8] -= 1 usr_data[5][1] -= 1 usr_data[6] = 0 # Medipack elif card_no == 2: if usr_data[1] <= 9: usr_data[1] += 1 usr_data[2] -= 1 usr_data[5][2] -= 1 usr_data[6] = 0 else: self.io.speech_bill( "Health already at max. No need for a Medipack!") return usr_data
def new_game(self): """ :return: """ try: self.io.speech_bill("Whats your name?") name = input(fonts.font_light('aqua') + '>>> ' + fonts.default()) self.usr_data[0] = name self.set_stage() while self.usr_data[1] != 0 or self.usr_data[8] != 0: self.new_round() if self.usr_data[8] == 0: system('clear') if not path.isfile( path.dirname(path.abspath(__file__)) + '/intro'): print('YOU WON') else: with open( path.isfile( path.dirname(path.abspath(__file__)) + '/extro_win')) as file: for line in file: self.io.speech_bill(line) sleep(2) elif self.usr_data[1] == 0: system('clear') if not path.isfile( path.dirname(path.abspath(__file__)) + '/extro_loose'): print("YOU LOST") else: with open( path.isfile( path.dirname(path.abspath(__file__)) + '/extro_loose')) as file: for line in file: self.io.speech_bill(line) sleep(2) self.high_score() except KeyboardInterrupt: print( fonts.font_dark('red') + "\n\n* Keyboard Interrupt *\n" + fonts.default()) print( fonts.font_light('green') + "* Auto-saving Game Progress *\n\n" + fonts.default()) self.save_game() sleep(2) system('clear')
def speech_bill(self, text, secure=1): """ This method prints the speechs of Bill Zuckerberg. :param secure: Whether he speaks by secure channel yo you(1, default) or directly to TRA (0) :param text: His Speech. :return: None """ if secure: print(fonts.font_light('aqua') + '[Bill: ', end='') self.typel(' ' + text + ']') print(fonts.default()) elif secure == 0: print(fonts.font_dark('aqua') + fonts.bold() + 'Bill : ', end='') self.typel(' ' + text) print(fonts.default())
def runtime_card_init(self, usr_data, card_no): """ This module initialises Long-Time-Magic-Cards. LTMCs are of 3 types: Shield, Insurance and Virus. These are the cards that are played at one round, but it remains active till future rounds. This module is called upon, when the card is played. :param usr_data: a list of current game data :param card_no: The Magic Card number; 0: Shield, 3: Virus, 4: Insurance :return: a list of updated game data """ if usr_data[4] != -1: self.io.speech_bill( 'You have a card active : ' + fonts.font_dark(self.color_code[self.card_list[usr_data[4]]]) + self.card_list[usr_data[4]]) self.io.speech_bill( 'Are you sure you want to proceed? (say yes(y) or No(n): ') ch = input(fonts.font_light('aqua') + '>>> ' + fonts.default()) if ch.upper() == 'Y' or ch.upper() == 'YES': usr_data[4] = -1 else: self.io.speech_tra('Cant Decide eh?', 2) return usr_data if usr_data[4] == -1: # Shield if card_no == 0: usr_data[4] = 0 # Virus elif card_no == 3: if usr_data[2] <= 1: self.io.speech_bill( "We cant do that! We don't have enough Attack Points.") else: usr_data[4] = card_no usr_data[2] -= 2 # Insurance elif card_no == 4: if usr_data[2] < 1: self.io.speech_bill( "We cant do that! We don't have enough Attack Points.") else: usr_data[4] = card_no usr_data[2] -= 1 return usr_data
def runtime_card_deploy(self, usr_data, card_no=None): """ This module is called upon when ever an LTMCs are set to take effect. :param usr_data: a list of current game data :param card_no: The Magic Card number; 0: Shield 3: Virus, 4: Insurance :return: a list of updated game data """ if card_no is None: card_no = usr_data[4] print( fonts.font_dark(self.color_code[self.card_list[card_no]]) + fonts.underline() + fonts.bold() + '* ' + self.card_list[card_no] + ' is being deployed *' + fonts.default()) # Shield if card_no == 0: usr_data[1] += 1 # Virus elif card_no == 3: if usr_data[8] > 0: usr_data -= 1 # Insurance elif card_no == 4: if usr_data[2] < 1: self.io.speech_bill( "We can\'t pay the Premium. We don't have enough Attack Points." ) self.io.speech_tra( "Haha, you lost your Insurance Card didn\'t you? Oh! pittyful Humans! " ) usr_data[4] = -1 elif usr_data[1] == 10: self.io.speech_bill( "Yay, full life boost! Come on now, lets finish this game!", 0) else: usr_data[2] -= 1 if usr_data[1] < 10: usr_data += 1 return usr_data
input("Press any key to continue!") system('clear') resolve_menu() # Exit elif choice == 6: print("* Hope to see you soon *") sleep(2) system('clear') exit() else: print( 'This program haven\'t been programed with any operation for this input, sorry!' ) system('clear') resolve_menu() except KeyboardInterrupt: print("\n\n SEE YOU SOON... \n") sleep(2) system('clear') if __name__: print( fonts.font_dark('green') + "\nPlease switch to full screen, if not already!\n" + fonts.default()) sleep(3) resolve_menu()
def gen_mc_force(self, usr_data): """ This function generates a Magic Card when ever the user wishes what's the catch? Simple, trade two other existing magic cards. :D And remember, the win_counter in reset after this. A few important points if you are trying to understand what are these lines of if-else and loops used here! > using a loop we are iterating all the type of Magic Cards. > break the loop once 2 cards are given > don't show cards with card count 0 > choice1 and choice2 are 'list' variables, where 0th element is the Magic Card name and 1st element is the number of cards. > choice1 takes one type of card, and choice2 takes another type of card; only when number of cards in choice1 is 1. if there are two cards for choice1, choice2 is not utilised. > using a while loop to force player to give correct input. > Once a correct input is provided, we generate a magic card as per user's choice. :return: None """ # Find if there are any cards at-all or not total_number_of_cards = 0 choice1 = [-1, 0] # [card_index, numbers_to_be_trades] choice2 = [-1, 0] for number in usr_data[5]: total_number_of_cards += int(number) # If there are atleast 2 Magic Cards, carry on... if total_number_of_cards >= 2: print( "\nEnter the number of cards you want to trade:" "(\n0 to skip that card, or the number of cards you want(1 or 2)\n" ) index = 0 for number in usr_data[5]: # Break the loop if two cards have been chosen. if choice1[1] == 2 or choice1[1] + choice2[1] == 2: index += 1 break # Don't show a Magic Card with count 0 if number == 0: index += 1 continue if choice1[1] == 0: choice1[0] = index choice1[1] = int( input( fonts.font_dark(self.color_code[ self.card_list[index]]) + self.card_list[index] + fonts.default() + ': ')) # Force the user to give correct input only. # Add Dialog while choice1[1] > 2 or choice1[1] < 0: if choice1[1] > 2: self.io.speech_tra( "How nice of you to sacrifice more than 2 cards.", 2) self.io.speech_tra( "But you don\'t need to be so good!", 2) self.io.speech_bill("Enter Correctly") choice1[1] = int( input( fonts.font_light('aqua') + '>>> ' + fonts.default())) else: self.io.speech_tra("Stop trying my patience!", 1) self.io.speech_tra("Enter Correctly:", 2) choice1[1] = int( input( fonts.font_light('red') + '>>> ' + fonts.default())) else: choice2[0] = index choice2[1] = int( input( fonts.font_dark(self.color_code[ self.card_list[index]]) + self.card_list[index] + fonts.default() + ': ')) while choice2[1] > 1: self.io.speech_tra("Please! That won\'t work.", 2) self.io.speech_tra("Enter Correctly:", 2) choice2[1] = int( input( fonts.font_light('red') + '>>> ' + fonts.default())) index += 1 if choice1[1] + choice2[1] == 2: self.io.speech_bill("Are you Sure? ") ch = input(fonts.font_light('aqua') + '>>> ' + fonts.default()) if ch.upper() == 'Y' or ch.upper() == 'YES' or ch.upper( ) == 'YUP': usr_data[5][choice1[0]] -= choice1[1] if choice1[1] <= 1: usr_data[5][choice2[0]] -= choice2[1] CustomIO.CustomIO().loading() print() usr_data = self.choose_card(usr_data, 2) elif ch.upper() == 'N' or ch.upper() == 'NO' or ch.upper( ) == 'NOPE': # add dialog self.io.speech_tra( "None of your cards were touched. I knew you couldn't decide...", 2) else: # add dialog self.io.speech_tra( "Say only what you are asked. Taking 'No' as your answer...", 1) else: self.io.speech_tra( "You know, I'm not a fool! Please stop trying cheap tricks!", 1) self.io.speech_tra( "I'm not going to ask you to enter correctly! Next time, remember this.", 2) else: self.io.speech_tra("Duh! You don\'t have enough cards to trade", 2) return usr_data
def resume(self): """ This helps to resume a previously saved game. Restores the saved values from the file saved_game.txt to the current game. :return: the list user data if the game can be resumed. """ try: print(" * Please wait, resuming game", end='') self.io.typel('... *', 1) print() index = 0 if path.isfile(self.dir_path + 'saved_game.txt'): with open(self.dir_path + 'saved_game.txt') as file: for line in file: if index == 0: self.usr_data[index] = line[0:-1] elif index == 5 or index == 9: l = [ int(x) for x in line if x not in ['[', ']', ',', ' ', '\n'] ] self.usr_data[index] = l else: self.usr_data[index] = int(line[:-1]) index += 1 else: print("* There is no saved file. Can't resume game. *") print("* Starting a new game! *") self.usr_data = [ 'Bill Zuckerberg', 6, 3, 100, 0, [0, 0, 1, 0, 0], 0, 0, 7 ] while self.usr_data[1] != 0 or self.usr_data[8] != 0: self.new_round() if self.usr_data[8] == 0: system('clear') if not path.isfile( path.dirname(path.abspath(__file__)) + '/intro'): print('YOU WON') else: with open( path.isfile( path.dirname(path.abspath(__file__)) + '/extro_win')) as file: for line in file: self.io.speech_bill(line) sleep(2) elif self.usr_data[1] == 0: system('clear') if not path.isfile( path.dirname(path.abspath(__file__)) + '/extro_loose'): print("YOU LOST") else: with open( path.isfile( path.dirname(path.abspath(__file__)) + '/extro_loose')) as file: for line in file: self.io.speech_bill(line) sleep(2) self.high_score() except KeyboardInterrupt: print( fonts.font_dark('red') + "\n\n* Keyboard Interrupt *\n" + fonts.default()) print( fonts.font_light('green') + "* Auto-saving Game Progress *\n\n" + fonts.default()) self.save_game() sleep(2) system('clear')