Beispiel #1
0
    def isoob(self):
        """out of bond management"""
        if super().isoob():
            if self.y < -300:
                game.Game.posi += 1
                self.y = 280
            elif self.y > 300:
                game.Game.posi -= 1
                self.y = -280
            elif self.x < -300:
                game.Game.posj -= 1
                self.x = 280
            elif self.x > 300:
                game.Game.posj += 1
                self.x = -280
            game.load()

        elif Rocket.debuginit < 2:  # Weird problems when first loading
            for door in shapes.Door.ldoor[game.Game.posi][game.Game.posj]:
                engine.add_obj(door)
            for key in shapes.Key.lkey[game.Game.posi][game.Game.posj]:
                engine.add_obj(key)
            Rocket.debuginit += 1

        return False
Beispiel #2
0
def main():
    vista.init()
    vista.addsplash()
    pygame.display.set_caption(_("Obb is loading.... Please wait"))
    noise.nexttrack()
    if settings.restart:
        game.restart()
    else:
        game.load()
    context.push(play.Play())
    clock = pygame.time.Clock()
    savetime = settings.savetimer
    while context.top():
        dt = clock.tick(settings.maxfps) * 0.001 * settings.gamespeed
        dt = min(dt, 1.0 / settings.minfps)
        con = context.top()
        events = pygame.event.get()
        keys = pygame.key.get_pressed()
        mousepos = pygame.mouse.get_pos()
        buttons = pygame.mouse.get_pressed()

        if settings.autosave:
            savetime -= dt
            if savetime < 0:
                game.save()
                settings.save()
                savetime = settings.savetimer

        for event in events:
            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
                if settings.saveonquit:
                    settings.save()
                    game.save()
                pygame.quit()
                return
            if event.type == KEYDOWN and event.key == K_F12:
                vista.screencap()
            if event.type == KEYDOWN and event.key == K_F3:
                settings.showfps = not settings.showfps

        con.think(dt, events, keys, mousepos, buttons)
        con.draw()
        if settings.showfps:
            t = pygame.time.get_ticks() * 0.001
            if int(t / 5.0) != int((t - dt) / 5.0):  # Update once every 5 seconds
                fpsstring = "%.1ffps" % clock.get_fps()
                try:
                    mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss // 1024
                    fpsstring += " %sMB" % mem
                except:
                    pass
                pygame.display.set_caption("Obb - %s" % fpsstring)
                if settings.fullscreen:
                    print(fpsstring)
        else:
            pygame.display.set_caption("Obb")
Beispiel #3
0
def input_num(num):
    player = game.load()
    result = game.play(num)
    if player['win'] + 1 < 3 and player['life'] - 1 > 0:
        if result == 'win':
            result = '이겼습니다!'
            show = '이겼습니다. 승리 : {} 기회 : {}'.format(player['win'] + 1,
                                                   player['life'])
        elif result == 'drawwin':
            result = '강화된 {}로 이겼습니다!'.format(player['powerup'])
            show = '강화된 {}로 이겼습니다! 승리 : {} 기회 : {}'.format(
                player['powerup'], player['win'] + 1, player['life'])
        elif result == 'draw':
            result = '비겼습니다'
            show = '비겼습니다. 승리 : {} 기회 : {}'.format(player['win'],
                                                   player['life'])
        else:
            result = '졌습니다.'
            show = '졌습니다.승리 : {} 기회 : {}'.format(player['win'],
                                                 player['life'] - 1)

        return render_template('play.html', data=result, info=show)

    elif player['win'] + 1 >= 3:
        result = '3번 승리로 게임에서 이겼습니다.'
        return render_template('game_result.html', data=result)
    else:
        result = '3번 패배로 게임에서 졌습니다.'
        return render_template('game_result.html', data=result)
Beispiel #4
0
    def __refresh_games(self):
        """Refresh the list of games from the object files"""
        self.games = ["Home"]

        path = "../../../object_files"
        for f in os.listdir(path):
            if fnmatch.fnmatch(f, '*.gme'):
                game_path = path + os.sep + f
                self.games.append(game.load(game_path))
Beispiel #5
0
 def load(self): #TODO
     load_game = load('load_game.txt')
     if load_game:
         gameinfo = load_game[0]
         field = load_game[1]
         self.parent.begin_game(gameinfo, field)
         self.close()
     else:
         self.close_buttons()
         self.no_load_game_button.show()
Beispiel #6
0
    def keyboard_lvl(key):
        """keyboard manager for the level selection menu"""
        total_lvl_number = len(listdir("Files/lvls/"))
        y0 = 4 * Menu.LEVEL_LINE_HEIGHT + Menu.FONT_SIZE

        if key == "Up":
            if Menu.cursor_position_on_screen > 0:
                Menu.cursor_position_on_screen -= 1
            elif Menu.cursor_position == 0:  # and Menu.cursor_position_on_screen == 0
                Menu.cursor_position_on_screen = Menu.MAX_NB_LVL_PER_PAGE - 1
            # in other cases, the arrow remains on the top
            Menu.cursor_position = (Menu.cursor_position - 1) % (total_lvl_number + 1)  # + 1 for the return button
            Menu.select_arrow.y = y0 - Menu.LEVEL_LINE_HEIGHT * Menu.cursor_position_on_screen
            Menu.display_level()

        if key == "Down":
            if Menu.cursor_position_on_screen < Menu.MAX_NB_LVL_PER_PAGE - 1:
                Menu.cursor_position_on_screen += 1
            elif Menu.cursor_position == total_lvl_number:  # and Menu.cursor_position_on_screen == MAX_NB_LVL_PER_PAGE - 1
                Menu.cursor_position_on_screen = 0
            # in other cases, the arrow remains on the bottom
            Menu.cursor_position = (Menu.cursor_position + 1) % (total_lvl_number + 1)  # + 1 for the return button
            Menu.select_arrow.y = y0 - Menu.LEVEL_LINE_HEIGHT * Menu.cursor_position_on_screen
            Menu.display_level()

        if key == "Return":
            engine.del_obj(Menu.select_arrow)
            engine.del_obj(Menu.lvl_rect)
            Menu.select_arrow = Menu.lvl_rect = None
            if Menu.cursor_position == 0:
                Menu.load_main_menu()
            else:
                lvl = "lvl" + str(Menu.cursor_position)

                engine.init_engine()
                game.Game.init_all(lvl)

                engine.add_obj(game.Game.ground)
                engine.add_obj(game.Game.rocket)

                game.cheat()
                engine.set_keyboard_handler(game.keyboard_cb)
                game.load()
Beispiel #7
0
 def saveGame(self):
     from inspect import currentframe, getframeinfo
     from pathlib import Path
     def savegame():
         o = input("Give the save a name: ")
         path = str(Path(getframeinfo(currentframe()).filename).resolve().parent) + str(Path(f'/saves/{o}/'))
         if os.path.exists(path):
             yn = input("The save \""+o+"\" already exists, do you want to overwrite it?\n(Y/N): ")
             if yn.lower() == "y":
                 game.save(o)
                 print("Done Saving!")
                 return True
             else:
                 print('Aborting save!')
                 return False
         else:
             game.save(o)
             print("Done Saving!")
             return True
     o = input("Do you want to:\n1) Save the game\n2) Load another game\n3) Quit game\n")
     if o == '1': # save the game
         savegame()
     elif o == '2': # load a game
         print('Saves:')
         for i, a in enumerate(save.list_saves(), 1):
             print(f'{i}) {a}') # list all the saves
         o = input("Which save do you want to load? ")
         try:
             o = int(o)
             if int(o) > len(save.list_saves()) or int(o) < 1:
                 print("That isn't a valid save!")
             else:
                 game.load(save.list_saves()[o - 1])
         except:
             print("That isn't a valid number!")
     elif o == '3': # quit game
         import menus
         yn = input("Do you want to save first?\n(Y/N) ")
         if yn.lower() == "y":
             if savegame():
                 menus.TitleScreen()
         else:
             menus.TitleScreen()
Beispiel #8
0
 def losealife(self):
     if self.lives == 0:
         game.banner('Game over')
         engine.exit_engine()
         game.Stats.display_stats()
     else:
         self.lives -= 1
         self.speed[0] = self.speed[1] = 0
         self.angle = 90
         self.x = 0
         self.y = 0
         self.skin = Rocket.skin
         game.Game.freeze_spawn = True
         game.banner("Life lost, {} remaining".format(self.lives))
         if game.Game.posi == 2 and game.Game.posj == 3 and not bad_guys.Boss.bossbeaten:
             engine.del_obj(game.Game.boss)
         game.Game.posi = 0
         game.Game.posj = 4
         game.load()
Beispiel #9
0
import value_iteration
import game
import policy_iteration

game = game.Level()
game.load("instances/lvl-n8-2")
game.display()
sol = value_iteration.Solver(game)
#policy = sol.solve_v_a(0.5, 0.000000000000000000000000000000000001)
policy = policy_iteration.solve_p_i(0.99, game)
#game.display_policy(policy)
game.visualize(policy)
#v = va.value_iteration(0.5, 0.001)
#v = sol.policy_iteration(1,False)
#va.display(v)
#res = va.best_policy(v)
#level_1.visualize(res)
Beispiel #10
0
def load():
    loadplayer = game.load()
    return loadplayer
Beispiel #11
0
        print(f"Set your learning language to {args.learning_lang}")
        learning_lang = args.learning_lang
    if mother_lang is None and args.mother_lang is None:
        print("Please specify your mother tongue language")
        exit(1)
    if args.mother_lang is not None:
        print(f"Set your mother tongue language to {args.mother_lang}")
        db_save('mother_lang', args.mother_lang)
        mother_lang = args.mother_lang

    lingo = None
    try:
        print(f"Logging you in as {username}...")
        lingo = duolingo.Duolingo(username, password)
        print(f"Successfully logged in!")
    except duolingo.DuolingoException:
        print(
            'Failed to log you in. Check your username/password and try again.'
        )
        exit(1)

    if args.load:
        load(lingo, learning_lang, mother_lang)
        exit()

    if args.play:
        play(learning_lang, mother_lang)
        exit()

    print("Specify an operation")
Beispiel #12
0
from flask import Flask, render_template, session, request
import game
import random, copy

import sys
f = open('log.txt', 'a')
sys.stdout = f
sys.stderr = f

app = Flask(__name__)
app.config["SECRET_KEY"] = "verysecretmuchlol"
app.config["DEBUG"] = True

game.load()

def aiTurn():
    board = session["board"]
    row, column = game.nextMove(board)
    if row == -1 or column == -1:
        return # no possible actions
    session["own"].append([copy.deepcopy(board), row, column])
    board[row][column] = "o"

def resetSession():
    del session["board"]
    del session["own"]
    del session["player"]

@app.route("/")
def index():
    if "board" not in session:
Beispiel #13
0
def main():

    menu_running = True

    # Start menu music
    pygame.mixer.music.load(globalvars.ASSETS.music_menu)
    pygame.mixer.music.play(-1)

    title_x = constants.CAMERA_WIDTH / 2
    title_y = constants.CAMERA_HEIGHT / 2 - 40
    title_text = "Python - RL"

    # Button addreses
    continue_button_y = title_y + 40
    new_game_button_y = continue_button_y + 40
    options_button_y = new_game_button_y + 40
    quit_button_y = options_button_y + 40

    continue_game_button = draw.UiButton(globalvars.SURFACE_MAIN, 'CONTINUE',
                                         (150, 30),
                                         (title_x, continue_button_y))

    new_game_button = draw.UiButton(globalvars.SURFACE_MAIN, 'NEW GAME',
                                    (150, 30), (title_x, new_game_button_y))

    options_button = draw.UiButton(globalvars.SURFACE_MAIN, 'OPTIONS',
                                   (150, 30), (title_x, options_button_y))

    quit_button = draw.UiButton(globalvars.SURFACE_MAIN, 'QUIT', (150, 30),
                                (title_x, quit_button_y))

    while menu_running:

        list_of_events = pygame.event.get()
        mouse_position = pygame.mouse.get_pos()

        game_input = (list_of_events, mouse_position)

        # Handle menu events
        for event in list_of_events:
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

        # If continue
        if continue_game_button.update(game_input):

            # Stop music menu
            pygame.mixer.music.stop()

            # Start music game
            pygame.mixer.music.load(globalvars.ASSETS.music_background)
            pygame.mixer.music.play(-1)

            # try to load game, start new if problems.
            try:
                game.load()
            except:
                game.new()

            game.main_loop()

        # If new game
        if new_game_button.update(game_input):

            # Stop music menu
            pygame.mixer.music.stop()

            # Start music game
            pygame.mixer.music.load(globalvars.ASSETS.music_background)
            pygame.mixer.music.play(-1)

            game.new()
            game.main_loop()

        if options_button.update(game_input):
            options()

        if quit_button.update(game_input):
            pygame.quit()
            sys.exit()

        # draw menu
        globalvars.SURFACE_MAIN.blit(globalvars.ASSETS.MAIN_MENU_BG, (0, 0))

        text.display(globalvars.SURFACE_MAIN,
                     title_text,
                     constants.FONT_TITLE_SCREEN, (title_x, title_y - 20),
                     constants.COLOR_RED,
                     back_color=constants.COLOR_BLACK,
                     center=True)

        # Draw the buttons
        continue_game_button.draw()
        new_game_button.draw()
        options_button.draw()
        quit_button.draw()

        # update surface
        pygame.display.update()

        globalvars.CLOCK.tick(constants.GAME_FPS)