示例#1
0
def add_system_message(message):
    """
    adds a system message to be displayed in chat
    :param message: str; message that i sdisplayed
    """
    dictionary = get_dict(
        lg.get_language(),
        "message")  # gets the correcct dictionary to translate message
    message = dictionary["System"] + dictionary[message]  # translates message
    chat.add_message(message, (50, 50, 0))  # displays message in dark yellow
示例#2
0
def hit_something(xcoord,
                  ycoord,
                  player,
                  resource_path,
                  sound_volume,
                  language,
                  old_xcoord=-1,
                  old_ycoord=-1):
    """
    hits whatever is on player, xcoord, ycoord

    hits a ship by destroying the part and from now on displaying it as red

    hits a field by now displaying "X" on it and marking it as hit

    :param xcoord: int; x coordinate of the field that is hit
    :param ycoord: int; y coordinate of the field that is hit
    :param player: int; player currently playing
    :param resource_path: Func; returns the resource path to a relative path
    :param sound_volume: float; 0 - 1, volume of sounds
    :param language: str; language all wiritings are currently displayed in
    :param old_xcoord: int; x coordinate of the field that was hit previously
    :param old_ycoord: int; y coordinate of the field that was hit previously
    """
    player = 1 - player  # setsthe player to the opposite of the input player
    # marks the small field as hit
    hit_small_field(player, xcoord, ycoord, resource_path, sound_volume,
                    language, old_xcoord, old_ycoord)
    for i in range(ship_count):  # goes through every ship's number
        # checks for every ship whether it is on the field
        if check_ship_pos(ship[player][i], (xcoord, ycoord))[0]:
            mark_destroyed(player, i, xcoord,
                           ycoord)  # marks ship's part as hit
            # plays the sound that indicates a ship part being hit
            _play_hit_sound(resource_path, sound_volume, language)
            destroyed_l = ship[player][i].is_destroyed()
            update_stats_values(
                player, destroyed_l)  # updates values used for statistics
            message, color = _get_hit_message(player, True, language,
                                              ship[player][i], destroyed_l)
            chat.add_message(message, color)  # displays success in chat
            return
    message, color = _get_hit_message(player, False, language)
    chat.add_message(message, color)  # displays miss in chat
示例#3
0
def do_chat():
    content = bottle.request.body.read().decode()
    content = json.loads(content)
    chat.add_message(content['message'])

    return json.dumps(chat.get_chat())
示例#4
0
def addMessage(chat_id):
    user_id = int(request.args.get('user_id'))
    message = request.get_json()
    return C.add_message(chat_id, user_id, message)
示例#5
0
def dochattext(msg):
    add_message(group_id, msg)