コード例 #1
0
ファイル: human.py プロジェクト: rjalfa/Python-Rummy
 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
コード例 #2
0
ファイル: score.py プロジェクト: jaste111/Python-Rummy
 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!")
コード例 #3
0
ファイル: score.py プロジェクト: rhythmize/Python-Rummy
 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!"))
コード例 #4
0
ファイル: pagination.py プロジェクト: OrderAndCh4oS/Invoicing
 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))
コード例 #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
コード例 #6
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()
コード例 #7
0
    def make_underline(col_widths, use_ansi=True, separator="|"):
        underline = [separator]
        for width in col_widths:
            underline.append("{}{}".format("-" * (width + 4), separator))

        return Colour.light_grey(
            "".join(underline)) if use_ansi else "".join(underline)
コード例 #8
0
    def make_row(wrapped_row,
                 col_widths,
                 use_ansi=True,
                 separator='|',
                 column_colours=None,
                 row_colour=None):
        if column_colours is None:
            column_colours = []
        if row_colour is None:
            row_colour = []

        separator = Colour.light_grey(separator) if use_ansi else separator
        string = []

        for h in range(Table.get_row_height(wrapped_row)):
            if h > 0:
                string.append('\n')
            string.append(separator)
            for i, column in enumerate(wrapped_row):
                if h < len(column):
                    data = str(column[h])
                    if use_ansi:
                        colour = column_colours[i] if i < len(
                            column_colours) else row_colour
                        if callable(colour):
                            data = colour(data)

                    padding = ' ' * (col_widths[i] - len(column[h]))
                    string.append('  {}{}  {}'.format(data, padding,
                                                      separator))
                else:
                    padding = ' ' * col_widths[i]
                    string.append('  {}  {}'.format(padding, separator))

        return ''.join(string)
コード例 #9
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
コード例 #10
0
ファイル: pagination.py プロジェクト: OrderAndCh4oS/Invoicing
 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
コード例 #11
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
コード例 #12
0
ファイル: human.py プロジェクト: rjalfa/Python-Rummy
 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))
コード例 #13
0
 def pagination(self):
     result = False
     while not result:
         self.display_pagination()
         user_input = Input.get(self.display_pagination_instructions())
         if user_input == 'b':
             break
         if self.should_change_page(user_input):
             self.change_page(user_input)
             print('\n')
             continue
         if user_input not in [str(x) for x in range(1, len(self.arr) + 1)]:
             Input.get("\n%s\nPress any key to continue.\n" %
                       Colour.red("The row number entered was not found."))
             continue
         result = self.arr[int(user_input) - 1]
     return result
コード例 #14
0
ファイル: menu.py プロジェクト: jscottgray/Invoicing
 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
コード例 #15
0
    def make_row(row, col_widths, use_ansi=True, separator="|", column_colours=None, row_colour=None):
        if column_colours is None:
            column_colours = []
        if row_colour is None:
            row_colour = []
        separator = Colour.light_grey(separator) if use_ansi else separator
        string = separator
        for i, column in enumerate(row):
            data = str(column)
            if use_ansi:
                colour = column_colours[i] if i < len(column_colours) else row_colour
                if callable(colour):
                    data = colour(data)
            padding = "".join([" " for _ in range(col_widths[i] - len(str(column)) + 2)])
            string += "  " + data + padding + separator

        return string
コード例 #16
0
 def create(length):
     return Colour.light_grey("".join(['-' for _ in range(length)]))
コード例 #17
0
 def make_underline(col_widths):
     underline = ""
     for width in col_widths:
         underline += "".join(["-" for _ in range(width + 5)])
     return Colour.light_grey(underline)
コード例 #18
0
ファイル: menu.py プロジェクト: jscottgray/Invoicing
 def wait_for_input(text=None):
     input('\nPress %s to continue.' %
           Colour.green('enter') if not text else "\n%s" % text)
コード例 #19
0
    def make_underline(col_widths, use_ansi=True, separator="|"):
        underline = separator
        for width in col_widths:
            underline += "".join(["-" for _ in range(width + 4)]) + "|"

        return Colour.light_grey(underline) if use_ansi else underline
コード例 #20
0
ファイル: play.py プロジェクト: rjalfa/Python-Rummy
 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: ")
コード例 #21
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"))
コード例 #22
0
 def show_item_detail(self, item):
     print(Style.create_title('%s Data' % self.table_name))
     for header in self.repository.get_headers():
         label = Style.make_label(header)
         print('%s: %s' % (label, Colour.blue(str(item[header]))))
コード例 #23
0
ファイル: hand.py プロジェクト: rjalfa/Python-Rummy
 def get_key(self):
     return ',  '.join(
         ["%s" % Colour.green(str((i + 1))) for i in range(len(self.hand))])
コード例 #24
0
 def display_errors(self, message):
     print(Style.create_title(message))
     for (key, value) in self.model.get_errors().items():
         print("%s: %s" % (key.capitalize(), Colour.red(value)))
コード例 #25
0
ファイル: card.py プロジェクト: rjalfa/Python-Rummy
 def red_card(self):
     if UNICODE_SUPPORT:
         return str(self.value) + Colour.red(self.suit)
     else:
         return str(self.value) + self.suit
コード例 #26
0
ファイル: style.py プロジェクト: jscottgray/Invoicing
 def create_underline(title):
     return Colour.blue("".join(['-' for _ in range(len(title))]))