Ejemplo n.º 1
0
def Start():
    opt = ['[OPT] Search', '[OPT] Search (File)', '[OPT] Exit'] ## Creating a list of opt to the Menu.
    ## Get the choice.
    choice = Menu(opt, 'Please choose an option:\n')

    ## Call the choice
    if choice == '[OPT] Search':
        Search.ByPhrase()
    elif choice == '[OPT] Search (File)':
        Search.ByFile()
    else:
        return ## Break the loop.
    Menu(opt, 'The search is over. Please use me again :))')
Ejemplo n.º 2
0
 def run(self):
     """Present the main menu to the user and repeatedly prompt for a valid command"""
     print("Welcome to the Bingo! Deck Generator\n")
     menu = Menu("Main")
     menu.addOption("C", "Create a new deck")
     
     keepGoing = True
     while keepGoing:
         command = menu.show()
         if command == "C":
             self.__createDeck()
         elif command == "X":
             keepGoing = False
Ejemplo n.º 3
0
def main():
    WINDOW_WIDTH = 540
    WINDOW_HEIGHT = 540

    pygame.init()
    display = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
    pygame.display.set_caption("SnakeClone")

    clock = pygame.time.Clock()

    state = GameStates.START
    gamedata = None

    while state != GameStates.EXIT:
        display.fill((0, 0, 0))

        if state == GameStates.GAME:
            game = Game(display, clock)
            state = game.run()
            gamedata = game.forwardData
        elif state == GameStates.MENU:
            state = Menu(display, clock).run()
        elif state == GameStates.SETTINGS:
            state = SettingsScreen(display, clock).run()
        elif state == GameStates.SCORE:
            state = ScoreScreen(display, clock, gamedata).run()
        elif state == GameStates.START:
            state = StartScreen(display, clock).run()
Ejemplo n.º 4
0
    def __deckMenu(self):
        """Present the deck menu to user until a valid selection is chosen"""
        menu = Menu("Deck")
        menu.addOption("P", "Print a card to the screen")
        menu.addOption("D", "Display the whole deck to the screen")
        menu.addOption("S", "Save the whole deck to a file")

        keepGoing = True
        while keepGoing:
            command = menu.show()
            if command == "P":
                self.__printCard()
            elif command == "D":
                print()
                self.__m_currentDeck.print()
            elif command == "S":
                self.__saveDeck()
            elif command == "X":
                keepGoing = False
Ejemplo n.º 5
0
def GetWebsiteBody(phrase: str) -> str:  ## Method to get the website to wrap.
    log(f'Searching on the google by: ' + colored(phrase, 'white'))

    ## Get the Google's result;
    results = googlesearch.search(phrase, num_results=10,
                                  lang='pt-br')  ## Get the google results.

    ## Call the Menu.
    lis = [
        f'[URL] {result}' for result in results
    ]  ## Define the list(menu) to a null list, and add each URL to results.
    url = Menu(
        lis,
        f'Phrase: {colored(phrase,"white")}\n{colored("Choose a website to get the content:", "magenta")}\n'
    )  ## Get the choice.

    ## Threat the website.
    log('Getting the website\'s body...')
    websiteBody = DoReq(url[5:])  ## Get the website's body.
    return f'<spam>{url}</spam>\n{websiteBody}'
Ejemplo n.º 6
0
from src.Menu import Menu
from src.Game import Game
from src.Highscores import Highscores
from src.GameOver import GameOver

# Pygame initialisieren
pygame.init()

# ==============================================================================

screenSize = (1280, 720)
screen = pygame.display.set_mode(screenSize)

eventHandler = EventHandler()
highscores = Highscores("./resources/highscores.dat")
menu = Menu(screenSize, eventHandler)
game = Game(screenSize, eventHandler, highscores.highscore)
gameOver = GameOver(screenSize, eventHandler)

clock = pygame.time.Clock()

# ==============================================================================

while eventHandler.windowActive:
    # Events abhandeln
    eventHandler.handleEvents()

    if eventHandler.pressed_Esc:
        highscores.active = False
        gameOver.active = False
        game.state = Game.GameStates.inactive
Ejemplo n.º 7
0
import pygame
from src.Game import Game
from src.Window import Window
from src.Menu import Menu
from src.State import State

if __name__ == '__main__':
    pygame.init()

    window = Window()
    current_state = Menu(window)
    while window.is_open():
        window.fill_base()
        for event in pygame.event.get():
            if event.type == pygame.QUIT or State.is_key_pressed(
                    pygame.K_ESCAPE):
                window.close()
                pygame.quit()

                print("UPDATE: Game window closed")
                break
            state_name = current_state.state
            current_state.keys_pressed_reaction()
            if state_name != current_state.state:
                if current_state.state == State.GAME_STATE or current_state.state == State.RESTART_STATE:
                    # Create new game
                    current_state = Game(window)
                elif current_state.state == State.AI_GAME_STATE or current_state.state == State.AI_RESTART_STATE:
                    current_state = Game(window, State.AI_GAME_STATE)
                elif current_state.state == State.MENU_STATE:
                    current_state = Menu(window)
Ejemplo n.º 8
0
 def open_menu(self):
     self.menu = Menu(screen_size=self.screen_size,
                      color=(20, 30, 200),
                      actor_list=self.team)
     self.show_menu = True
     self.menu.open()
Ejemplo n.º 9
0
class Camera(object):
    def __init__(self, screen_size, roster, flags):
        self.screen_size = screen_size
        self.flags = flags
        self.controller = Controller()
        # build team roster
        self.team = []
        for hero in roster:
            self.add_hero(hero_data=hero)

        self.player = self.team[0]

        self.center_box = pygame.Rect(self.screen_size[0] / 4,
                                      self.screen_size[1] / 4,
                                      self.screen_size[0] / 2,
                                      self.screen_size[1] / 2)

        self.cam_center = (self.screen_size[0] / 2, self.screen_size[1] / 2)
        self.cam_offset_x = 0
        self.cam_offset_y = 0
        self.map = None
        self.menu = None
        self.show_menu = False

        self.notification = None

        self.destination_door = None
        self.fade_alpha = 0
        self.fade_speed = 5
        self.fade_out = False
        self.fade_in = False

        self.text_box = self.build_text_box()
        self.blackness = pygame.Surface(self.screen_size)
        self.blackness.fill((0, 0, 0))
        self.blackness.set_alpha(self.fade_alpha)

        # battle
        self.in_battle = False
        self.battle = None

    def build_text_box(self, left=4, top=500, height=200, color=(20, 30, 200)):
        return TextBox(
            pygame.Rect(left, top, self.screen_size[0] - left * 2, height),
            "TEXT", color)

    def convert_door_destination(self, cords):
        x = int(cords[0]) * self.map.tileset_data["t_width"]
        y = int(cords[1]) * self.map.tileset_data["t_height"]
        return x, y

    def load_map(self, map_name, goto=None):
        self.map = Map(camera=self, directory=map_name)
        if goto:
            self.player.teleport(x=goto[0], y=goto[1])
        elif self.map.starting_location:
            self.player.teleport(x=self.map.starting_location[0],
                                 y=self.map.starting_location[1])
        self.cam_offset_x = self.player.sprite_rect.left
        self.cam_offset_y = self.player.sprite_rect.top

    def draw_map(self, screen, draw_player=True):
        view = pygame.Surface(self.map.map_size)
        self.map.draw(view, passmap=False)
        if draw_player:
            self.player.draw(view)
        self.map.draw_upper(view)
        screen.blit(view, (self.cam_center[0] - self.cam_offset_x,
                           self.cam_center[1] - self.cam_offset_y))

    def open_menu(self):
        self.menu = Menu(screen_size=self.screen_size,
                         color=(20, 30, 200),
                         actor_list=self.team)
        self.show_menu = True
        self.menu.open()

    def close_menu(self):
        self.menu.close()
        self.show_menu = False
        self.menu = None

    def add_hero(self, hero_data):
        with open(path.join(settings.ASS_DATA,
                            "ally_specs.json")) as data_file:
            data = json.load(data_file)[hero_data["DATA"]]
            player_battle = BattleObject(
                name=hero_data["NAME"] or data["NAME"],
                sprite_sheet=SpriteSheet(
                    path.join(settings.BATTLE, data["BATTLE"]["SPRITE"]),
                    data["BATTLE"]["WIDTH"], data["BATTLE"]["HEIGHT"]),
                sprite_rect=pygame.Rect(0, 0, data["BATTLE"]["WIDTH"],
                                        data["BATTLE"]["HEIGHT"]),
                team=0,
                stats=hero_data["STATS"] or data["BATTLE"]["BASE_STATS"])
            player_data = {"properties": data}
            player_data["properties"]["SPEED"] = settings.PLAYER_SPEED
            self.team.append(
                Player(actor_json=player_data, battle_object=player_battle))
            data_file.close()

    def start_battle(self, battle_index):
        self.battle = Battle(screen_size=self.screen_size,
                             battle_index=battle_index,
                             team=[self.player])
        self.in_battle = True

    def update(self, screen):
        if self.notification:
            self.notification.draw(screen)
            if self.controller.any_key():
                self.notification = None
        elif self.in_battle:
            if self.battle.state == "END":
                self.in_battle = False
                self.battle = None
            else:
                self.controller.poll_battle(self.battle)
                self.battle.draw(screen)
        elif self.show_menu:
            self.controller.poll_main_menu(camera=self)
            # performance hit might be if you draw this map under the box
            self.draw_map(screen=screen, draw_player=False)
            if self.menu:
                self.menu.draw(screen)
        else:
            if not self.fade_in and not self.fade_out:
                # check for door intersection here?
                for d in self.map.door_list:
                    if d.door.colliderect(self.player.pass_rect):
                        self.destination_door = d
                        self.fade_alpha = 0
                        self.fade_out = True
                if self.player.acting:
                    self.player.move_to()
                else:
                    self.controller.poll(camera=self,
                                         tbox=self.text_box,
                                         action_map=self.map.action_map)
                # check if camera should shift
                if self.player.sprite_rect.left < self.cam_offset_x - self.center_box.left:
                    self.cam_offset_x -= settings.CAM_SPEED
                elif self.player.sprite_rect.left > self.cam_offset_x + self.center_box.left:
                    self.cam_offset_x += settings.CAM_SPEED
                if self.player.sprite_rect.top < self.cam_offset_y - self.center_box.top:
                    self.cam_offset_y -= settings.CAM_SPEED
                elif self.player.sprite_rect.top > self.cam_offset_y + self.center_box.top:
                    self.cam_offset_y += settings.CAM_SPEED

            # update NPC movement
            for actor in self.map.actor_list:
                if actor.behavior == "WANDER":
                    if actor.internal_clock > 1:
                        actor.move_to()
                        actor.internal_clock -= 1
                    else:
                        x = random.randrange(
                            -3, 4) * actor.position.width + actor.position.left
                        y = random.randrange(
                            -3, 4) * actor.position.height + actor.position.top
                        actor.set_destination(x=x, y=y)
                        # print("MOVING ACTOR from {0}, {1} to {2}, {3}".format(actor.position.left,
                        #                                                       actor.position.top, x, y))
                        actor.internal_clock = random.randrange(200, 400)

            # draw things
            self.draw_map(screen=screen)
            screen.blit(self.blackness, (0, 0))
            if self.text_box:
                self.text_box.draw(screen)

            if self.fade_in:
                if self.fade_alpha > 0:
                    self.fade_alpha -= self.fade_speed
                    self.blackness.set_alpha(self.fade_alpha)
                    screen.blit(self.blackness, (0, 0))
                else:
                    self.fade_in = False
            elif self.fade_out:
                if self.fade_alpha < 255:
                    self.fade_alpha += self.fade_speed
                    self.blackness.set_alpha(self.fade_alpha)
                    screen.blit(self.blackness, (0, 0))
                else:
                    self.fade_out = False
                    self.fade_in = True
                    print(self.destination_door.destination_map)
                    self.load_map(
                        map_name=self.destination_door.destination_map)
                    door_cords = self.convert_door_destination(
                        self.destination_door.destination_cords)
                    self.player.teleport(x=door_cords[0], y=door_cords[1])

    def save_game(self):
        save_path = path.join("..", "data", "save.json")
        char_block = {
            "DATA": "BOBMAN",
            "STATS": self.player.battle_object.stats
        }
        loc_block = {
            "MAP": self.map.name,
            "POSITION":
            (self.player.sprite_rect.left, self.player.sprite_rect.top)
        }
        save_block = {
            "CHAR": char_block,
            "LOC": loc_block,
            "FLAGS": self.flags
        }
        with open(save_path, 'w') as out_file:
            json.dump(save_block, out_file)
            out_file.close()
        self.notification = Notice(screen_size=self.screen_size,
                                   text="GAME SAVED",
                                   color=(80, 80, 150))

    def exit(self):
        print("Exiting gracefully...")
        sys.exit(0)