def set_choices(_choices, box="client"):
     _update_textbox(box, [Text("")], True)
     for choice in _choices:
         _update_textbox(box, [Text(choice + " ",
                                    font_size=choice_size,
                                    click=True,
                                    font_name=choice_font,
                                    color=choice_color)])
Beispiel #2
0
 def gen_desc(self, flower=False):
     desc = [Text(self.description, new_line=True)]
     if len(self.attacks) > 0:
         desc += [
             Text("", new_line=True),
             Text("Attacks",
                  new_line=True,
                  color=header_color,
                  font_size=header_size,
                  bold=True)
         ]
     for _attack in self.attacks:
         desc += _attack.gen_desc(flower=flower)
     return desc
Beispiel #3
0
def get_input(prompt=None, _path=None, allow_path_change=True):
    """Sets the prompt and waits for input.

    :type prompt: None | list[Text] | str
    :type _path: None | list[GameObject] | list[GameAction]
    :type allow_path_change: bool
    """
    global path, waiting

    if not isinstance(prompt, type(None)):
        if type(prompt) == str:
            text_list = [Text(prompt, color=prompt_color, new_line=True)]
        elif type(prompt) == list:
            text_list = prompt
        else:
            raise Exception("Must be None, str, or list[Text]")
        update_textbox("events", text_list)

    path = _path[:]
    _user_input = check_input()
    waiting = True
    while isinstance(_user_input, type(None)):
        time.sleep(.01)
        if len(path) != len(_path) and allow_path_change:
            # Backspace pressed. Path changed
            return None, len(path) - 1
        if not is_running():
            return None, None
        _user_input = check_input()
        hotkeys = check_hotkeys()
        if len(hotkeys) > 0:
            key = hotkeys[-1]
            return key, "HOTKEY"
    waiting = False
    return _user_input, len(path) - 1
Beispiel #4
0
def set_text(text):
    """Sets text in simulation box

    :type text: Text | str
    """
    if isinstance(text, str):
        text = Text(text, new_line=True, color=status_color)
    simulation_text_to_add.append(text)
Beispiel #5
0
def get_input(_prompt, sound=True, display_choice=True):
    """Sets a prompt and returns the user's reply

    :rtype: str
    """
    if isinstance(_prompt, str):
        _prompt = Text(_prompt, new_line=True, color=prompt_color)
    set_text(_prompt)
    if sound:
        play_notification()
    while True:
        sleep(.01)
        answer = get_answer()
        if not isinstance(answer, type(None)):
            break
    if display_choice and answer != "":
        set_text(Text(answer, new_line=True, color=choice_color))
    return answer
Beispiel #6
0
 def get_word(self, replace=True, strip=False):
     end = ""
     if not strip:
         end = " "
     if replace:
         name = self.get_name().replace("-", " ") + end
     else:
         name = self.get_name()
     return Text(name, color=npc_color, tooltip=self.gen_desc())
Beispiel #7
0
 def gen_desc(self):
     text_list = []
     if not isinstance(self.description, type(None)):
         text_list.append(Text(self.description, new_line=True))
     text_list += [
         Text("", new_line=True),
         Text("Treasure: ", color=header_color),
         Text(" Max: "),
         Text(str(self.treasure["Max"]), color=number_color),
         Text(", Min: "),
         Text(str(self.treasure["Min"]), color=number_color),
         Text(", Probability: "),
         Text(str(self.treasure["Probability"]), color=number_color)
     ]
     return text_list
Beispiel #8
0
    def add_event(_event=""):
        """Adds an event to the events box

        :type _event: str | list[Text]
        :param _event: "" for new line
        """

        if _event == "":
            _event = [Text("", new_line=True)]

        _update_textbox("events", _event)
Beispiel #9
0
    def run(self):
        """Starts the server thread"""

        # Start server
        server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server.bind((self.host, self.port))
        server.listen()

        # Wait for everyone to connect
        while len(self.connections) < self.num_players:
            # Check remaining players
            remaining_players = self.num_players - len(self.connections)
            set_text(Text("Waiting for " + str(remaining_players) + " player"
                          + ("s" if remaining_players > 1 else "")
                          + " to connect. ", new_line=True, color=status_color))
            # Wait for connection
            connection, address = server.accept()
            set_text(Text("Player Connected from " + str(address) + ".",
                          new_line=True, color=status_color))
            # Add new Connection thread to list of connections
            self.connections.append(
                Connection(len(self.connections), connection, address))
            self.connections[-1].setDaemon(True)
            self.connections[-1].start()
        set_text(Text("All players connected.", new_line=True,
                      color=status_color))

        available_jobs = jobs

        for player in self.num_players:
            for job in jobs:
                pass
                # TODO: Send jobs to clients
        # Receive data from clients
        while True:
            sleep(.1)
            # TODO: Add random events
            # If data has not been handled, handle first in line
            if len(unhandled_data) > 0:
                self.handle_data(unhandled_data.pop(0))
Beispiel #10
0
    def get_input(prompt=None, display_answer=True):
        """Creates a prompt and waits for input

        :type prompt: str | None
        :type display_answer: bool
        """

        answer = _get_input(prompt)

        if display_answer:
            add_event([Text(answer, color=input_color, new_line=True)])

        return answer
Beispiel #11
0
    def run(self):
        """Runs the thread"""
        while True:
            answer = get_input(Text("Host or Join server?", new_line=True,
                                    color=prompt_color)).lower()
            choices = ["host", "join"]
            if answer in choices:
                break

        if answer == "host":
            self.host_server()
        elif answer == "join":
            self.join_server()
Beispiel #12
0
    def gen_desc(self):
        """Generates a description based on stats"""

        if self.name == "yourself":
            raise Exception("Use game_save.get_stats_tooltip() instead for "
                            "player")
        if "Story-Teller" in self.attributes and not self.paid:
            return [Text("A wizened teller of tales.", new_line=True)]

        if not isinstance(self.description, type(None)):
            desc = [
                Text(self.description, new_line=True),
                Text("", new_line=True)
            ]
        else:
            desc = []

        desc += [
            Text("Health",
                 new_line=True,
                 color=header_color,
                 bold=True,
                 font_size=header_size)
        ]

        for stat in self.health_stats:
            desc += [
                Text(stat + ": ", color=header_color),
                Text(str(self.health_stats[stat]),
                     new_line=True,
                     color=number_color)
            ]

        desc.append(Text("", new_line=True))
        if len(self.attacks) > 0:
            desc.append(
                Text("Attacks",
                     new_line=True,
                     color=header_color,
                     font_size=header_size,
                     bold=True))
        total_prob = 0
        for _attack in self.attacks:
            total_prob += _attack.choice_probability
        for _attack in self.attacks:
            desc += _attack.gen_desc(total_prob=total_prob)

        return desc
Beispiel #13
0
def update_textbox(_box, text, clear=False):
    """Updates events textbox with new event.

    :type _box: str
    :type text: list[Text] | str
    :type clear: bool

    :param _box: Must be 'events', 'objects', or 'actions'
    :param text: list of text to update box with
    :param clear: Overwrites the box if true.
    """
    if type(text) == str:
        text_list = [Text(text, new_line=True)]
    elif type(text) == list:
        text_list = text
    else:
        raise Exception("Must be None, str, or list[Text]")
    textbox_updates[_box].append([text_list, clear])
def get_input(prompt=None):
    """Sets the prompt and waits for input.

    :type prompt: None | list[Text] | str
    """
    if not isinstance(prompt, type(None)):
        if type(prompt) == str:
            text_list = [Text(prompt, color=prompt_color, new_line=True)]
        elif type(prompt) == list:
            text_list = prompt
        else:
            raise Exception("Must be None, str, or list[Text]")
        update_textbox("events", text_list)

    _user_input = check_input()
    while isinstance(_user_input, type(None)):
        time.sleep(.1)
        if not is_running():
            return None
        _user_input = check_input()

    return _user_input
Beispiel #15
0
 def add_server_event(event):
     add_event([Text(event, color=server_color, new_line=True)])
Beispiel #16
0
    def gen_desc(self,
                 weapon=None,
                 show_title=True,
                 total_prob=None,
                 flower=False):
        """Generates a description based on stats"""
        desc = []
        if not isinstance(weapon, type(None)):
            desc = [
                Text(weapon.get_name(),
                     color=header_color,
                     font_size=header_size,
                     new_line=True),
                Text("", new_line=True)
            ]
        if show_title:
            desc.append(
                Text(self.name, new_line=True, bold=True, color=header_color))
        if not isinstance(total_prob, type(None)):
            desc += [
                Text("Choice Probability: "),
                Text(str(int(self.choice_probability / total_prob * 100)) +
                     "%",
                     color=number_color,
                     new_line=True)
            ]
        if not flower:
            desc += [
                Text("Hit Probability: "),
                Text(str(self.hit_probability),
                     color=number_color,
                     new_line=True),
                Text("Cooldown: "),
                Text(str(self.display_cooldown()),
                     color=number_color,
                     new_line=True),
                Text("Current Cooldown: "),
                Text(str(self.display_current_cooldown()),
                     color=number_color,
                     new_line=True)
            ]
            if "Consumable" in self.attributes:
                desc += [Text("Weapon destroyed on use.", new_line=True)]
            if "Thrown" in self.attributes:
                desc += [Text("Weapon dropped on use.", new_line=True)]

            if self.ammo > 0:
                desc += [
                    Text("Ammo: "),
                    Text(str(self.current_ammo),
                         color=number_color,
                         new_line=True)
                ]

            weapon_name = ""
            if not isinstance(weapon, type(None)):
                weapon_name = weapon.get_name()

            for stat in self.damages:
                # Add probability description
                prob_desc = []
                if not isinstance(self.probabilities, type(None)):
                    if stat in self.probabilities:
                        prob_desc += [
                            Text(", Probability: "),
                            Text(str(self.probabilities[stat]),
                                 color=number_color)
                        ]
                    else:
                        raise Exception(f"{weapon_name}, {self.name}: " +
                                        stat + " needs probability")

                # Add effectiveness description
                effect_desc = []
                if not isinstance(self.effectiveness, type(None)):
                    if stat in self.effectiveness:
                        effect_desc += [
                            Text(", Effectiveness: "),
                            Text(str(self.effectiveness[stat]),
                                 color=number_color)
                        ]
                    else:
                        raise Exception(f"{weapon_name}, {self.name}: " +
                                        stat + " needs effectiveness")

                desc += [
                    Text(stat + ": ", color=header_color),
                    Text(str(self.damages[stat]), color=number_color)
                ]
                desc += prob_desc
                desc += effect_desc
                desc.append(Text("", new_line=True))
        desc.append(Text("", new_line=True))
        return desc