Example #1
0
 def get_user_pick_up_input(self):
     player_choice = ''
     while player_choice.lower() not in ['d', 'p']:
         player_choice = input("Enter " + Colour.green('d') +
                               " to draw or " + Colour.green('p') +
                               " to pickup discard: ")
     return player_choice
Example #2
0
 def show_winners(self):
     winners = self.find_lowest_scores()
     if len(winners) == 1:
         return Colour.green("%s is the Winner!!" % winners[0])
     else:
         return Colour.green(", ".join([str(w) for w in winners]) +
                             " are joint winners!")
Example #3
0
 def end_game(self):
     winners = self.find_lowest_scores()
     if len(winners) == 1:
         print(Colour.green("%s is the Winner!!" % winners[0]))
     else:
         print(
             Colour.green(", ".join([w for w in winners]) +
                          " are joint winners!"))
Example #4
0
 def pagination_text(self):
     text = ""
     if self.page > 1:
         text += "%s previous | " % Colour.green('<')
     text += "page %d" % self.page
     if self.page * self.limit < self.total:
         text += " | next %s" % Colour.green('>')
     print(Style.create_underline(text))
     print(text)
     print(Style.create_underline(text))
Example #5
0
 def make_row(row, col_widths, separator="|", has_key=False):
     string = ""
     for i, column in enumerate(row):
         data = str(column)
         if i is 0 and has_key:
             data = Colour.green(data)
         padding = "".join(
             [" " for _ in range(col_widths[i] - len(str(column)) + 2)])
         string += "  " + data + padding + Colour.light_grey(separator)
     return string
Example #6
0
 def create_input(action_collection: ActionCollection):
     user_input = None
     keys = []
     output = ''
     while True:
         for action in action_collection.actions:
             if isinstance(action.key, range):
                 output += "%s: %s\n" % (
                     str(action), '%s-%s' %
                     (Colour.green(str(action.key[0])),
                      Colour.green(str(action.key[-1]))))
                 keys.extend([str(key) for key in action.key])
             else:
                 output += "%s: %s\n" % (str(action),
                                         Colour.green(action.key))
                 keys.append(str(action.key))
         View.render(output)
         while user_input not in keys:
             user_input = UserInput.get_input('Select an option: ')
         break
     return user_input
Example #7
0
 def delete(self):
     print(Style.create_title('Delete %s' % self.table_name))
     item = self.make_paginated_menu()
     if item:
         user_action = False
         while not user_action == 'delete':
             user_action = input(
                 'Type \'%s\' to remove this item or %s to cancel: ' %
                 (Colour.red('delete'), Colour.green('c')))
             if user_action == 'c':
                 return
         self.save_remove(item)
         Menu.wait_for_input()
Example #8
0
 def menu(self):
     result = False
     while not result:
         self.paginated_table()
         self.pagination_text()
         user_input = input('\nEnter an %s, use %s and %s to navigate, or %s to go back: ' % (
             Colour.green("'id'"),
             Colour.green("<"),
             Colour.green(">"),
             Colour.green("b")
         ))
         if (user_input == 'b'):
             break
         if self.should_change_page(user_input):
             self.change_page(user_input)
             continue
         if not Validation.is_number(user_input):
             print('Command not recognised')
             continue
         result = self.find_by_id(user_input)
         if not result:
             Menu.wait_for_input('An item with that ID was not found. Press any key to continue.')
     return result
Example #9
0
 def test_get_key(self):
     test_hand = Hand()
     test_hand.hand = [
         Card(x, y)
         for x, y in [("A",
                       "♥"), ("2",
                              "♥"), ("3",
                                     "♥"), ("4",
                                            "♥"), ("T",
                                                   "♥"), ("J",
                                                          "♥"), ("Q", "♥")]
     ]
     key_string = ',  '.join(
         ["%s" % Colour.green(str((i + 1))) for i in range(7)])
     assert test_hand.get_key() == key_string
Example #10
0
 def create(title, action_collection: ActionCollection):
     user_input = 0
     keys = []
     while True:
         print(Style.create_title(title))
         for action in action_collection.actions:
             print(Colour.green(action.key) + ": " + str(action))
             keys.append(action.key)
         while user_input not in keys:
             user_input = input('\nSelect an option: ')
         for action in action_collection.actions:
             if action.check_input(user_input):
                 action.execute()
         if user_input == 'b' or user_input == 'q':
             break
         else:
             user_input = 0
Example #11
0
 def discard_or_knock(self):
     self.render_player_turn_end()
     scores = self.melds.find_discard_scores(self.hand.get_hand())
     if min(scores) <= 10 and not self.round.knocked:
         message = "Enter a number to discard a card or " + Colour.green(
             'k') + " to Knock: "
     else:
         message = "Enter a number to discard a card: "
     player_choice = ""
     while player_choice not in [str(i) for i in range(1, 9)]:
         if self.round.knocked:
             message = "Enter a number to discard a card: "
         player_choice = input(message)
         if player_choice.lower() == "k" and min(scores) < 10:
             self.round.knocked = True
     player_choice = int(player_choice) - 1
     self.round.deck.discard_card(self.hand.discard_card(player_choice))
Example #12
0
 def wait_for_input(text=None):
     input('\nPress %s to continue.' %
           Colour.green('enter') if not text else "\n%s" % text)
Example #13
0
 def get_key(self):
     return ',  '.join(
         ["%s" % Colour.green(str((i + 1))) for i in range(len(self.hand))])
Example #14
0
 def display_pagination_instructions(self):
     return '\nChoose a \'%s\' to select a row, use %s and %s to navigate, or %s to go back: ' % (
         Colour.green("number"), Colour.green("<"), Colour.green(">"),
         Colour.green("b"))
Example #15
0
 def confirm_start_new_round(self):
     print("\nReady %s?" % self.players[self.round.current_player])
     ready = ''
     while ready.lower() != 'y':
         ready = input("Enter " + Colour.green('y') +
                       " when you are ready for the next round: ")