コード例 #1
0
def _get_hit_message(play, success, language, hit_ship="", destroyed_l=False):
    """
    evaluates displayed message based on hit and player

    :param play: int; player, 0 enemy 1 player
    :param success: bool; ship was hit
    :param language: str; language all wiritngs are currently displayed in
    :param hit_ship: Ship, hit ship
    :param destroyed_l: bool; ship was destroyed with that hit
    :return: str, tup(int, int, int)
    """
    dictionary = get_dict(language, "message")  # sets dictionary
    color = (0, 50, 125) if play else (125, 0,
                                       0)  # sets a color based on the player
    play = "Player" if play else "Enemy"  # sets player
    player = dictionary[play]  # translates player
    # sets message
    if destroyed_l:  # a ship was destroyed
        message = "destroyed"
    elif success:  # a ship was hit
        message = "success"
    else:  # no ship was hit
        message = "failure"
    message = dictionary[message]  # translates message
    if success:  # a ship was hit
        # adds the ship and its number
        hit_ship = hit_ship.name + " " + str(hit_ship.identification_number)
    return player + message + hit_ship, color  # returns message and color
コード例 #2
0
def create_request_buttons(field_size, bg_color, writing_color, language):
    """
    creates request buttons labeled with 'New Game' and 'Load Game'

    those buttons are used once after the beginning and before the actual game start

    :param field_size: float; size of a virtual field that is determined by the size of the window that inhabits the GUI
    :param bg_color: tup(int, int, int); color of the buttons' backgrounds
    :param writing_color: tup(int, int, int); writings' colors
    :param language: str; language the program currently displays all writing in
    """
    global request_buttons
    global button_writings_request
    request_buttons = []  # creates a list that later holds the request buttons
    button_writings_request = [
    ]  # creates a list that later holds the writings to the request buttons
    for i in range(3):
        # determines the correct intention for the button
        intention = 'new' if i == 0 else 'load'
        intention = 'random' if i == 1 else intention
        # calculates button's size
        size_x = field_size * 10
        size_y = field_size * 2
        # determines the correct dict to show request in correct language
        lang_dict = get_dict(language, "button")
        if i == 2:
            location_top_left = [23 / 2 * field_size, 21 / 2 * field_size]
            start_coord = [10, 9]
        elif i == 1:
            location_top_left = [35 / 2 * field_size, 15 / 2 * field_size]
            start_coord = [16, 6]
        else:
            location_top_left = [11 / 2 * field_size, 15 / 2 * field_size]
            start_coord = [4, 6]
        xcoord_count = 10

        # creates a button
        request_buttons.append(
            Button(size_x=size_x,
                   size_y=size_y,
                   number=i + 200,
                   location_top_left=location_top_left,
                   liste='request_buttons',
                   intention=intention,
                   field_size_x=10,
                   field_size_y=2,
                   field_coords=_get_field_coords_from_start(
                       xcoord_count, start_coord),
                   color_local=bg_color,
                   active=True))
        # creates a writing to the button
        button_writings_request.append(
            ButtonWriting(top_left_corner=_get_center_writing(
                request_buttons[i]),
                          font=_get_font_button(field_size),
                          content=lang_dict[intention],
                          color_local=writing_color,
                          button=request_buttons[i],
                          background=None,
                          active=True))
コード例 #3
0
def translate_title(language, title):
    """
    translates title or content into english/german/latin
    :param language: str; language the program's texts are currently displayed in
    :param title: str; title or content that is translated
    :return: str; translated title or content
    """
    translated_title = get_dict(language, "table")[title]
    return translated_title  # returns translated title
コード例 #4
0
ファイル: main.py プロジェクト: airberlin1/schiffe_versenken
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
コード例 #5
0
def add_missing_message(file, path, language, file_not_here=True):
    """
    adds file is missing message to chat

    :param file: str; file that is missing
    :param path: str; missing file's directory
    :param language: str; language all texts are currently displayed in
    :param file_not_here: bool; file is missing, not directory
    """
    chat.add_message("   " + path, (50, 50, 0))  # displays path
    # displays translated missing message
    dictionary = get_dict(language, "message")
    if file_not_here:
        chat_message = dictionary["System"] + dictionary["missing"] + file + "' in "
    else:
        chat_message = dictionary["System"] + dictionary["missingdir"]
    chat.add_message(chat_message, (50, 50, 0))
コード例 #6
0
def create_placement_buttons(field_size, language):
    """
    creates buttons visible in palyer controlled ship placing

    :param field_size: float; size of a virtual field that is determined by the size of the window that inhabits the GUI
    :param language: str; language the program currently displays all writing in
    """
    global placement_buttons
    global placement_writings
    placement_writings = []  # later holds writings on palcement buttons
    placement_buttons = []  # later holds placement buttons
    for i in range(2):
        intention = "Abbrechen" if i else "Start"  # gets intention
        size_x, size_y = (8 * field_size, 2 * field_size)  # calculates size
        lang_dict = get_dict(
            language, "button")  # gets dictionary used to translate writing
        location_top_left = [16, 2] if i else [16, 5]
        # creates a button
        placement_buttons.append(
            Button(size_x=size_x,
                   size_y=size_y,
                   number=i + 200,
                   location_top_left=location_top_left,
                   liste='placement_buttons',
                   intention=intention,
                   field_size_x=8,
                   field_size_y=2,
                   field_coords=_get_field_coords_placement_buttons(i),
                   color_local=DARKBLUE,
                   active=False))
        # creates a writing to the button
        placement_writings.append(
            ButtonWriting(top_left_corner=_get_center_writing(
                placement_buttons[i]),
                          font=_get_font_button(field_size),
                          content=lang_dict[intention],
                          color_local=DARKERGREEN,
                          button=placement_buttons[i],
                          background=None,
                          active=False))
コード例 #7
0
def _get_writing_content(button_list, language, button_number):
    """
    retunrs content for a writing
    :param button_list: str; list the button is in
    :param language: str; language all tect is currentöy displayed in
    :param button_number: int; number of button
    :return: str; content of button
    """
    dictionary = get_dict(
        language,
        "button")  # gets dictionary used to translate button's intention
    if button_list == "start_buttons":  # button is displayed in the beginning
        # translates button's intention
        return dictionary[start_buttons[button_number].intention]
    else:  # button is displayed in game
        if button_number < 102:  # surrender button
            intention = "Aufgeben"
        elif button_number < 104:  # settings button
            intention = "Menue"
        else:  # save button
            intention = "Speichern"
        return dictionary[intention]  # translates button