예제 #1
0
    def init_words(res, req, session):
        user_id, user, tokens = parse_info(req, session)
        ok, named = GameManager.check_for_unnamed(tokens, user, user_id)

        if ok == 0:
            res['response']['text'] = get(INCORRECT)
        elif ok == 1:
            if len(named) == 1:
                res['response']['text'] = get(YOU_NAMED_ONE).format(named[0])
            else:
                res['response']['text'] = get(YOU_NAMED_SEVERAL).format(
                    ", ".join(named))
        else:
            res['response']['text'] = GameManager.what_and_how_much(
                named, user)
            res['response']['tts'] = res['response']['text'].replace(
                'слов', 'сл+ов')

        res['response']['buttons'] = [UI.button(get(SOURCE_BTN))]

        if GameManager.check_for_win(user):
            res['response']['text'] += f'\n{get(WIN)}'
            user['state'] = State.HELLO
            res['response']['buttons'] = [UI.button(get(YES_BTN))]
        else:
            GameManager.show_word(res, user)
예제 #2
0
    def change_word(res, req, session):
        user_id, user, tokens = parse_info(req, session)
        ok, named = GameManager.check_for_unnamed(tokens, user, user_id)
        res['response']['text'] = ''
        if ok:
            res['response']['text'] += GameManager.what_and_how_much(
                named, user) + '\n'

        res['response']['text'] += f'{get(WANNA_CHANGE)}'
        res['response']['buttons'] = [
            UI.button(get(YES_BTN)),
            UI.button(get(NO_BTN))
        ]
        user['state'] = State.WANNA_CHANGE
예제 #3
0
 def stay(res, user):
     res['response']['text'] = f'{get(OK_STAY)}\n' \
                               f'{get(YOUR_WORD)}\n' \
                               f'{user["word"].upper()}.\n' \
                               f'{choice((get(CAN_NAME_SEVERAL), get(I_CAN_CHANGE)))}'
     res['response']['buttons'] = [UI.button(get(SOURCE_BTN))]
     user['state'] = State.PLAY
예제 #4
0
    def start_new_game(res, user, user_id, after_change=False):
        word = DBHelper.get_random_word(WORD_MIN_LENGTH, WORD_MAX_LENGTH)
        res['response']['text'] = f'{get(YOUR_WORD if after_change else START_WORD)}\n' \
                                  f'{word.upper()}.\n'
        res['response']['buttons'] = [UI.button(get(SOURCE_BTN))]

        user['state'] = State.PLAY
        user['word'] = word
        user['named'] = []
        user['unnamed'] = DBHelper.get_words_from_word(word)

        if DBHelper.get_words(user_id)[0] == 0:
            hint = choice(
                list(
                    filter(lambda x: len(x) >= MIN_WORD_LENGTH_TO_HINT,
                           user['unnamed'])))
            res['response']['buttons'].insert(0, UI.button(hint.capitalize()))
            res['response']['text'] += f'Подскажу первое - {hint}.\n'

        res['response'][
            'text'] += f'{choice((get(CAN_NAME_SEVERAL), get(I_CAN_CHANGE)))}'
예제 #5
0
    def hello(res, user, user_id):
        if not DBHelper.exists(user_id):
            DBHelper.new_player(user_id)

        words, daily_words = DBHelper.get_words(user_id)
        if words == 0:
            res['response']['text'] = get(HELLO)
            DBHelper.new_player(user_id)
        else:
            res['response']['text'] = f'{get(HELLO_AGAIN)}\n' \
                                      f'{get(START_FOUND)} {DBHelper.num_and_word(words)}!\n' \
                                      f'{get(PLAY_MORE)}'
            res['response']['tts'] = res['response']['text'].replace(
                'слов', 'сл+ов')
        res['response']['buttons'] = [UI.button(get(YES_BTN))]
        user['state'] = State.HELLO
예제 #6
0
 def leave_yes(res, req, session):
     user_id, user, tokens = parse_info(req, session)
     res['response']['text'] = get(OK_LEAVE)
     res['response']['buttons'] = [UI.button(get(PLAY_BTN))]
     user['state'] = State.HELLO
예제 #7
0
class Game(DirectObject):
    def __init__(self, app):
        self.app = app
        builtins.get_local_file = get_local_file

        #insert the game into buildins for easy gui callback
        builtins.game = self

        #stats
        self.stats = Stats()
        builtins.stats = self.stats

        with loading():
            #database
            self.db = Database('save.db')
            #init the gui system
            self.gui = UI()
            self.gui.software_cursor()
            #make the main menu
            self.gui.load_from_file(get_local_file('ui/layout.json'))
            self.gui.show_hide([
                'special_frame', 'trait_frame', 'perk_frame', 'skill_frame',
                'stats_frame', 'level_up', 'level_down', 'level_node', 'items',
                'paypal', 'shader', 'save', 'exit'
            ])
            self.stats.update_ui()

    def toggle_shader(self):
        if getattr(self, "shader_quad", None) is None:
            winprops = WindowProperties()
            winprops.set_size(1024, 600)
            props = FrameBufferProperties()
            props.set_rgb_color(True)
            props.set_rgba_bits(8, 8, 8, 8)
            props.set_depth_bits(0)
            props.set_aux_rgba(False)
            props.set_srgb_color(False)
            self.fbo = base.graphicsEngine.make_output(
                base.pipe, 'fbo', -2, props, winprops,
                GraphicsPipe.BFSizeTrackHost | GraphicsPipe.BFCanBindEvery
                | GraphicsPipe.BFRttCumulative | GraphicsPipe.BFRefuseWindow,
                base.win.get_gsg(), base.win)

            self.fbo.set_clear_color((0, 0, 0, 0))
            self.color = Texture()
            self.color.set_wrap_u(Texture.WM_clamp)
            self.color.set_wrap_v(Texture.WM_clamp)
            self.fbo.add_render_texture(tex=self.color,
                                        mode=GraphicsOutput.RTMBindOrCopy,
                                        bitplane=GraphicsOutput.RTPColor)
            self.fbo_cam = base.makeCamera2d(self.fbo)
            cm = CardMaker("quad")
            cm.set_frame_fullscreen_quad()

            self.shader_quad = NodePath(cm.generate())
            self.shader_quad.set_shader(
                Shader.load(Shader.SLGLSL, "shaders/crt_v.glsl",
                            "shaders/crt_f.glsl"), 1)
            self.shader_quad.set_shader_input('color_tex', self.color)
            self.shader_quad.reparent_to(render2dp)
        else:
            if self.shader_quad.is_hidden():
                self.shader_quad.show()
                self.fbo.set_active(True)
            else:
                self.shader_quad.hide()
                self.fbo.set_active(False)

    def show_preview(self, name):
        txt = self.db.get_preview(name)
        self.gui['load_preview'].set_text(txt)
        self.gui.show_hide('preview_frame')
        self.last_name = name

    def load_from_db(self):
        self.db.load(self.last_name, self.stats)
        self.toggle_database()
        self.gui['feedback'].set_text('Character loaded!')
        self.gui['feedback_node'].show()

    def save_to_db(self):
        name = self.gui['name_input'].get()
        keys = self.gui['tag_input'].get()
        self.db.save(name, keys, self.stats)
        self.search(True)

    def search(self, show_all=False):
        #remove old buttons
        names_to_remove = []
        for name, element in self.gui.elements.items():
            if name.startswith('charater_load_'):
                names_to_remove.append(name)
        for name in names_to_remove:
            self.gui.remove_button(name)
        #find characters
        if show_all:
            records = self.db.search()
        else:
            records = self.db.search(self.gui['search_input'].get())

        #create buttons
        for name, keys, s, p, e, c, i, a, l in records:

            txt = '{name:<38}{keys:<59}{s:<8}{p:<8}{e:<8}{c:<8}{i:<8}{a:<8}{l:<8}'.format(
                name=name, keys=keys, s=s, p=p, e=e, c=c, i=i, a=a, l=l)
            self.gui.button(txt=txt,
                            sort_dict={
                                "name": name,
                                "tag": keys,
                                "s": s,
                                "p": p,
                                "e": e,
                                "c": c,
                                "i": i,
                                "a": a,
                                "l": l
                            },
                            cmd="game.show_preview('" + name + "')",
                            parent="database_frame_canvas",
                            width=1000,
                            pos=[3, i * 32],
                            mono_font=1,
                            center=0,
                            name='charater_load_' +
                            name.lower().replace(' ', '_'))
        self.gui.sort_buttons('database_frame_canvas', 'name')

    def toggle_database(self):
        if self.gui['trait_frame'].is_hidden():
            self.toggle_inventory()
        popup = ['database_frame', 'save_frame']
        editor = [
            'special_frame', 'trait_frame', 'perk_frame', 'skill_frame',
            'stats_frame', 'level_up', 'level_down', 'items', 'paypal',
            'shader', 'save', 'exit', 'level_node'
        ]
        if self.gui['database_frame'].is_hidden():
            self.gui.show_hide(popup, editor)
            self.search(True)
        else:
            self.gui.show_hide(editor, popup)
        self.gui.show_hide(None, 'preview_frame')

    def toggle_inventory(self):
        if self.gui['trait_frame'].is_hidden():
            self.gui.show_hide(
                ['trait_frame', 'perk_frame', 'skill_frame'],
                ['bonus_frame', 'weapon_frame', 'target_frame', 'hit_frame'])
            self.gui['items']['text'] = 'INVENTORY'
        else:
            if self.stats.level == 1:
                self.gui['feedback'].set_text('Level up first!')
            return
            self.gui.show_hide(
                ['bonus_frame', 'weapon_frame', 'target_frame', 'hit_frame'],
                ['trait_frame', 'perk_frame', 'skill_frame'])
            self.gui['items']['text'] = 'CHARACTER'

    def support(self, hide=False):
        popup = 'support_frame'
        editor = [
            'special_frame', 'trait_frame', 'perk_frame', 'skill_frame',
            'stats_frame', 'level_up', 'level_down', 'items', 'paypal',
            'shader', 'save', 'exit', 'level_node'
        ]
        if hide:
            self.gui.show_hide(editor, popup)
            self.gui['items']['text'] = 'INVENTORY'
        else:
            self.gui.show_hide(popup, editor)
            self.gui.show_hide(
                [],
                ['bonus_frame', 'weapon_frame', 'target_frame', 'hit_frame'])

    def do_nill(self):
        pass

    def save_screen(self):
        base.screenshot('character')

    def exit_game(self):
        with open('config.ini', 'w') as config_filename:
            Config.write(config_filename)
        self.app.final_exit()