예제 #1
0
 def on_key_press(self, symbol, modifiers):
     if symbol == key.ENTER:
         mana = [self.mana.pay[c] for c in self.mana.colors]
         manastr = "".join([color * int(mana[i]) for i, color in enumerate("WUBRG") if mana[i] != ""])
         if mana[-1] > 0:
             manastr += str(mana[-1])
         if manastr == "":
             manastr = "0"
         if Mana.compare_mana(self.required_str, manastr):
             self.window.process_action(Action.ManaSelected(manastr))
             self.deactivate()
         return True
     elif symbol == key.ESCAPE:
         self.window.process_action(Action.CancelAction())
         self.deactivate()
         return True
예제 #2
0
 def on_key_press(self, symbol, modifiers):
     if symbol == key.ENTER:
         mana = [self.mana.pay[c] for c in self.mana.colors]
         manastr = ''.join([
             color * int(mana[i]) for i, color in enumerate("WUBRG")
             if mana[i] != ''
         ])
         if mana[-1] > 0: manastr += str(mana[-1])
         if manastr == '': manastr = '0'
         if Mana.compare_mana(self.required_str, manastr):
             self.window.process_action(Action.ManaSelected(manastr))
             self.deactivate()
         return True
     elif symbol == key.ESCAPE:
         self.window.process_action(Action.CancelAction())
         self.deactivate()
         return True
예제 #3
0
파일: cli.py 프로젝트: trunghuynh/incantus
def playerInput(context, prompt=''):
    print_header()
    printer(prompt)

    process = context['process']
    action = False

    if context.get("get_ability", False):
        while action == False:
            txt = text_input(
                "What would you like to do\n(Enter to pass priority): ")
            if not txt:
                action = process(Action.PassPriority())
            else:
                try:
                    cardnum = int(txt)
                    card = card_map.get(cardnum, None)
                    if card:
                        action = process(Action.CardSelected(card))
                        printer("You selected %s in %s" % (card, card.zone))
                except:
                    pass
            if action == False: printer("Invalid action")
    elif context.get("get_target", False):
        while action == False:
            txt = text_input("Select target (P# for player): ").upper()
            if not txt: action = process(Action.PassPriority())
            elif txt == "/": action = process(Action.CancelAction())
            else:
                if txt[0] == "P":
                    try:
                        pnum = int(txt[1:])
                        if pnum < len(Keeper.players):
                            action = process(
                                Action.PlayerSelected(Keeper.players[pnum]))
                    except:
                        pass
                else:
                    try:
                        cardnum = int(txt)
                        card = card_map.get(cardnum, None)
                        if card:
                            action = process(Action.CardSelected(card))
                            printer("You selected %s in %s" %
                                    (card, card.zone))
                    except:
                        pass
            if action == False: printer("Invalid target")
    elif context.get("get_cards", False):
        sellist = context['list']
        numselections = context['numselections']
        required = context['required']
        from_zone = context['from_zone']
        from_player = context['from_player']
        check_card = context['check_card']
        printer("Choose from %s" % ', '.join(map(str, sellist)))
    elif context.get("reveal_card", False):
        sellist = context['cards']
        from_zone = context['from_zone']
        from_player = context['from_player']
        printer.indent()
        printer("%s reveals: %s" % (from_player, ', '.join(map(str, sellist))))
        printer.unindent()
        action = True
    elif context.get("get_selection", False):
        sellist = context['list']
        numselections = context['numselections']
        required = context['required']
        msg = context['msg']
        printer.indent()
        while action is False:
            map(printer, ["%d) %s" % (o[1], o[0]) for o in sellist])
            txt = text_input(msg + ":")
            if txt:
                try:
                    num = int(txt)
                    if num < len(sellist):
                        action = process(Action.SingleSelected(num))
                except:
                    pass
        printer.unindent()
    elif context.get("get_choice", False):
        msg = context['msg']
        notify = context['notify']
        if notify: msg += " (Hit enter to continue)"
        else: msg += "([Y]/N):"
        text = text_input(msg).upper()
        if notify: action = Action.OKAction()
        elif not text or text == "Y": action = Action.OKAction()
        else: action = Action.CancelAction()
    elif context.get("get_mana_choice", False):
        required = context['required']
        manapool = context['manapool']
        from_player = context['from_player']
        while action == False:
            manastr = text_input("(Required: %s) Mana to use: " %
                                 required).upper()
            if not manastr:
                action = process(Action.CancelAction())
            else:
                # Make sure it's a valid string
                try:
                    Mana.convert_mana_string(manastr)
                    if (Mana.compare_mana(required, manastr)
                            and Mana.subset_in_pool(manapool, manastr)):
                        action = process(Action.ManaSelected(manastr))
                except:
                    pass
    elif context.get("get_X", False):
        from_player = context['from_player']
        prompt = "Enter X: "
        while action == False:
            text = text_input(prompt)
            if not text:
                action = Action.CancelAction()
            else:
                try:
                    amount = int(text)
                    if amount >= 0: action = Action.XSelected(amount)
                    else: prompt = "Invalid input. Enter X: "
                except:
                    prompt = "Invalid input. Enter X: "
            action = process(action)
    elif context.get("get_distribution", False):
        amount = context['amount']
        targets = context['targets']
    elif context.get("get_damage_assign", False):
        blocking_list = context['blocking_list']
        trample = context['trample']

    dump_to_replay.write(action)

    return action
예제 #4
0
파일: cli.py 프로젝트: Incantus/incantus
def playerInput(context, prompt=''):
    print_header()
    printer(prompt)

    process = context['process']
    action = False

    if context.get("get_ability", False):
        while action == False:
            txt = text_input("What would you like to do\n(Enter to pass priority): ")
            if not txt: 
                action = process(Action.PassPriority())
            else:
                try:
                    cardnum = int(txt)
                    card = card_map.get(cardnum, None)
                    if card:
                        action = process(Action.CardSelected(card))
                        printer("You selected %s in %s"%(card, card.zone))
                except: pass
            if action == False: printer("Invalid action")
    elif context.get("get_target", False):
        while action == False:
            txt = text_input("Select target (P# for player): ").upper()
            if not txt: action = process(Action.PassPriority())
            elif txt == "/": action = process(Action.CancelAction())
            else:
                if txt[0] == "P":
                    try:
                        pnum = int(txt[1:])
                        if pnum < len(Keeper.players):
                            action = process(Action.PlayerSelected(Keeper.players[pnum]))
                    except: pass
                else:
                    try:
                        cardnum = int(txt)
                        card = card_map.get(cardnum, None)
                        if card:
                            action = process(Action.CardSelected(card))
                            printer("You selected %s in %s"%(card, card.zone))
                    except: pass
            if action == False: printer("Invalid target")
    elif context.get("get_cards", False):
        sellist = context['list']
        numselections = context['numselections']
        required = context['required']
        from_zone = context['from_zone']
        from_player = context['from_player']
        check_card = context['check_card']
        printer("Choose from %s"%', '.join(map(str, sellist)))
    elif context.get("reveal_card", False):
        sellist = context['cards']
        from_zone = context['from_zone']
        from_player = context['from_player']
        printer.indent()
        printer("%s reveals: %s"%(from_player, ', '.join(map(str,sellist))))
        printer.unindent()
        action = True
    elif context.get("get_selection", False):
        sellist = context['list']
        numselections = context['numselections']
        required = context['required']
        msg = context['msg']
        printer.indent()
        while action is False:
            map(printer, ["%d) %s"%(o[1], o[0]) for o in sellist])
            txt = text_input(msg+":")
            if txt:
                try:
                    num = int(txt)
                    if num < len(sellist):
                        action = process(Action.SingleSelected(num))
                except:
                    pass
        printer.unindent()
    elif context.get("get_choice", False):
        msg = context['msg']
        notify = context['notify']
        if notify: msg += " (Hit enter to continue)"
        else: msg += "([Y]/N):"
        text = text_input(msg).upper()
        if notify: action = Action.OKAction()
        elif not text or text == "Y": action = Action.OKAction()
        else: action = Action.CancelAction()
    elif context.get("get_mana_choice", False):
        required = context['required']
        manapool = context['manapool']
        from_player = context['from_player']
        while action == False:
            manastr = text_input("(Required: %s) Mana to use: "%required).upper()
            if not manastr:
                action = process(Action.CancelAction())
            else:
                # Make sure it's a valid string
                try: 
                    Mana.convert_mana_string(manastr)
                    if (Mana.compare_mana(required, manastr) and 
                        Mana.subset_in_pool(manapool, manastr)):
                        action = process(Action.ManaSelected(manastr))
                except: pass
    elif context.get("get_X", False):
        from_player = context['from_player']
        prompt = "Enter X: "
        while action == False:
            text = text_input(prompt)
            if not text:
                action = Action.CancelAction()
            else:
                try:
                    amount = int(text)
                    if amount >= 0: action = Action.XSelected(amount)
                    else: prompt = "Invalid input. Enter X: "
                except:
                    prompt = "Invalid input. Enter X: "
            action = process(action)
    elif context.get("get_distribution", False):
        amount = context['amount']
        targets = context['targets']
    elif context.get("get_damage_assign", False):
        blocking_list = context['blocking_list']
        trample = context['trample']

    dump_to_replay.write(action)

    return action