def get_saves_path():
    """Returns the path to the saves folder and creates new one if missing"""

    stored_path = get_value("save", "saves_path")\
        .replace("~Game Root~", get_game_root())

    check_path(stored_path)
    return stored_path
def get_save_file_name(_save):
    """Returns the name of the save file in the config and creates a new one
     if missing.

    :type _save: Save
    :param _save: Used to create a new save file when necessary
    :rtype: str, bool
    :returns: save file name, if new file was created
    """

    new = False
    save_file_path = get_saves_path()
    save_file_name = get_value("save", "save_file")
    if isinstance(save_file_name, type(None)) \
            or not os.path.exists(save_file_path + save_file_name
                                  + "." + extension):
        # No file saved to config or saved file is missing

        # Get highest available number for file name
        highest_file = -1
        for file in os.listdir(save_file_path):
            if file.endswith("." + extension):
                file_num = -1
                try:
                    file_num = int(file[:-len("." + extension)])
                except ValueError:
                    continue
                if file_num > highest_file:
                    highest_file = file_num

        save_file_name = str(highest_file + 1)
        full_path = save_file_path + save_file_name + "." + extension
        file = open(full_path, "w")
        file.close()
        save_to_file(full_path, _save)
        change_config("save", "save_file", "'" + save_file_name + "'")
        print("Creating new save file")
        new = True
    return save_file_name, new
Example #3
0
import threading
import socket
import time
import select

from core.display import Text
from core.configs import get_value, change_config

input_color = get_value("customization", "input_color")
choice_size = get_value("display", "choice_font_size")
choice_font = get_value("display", "choice_font")
server_color = get_value("customization", "server_color")
choice_color = get_value("display", "choice_font_color")
default_host = get_value("server", "default_host")
default_port = get_value("server", "default_port")

jobs_list = ["Doctor", "Police", "Salesman", "Hooligan"]

timeout = .01
BUFFER_SIZE = 2048


def is_number(num):
    """Checks if num is a number"""
    try:
        int(num)
    except ValueError:
        return False
    return True

Example #4
0
"""Initializes word game"""
import time
import threading

import pygame
from core.display import TextBox, Text
from core.user_input import TypingManager

from core.configs import get_value, change_config

# Initialize Pygame
pygame.init()

# Pull values from configs
fps = get_value("display", "fps")
resolution = get_value("display", "resolution")

border_color = get_value("customization", "border_color")
border_size = get_value("customization", "border_size")

mouse_hotkeys = get_value("mouse_hotkeys")
keyboard_hotkeys = get_value("keyboard_hotkeys")
alt_hold_time = get_value("input", "alt_hold_time")

display = pygame.display.set_mode(resolution, pygame.RESIZABLE)
pygame.display.set_caption("The Odyssey+")
pygame_clock = pygame.time.Clock()

status_color = get_value("customization", "status_color")
dead_color = get_value("game_customization", "dead_color")
number_color = get_value("customization", "number_color")
import time
import threading

import pygame
from core.display import TextBox, Text
from core.user_input import TypingManager

from core.configs import get_value

# Initialize Pygame
pygame.init()

# Pull values from configs
fps = get_value("display", "fps")
resolution = get_value("display", "resolution")

border_color = get_value("customization", "border_color")
border_size = get_value("customization", "border_size")

display = pygame.display.set_mode(resolution, pygame.RESIZABLE)
pygame.display.set_caption("The Odyssey")
pygame_clock = pygame.time.Clock()

status_color = get_value("customization", "status_color")
prompt_color = get_value("customization", "prompt_color")
input_color = get_value("customization", "input_color")
background_color = get_value("customization", "background_color")

textbox_updates = {}

temporary_box_starts = {}
"""
import os
import time

import jsonpickle
import json
# import pickle
# from cryptography.fernet import Fernet

from core.files import get_game_root, check_path
from core.configs import get_value, change_config

# key = b'9kuDNxazpWoLSeDo9RBbtcCzaYuCzKbgX5m46MY_gqY='
# cipher_suite = Fernet(key)

extension = get_value("save", "extension")


def save_to_file(game_save, file_name, saves_path=None):
    """Pickles, encrypts, and saves to file_path"""

    for _object in game_save.get_path():
        _object.clear_font()

    if isinstance(saves_path, type(None)):
        saves_path = get_saves_path()

    file_path = saves_path + file_name

    if os.path.isfile(file_path):
        os.remove(file_path)
Example #7
0
def main():
    """Starts the program"""
    from core.display import TextBox
    from core.user_input import TypingManager
    global user_input, simulation_text_to_add

    # Initialize Pygame
    pygame.init()
    pygame.mixer.init()

    # Pull values from configs
    fps = get_value("display", "fps")
    resolution = get_value("display", "resolution")

    border_color = get_value("customization", "border_color")
    border_size = get_value("customization", "border_size")
    background_color = get_value("customization", "background_color")

    display = pygame.display.set_mode(resolution, pygame.RESIZABLE)
    pygame.display.set_caption("Halo Life: Online")
    pygame_clock = pygame.time.Clock()

    # Setup textboxes
    bounds = [(0, 0, .5, .8), (0, .8, 1, 1), (.5, 0, 1, .4), (.5, .4, 1, .6),
              (.5, .6, 1, .8)]
    text_box_names = ["simulation", "input", "tooltips",
                      "community verification",
                      "personal verification"]
    text_boxes = {}

    index = 0
    # Create textboxes
    for box in text_box_names:
        text_boxes[box] = TextBox(box, bounds[index], "",
                                  border_color=border_color,
                                  border_size=border_size)
        # Action and objects boxes are justified
        if "verification" in box:
            text_boxes[box].set_alignment("justified")
        index += 1

    simulation_text_list = []

    # Declare typing manager
    typing_manager = TypingManager(False)

    # Declare Game thread
    game_thread = Game()
    game_thread.setDaemon(True)
    game_thread.start()

    # Variable Declaration
    return_pressed = False

    # Begin game loop
    quit_running = False
    while not quit_running:
        display.fill(background_color)

        # Render Textboxes
        for box in text_boxes:
            text_boxes[box].render(display, resolution)

        # Handle typing
        typing_returns = typing_manager.type_loop()
        current_input_string = typing_returns[0]
        string_returned = typing_returns[2]
        if string_returned and not return_pressed:
            return_pressed = True
            user_input = current_input_string
            current_input_string = ""
            typing_manager.string = ""

        text_boxes["input"].set_text_list(current_input_string)

        # Handle Pygame Events
        for event in pygame.event.get():
            # Screen Resized
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_RETURN:
                    return_pressed = False

            if event.type == pygame.VIDEORESIZE:
                display = pygame.display.set_mode(event.dict["size"],
                                                  pygame.RESIZABLE)
                resolution = event.dict["size"]

            # Screen closed
            elif event.type == pygame.QUIT:
                pygame.display.quit()
                quit_running = True
                break

            else:
                # Push events to textboxes and typing manager
                old_tooltip = None
                for box in text_boxes:

                    new_tooltip, tooltip_scroll, hovered = text_boxes[box].handle_event(
                        event, pygame.mouse.get_pos())
                    # Check for tooltip
                    if isinstance(new_tooltip, type(None)):
                        text_boxes["tooltips"].set_text_list("")
                    elif new_tooltip != old_tooltip:
                        # Only display tooltip if have not already
                        text_boxes["tooltips"].set_text_list(new_tooltip)
                        old_tooltip = new_tooltip
                typing_manager.handle_event(event)

        if quit_running:
            break

        pygame_clock.tick(fps)
        pygame.display.flip()

        # Update simulation textbox if new text
        if len(simulation_text_to_add) > 0:
            for text in simulation_text_to_add:
                simulation_text_list.append(text)
            simulation_text_to_add = []
            text_boxes["simulation"].set_text_list(simulation_text_list)
Example #8
0
"""Initializes word game"""
import threading
import socket
import select
from time import sleep

import pygame

from core.configs import get_value
from core.display import Text

simulation_text_to_add = []
user_input = None

status_color = get_value("customization", "status_color")
prompt_color = get_value("customization", "prompt_color")
choice_color = get_value("customization", "choice_color")
allow_notifications = get_value("audio", "allow_notifications")
volume = get_value("audio", "volume")
default_port = get_value("server", "default_port")
default_host = get_value("server", "default_host")

jobs = ["Law Officer", "First Responder", "Ruffian", "Military Officer"]

timeout = .01
unhandled_data = []


class Player(object):
    """Stores information for individual player"""
Example #9
0
"""
Includes methods to allow for user input
"""
import pygame

from core.configs import get_value

key_tick = get_value("input", "key tick")
key_repeat_delay = get_value("input", "key repeat delay")
max_keys_pressed = get_value("input", "max keys pressed")
unshifted_keys = get_value("input", "unshifted keys")
shifted_keys = get_value("input", "shifted keys")

alphanumerals = "abcdefghijklmnopqrstuvwxyz1234567890"


class TypingManager(object):  # TODO: Keep cursor in bounds
    """Controls typing by tracking key presses
    Called Externally.

    :type enable_cursor: bool
    """
    def __init__(self, enable_cursor=True):
        self.keys = {}
        self.cursor_pos = 0
        self.string = ""
        self.enable_cursor = enable_cursor

    @staticmethod
    def is_character(key):
        """Tests whether given key is a character.
Example #10
0
"""
Includes classes allowing for the displaying of text.
Wordwrap, fonts, scrolling, and tooltips are all handled here.
"""
import pygame

from core.configs import get_value

default_font = get_value("display", "default_font")
default_color = get_value("display", "default_color")
default_font_size = get_value("display", "default_font_size")

has_tooltip_color = get_value("customization", "has_tooltip_color")

lines_per_scroll = get_value("display", "lines_per_scroll")
min_scroll_bar_height = get_value("display", "min_scroll_bar_height")

priority_word_wrap_chars = get_value("display", "priority_word_wrap_chars")


class Text(object):
    """Stores a phrase, font, color, and tooltip

    :type text: str
    :type tooltip: list[Text] | str | None
    :type color: tuple[int, int, int]
    :type highlight_color: tuple[int, int, int] | None
    :type font_name: str
    :type font_size: int
    :type bold: bool
    :type italic: bool
Example #11
0
"""Stores information relating to NPCs"""
import random

from core.display import Text
from core.configs import get_value, list_to_dict

from core.tools import weighted_choice

header_color = get_value("customization", "header_color")
header_size = get_value("customization", "header_size")
number_color = get_value("customization", "number_color")
npc_color = get_value("game_customization", "npc_color")

starting_health = get_value("game_objects", "starting_health")
starting_attacks = get_value("game_objects", "starting_attacks")
starting_weapons = get_value("game_objects", "starting_weapons")


class NPC(object):
    """Stores information relating to NPCs

    :type health_stats: None | Stats
    :type attacks: None | list[Attack]]
    :param aggressiveness: scale from 0 to 100 percent chance to attack
    """
    def __init__(self,
                 name="You",
                 _type=None,
                 health_stats=starting_health,
                 aggressiveness=90,
                 _attacks=starting_attacks,