Esempio n. 1
0
    def exit_window(self):
        # Menus in game
        if self.app_states == AppStates.GAME:
            if self.game.target_mode:
                self.game.quit_target_mode()

            # Si pas de menu, on propose de quitter
            elif not self.game.current_menu:
                self.game.current_menu = QuitMenu(self)
            # Si menu, avec back to main quand on exit
            elif self.game.current_menu.back_to_main:
                self.app_states = AppStates.MAIN_MENU
                self.current_menu = MainMenu(self)
                self.game.close_menu()
            else:
                # on quitte le menu actuel pour revenir au jeu
                self.game.close_menu()

        elif self.app_states == AppStates.MAIN_MENU:
            # Je suis dans le main menu, je quitte l'appli
            if isinstance(self.current_menu, MainMenu):
                self.quit_app = True
            else:
                self.current_menu = MainMenu(self)
        blt.clear()
        blt.refresh()
Esempio n. 2
0
 def __init__(self):
     window = system.get_window()
     self.title_label = Label('Headshot', font_name=press_start_2p, font_size=36)
     self.title_label.anchor_x = 'center'
     self.title_label.anchor_y = 'center'
     self.main_menu = MainMenu()
     self.resize()
     window.on_key_press = self.main_menu.on_key_press
     self.main_menu.focused = True
Esempio n. 3
0
    def test_localization_menu_button(self):

        main_menu = MainMenu(self.driver)
        main_menu.selectLocalization()
        # check the head name
        self.assertEqual(
            "Localization",
            self.driver.find_element(By.ID, "localizationHeading").text)
        # check the url
        self.assertTrue(self.driver.current_url.find('localization') > 0)
Esempio n. 4
0
 def __init__(self, width, height):
     super().__init__()
     self.width = width
     self.height = height
     self.setSceneRect(0, 0, width, height)
     self.timer = QtCore.QBasicTimer()
     self.playing = False
     self.pause_menu = PauseMenu(self)
     self.dead_menu = DeadMenu(self)
     self.win_menu = WinMenu(self)
     self.main_menu = MainMenu(self)
     self.main_menu.construct_main_menu()
     self.game = None
Esempio n. 5
0
    def start(self):
        self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), MODE)
        self.gameboard = GameBoard((GAME_SIZE, GAME_SIZE), self)
        self.scoreboard = ScoreBoard((WINDOW_WIDTH - GAME_SIZE, WINDOW_HEIGHT), self.score_manager)
        self.topmenu = TopMenu((GAME_SIZE, WINDOW_HEIGHT - GAME_SIZE))
        self.mainmenu = MainMenu((WINDOW_WIDTH, WINDOW_HEIGHT), self)
        self.gameovermenu = GameOverMenu((WINDOW_WIDTH, WINDOW_HEIGHT), self)

        while not self.done:
            key = pygame.key.get_pressed()
            left, right = self._get_movement(key)

            #if key[pygame.K_ESCAPE]:
            #    self.done = True

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.done = True

            if self.state == GameState.Running:
                self._tick(left, right)
            elif self.state == GameState.MainMenu:
                self._main_menu_tick(left, right)
            elif self.state == GameState.GameOver:
                self._game_over_tick()


            pygame.display.flip()

            self.time_passed = self.clock.tick(FPS)

        pygame.quit()
Esempio n. 6
0
    def run(self):
        # initialize controls.
        key = libtcod.Key()
        mouse = libtcod.Mouse()

        self.app_states = AppStates.MAIN_MENU
        self.current_menu = MainMenu(self)

        # main loop
        while not libtcod.console_is_window_closed():
            # check key / mouse event
            libtcod.sys_check_for_event(
                libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

            self.render_engine.render_app(self, mouse)

            if self.game and self.game.reset_game_windows:
                self.render_engine.reset_render_windows()

            self.input_handler.press(key)

            if self.app_states == AppStates.GAME:
                self.game.game_turn()

            if self.quit_app:
                break
Esempio n. 7
0
    def __init__(self, driver):
        self.driver = driver
        self.wait = WebDriverWait(self.driver, EXPLICIT_TIMEOUT)

        self.main_menu = MainMenu(self.driver)

        self.page_url = None
Esempio n. 8
0
    def create_user(self, email, username, password):
        """Creates a new user from their credentials and signs them into the system"""
        # Encrypt the password and setup the user dict
        password = bcrypt.hashpw(password.encode(), self.salt).hex()
        user_post = DBPostCreator.create_user_post(email, username, password,
                                                   self.get_outer_ip())
        # Register the user in the server
        threading.Thread(
            target=self.server_communicator.create_user(user_post),
            daemon=True).start()
        # Cache stats
        cache = self.cache_stats(username)
        # Close the welcome screen
        self.running = False
        # Stop all music
        for sound in self.BACKGROUND_MUSIC.values():
            sound.stop()

        MainMenu(
            user_post,
            cache,
            self.server_communicator,
            self.width,
            self.height,
            self.refresh_rate,
            self.background_path,
        ).run()
        pygame.quit()
Esempio n. 9
0
    def login_continue(self):
        """Process the login info given"""
        user_inputs = tuple(self.textboxes.values())
        user_identifier = user_inputs[0]
        password = user_inputs[1]
        valid_user = True

        if user_identifier == "":
            self.create_popup_button(r"Please enter Username\Email")
            valid_user = False

        if password == "":
            self.create_popup_button(r"Please enter a Password")
            valid_user = False

        if not valid_user:
            return

        # Encrypt the password and get the user dict from the server
        password = bcrypt.hashpw(password.encode(), self.salt).hex()
        user = self.server_communicator.get_user(user_identifier, password)

        # Update the user's latest ip
        if user:
            """if user["online"]:
            self.create_popup_button("User already connected")
            return"""
            new_outer_ip = self.get_outer_ip()
            # Update routine user stats (online, ip etc...)
            print("hello")
            threading.Thread(
                target=self.server_communicator.on_connection,
                args=(
                    user["username"],
                    new_outer_ip,
                ),
                daemon=True,
            ).start()
            # Cache stats
            cache = self.cache_stats(user["username"])
            # Close the welcome screen
            self.running = False
            # Stop all music
            for sound in self.BACKGROUND_MUSIC.values():
                sound.stop()
            MainMenu(
                cache["user"],
                cache,
                self.server_communicator,
                self.width,
                self.height,
                self.refresh_rate,
                self.background_path,
            ).run()
            pygame.quit()
            self.running = True
        else:
            self.reset_textboxes()
            self.create_popup_button("Invalid credentials")
Esempio n. 10
0
    def test_recruitment_menu(self):
        main_menu = MainMenu(self.driver)
        base_page = BasePage(self.driver)
        main_menu.selectRecruitment()
        header = base_page.get_header()
        self.assertEqual('Candidates', header)

        self.driver.set_window_size(100, 100)
        # If the window is small there is no way to click by standard way
        # self.driver.find_element_by_link_text("Vacancies").click()
        # The only way is to use JS query
        # self.driver.execute_script("document.querySelector('#menu_recruitment_viewJobVacancy').click()")
        # OR the easier way
        self.driver.execute_script(
            'arguments[0].click()',
            self.driver.find_element_by_link_text("Vacancies"))

        header = base_page.get_header()
        self.assertEqual('Vacancies', header)
Esempio n. 11
0
class MainInterface(Interface):
    title_label: Label = None
    main_menu: Menu = None

    def __init__(self):
        window = system.get_window()
        self.title_label = Label('Headshot', font_name=press_start_2p, font_size=36)
        self.title_label.anchor_x = 'center'
        self.title_label.anchor_y = 'center'
        self.main_menu = MainMenu()
        self.resize()
        window.on_key_press = self.main_menu.on_key_press
        self.main_menu.focused = True

    def on_draw(self):
        self.title_label.draw()
        self.main_menu.draw()

    def resize(self):
        window = system.get_window()
        self.main_menu.move(window.width / 2, 100)
        self.title_label.x = window.width / 2
        self.title_label.y = window.height / 2
Esempio n. 12
0
    def run(self):
        self.app_states = AppStates.MAIN_MENU
        self.current_menu = MainMenu(self)

        while True:
            if blt.has_input():
                key = blt.read()

                self.input_handler.press(key)

            self.render_engine.render_app(self)

            if self.app_states == AppStates.GAME:
                self.game.game_turn()

            if self.quit_app:
                break
Esempio n. 13
0
class Scene(QtWidgets.QGraphicsScene):
    def __init__(self, width, height):
        super().__init__()
        self.width = width
        self.height = height
        self.setSceneRect(0, 0, width, height)
        self.timer = QtCore.QBasicTimer()
        self.playing = False
        self.pause_menu = PauseMenu(self)
        self.dead_menu = DeadMenu(self)
        self.win_menu = WinMenu(self)
        self.main_menu = MainMenu(self)
        self.main_menu.construct_main_menu()
        self.game = None

    def display_main_menu(self):
        self.playing = False
        self.close_all_game_menus()
        self.main_menu.construct_main_menu()

    def display_game_view(self, game):
        self.clear()
        self.close_all_game_menus()
        self.setBackgroundBrush(
            QtGui.QBrush(QtGui.QImage(SPRITE_MAIN_BACKGROUND)))
        self.game = game
        grounds = self.game.grounds
        coins = self.game.coins
        spikes = self.game.spikes
        clouds = self.game.clouds
        enemies = self.game.enemies
        boxes = self.game.boxes
        flag = self.game.flag
        player = self.game.player
        player.scene = self
        self.game.scene = self

        self.addItem(player)
        self.addItem(flag)

        for cloud in clouds:
            self.addItem(cloud)

        for ground in grounds:
            self.addItem(ground)

        for box in boxes:
            self.addItem(box)

        for enemy in enemies:
            self.addItem(enemy)

        for spike in spikes:
            self.addItem(spike)

        for coin in coins:
            self.addItem(coin)

        self.add_point_text()
        self.add_time_text()
        self.timer.start(CLOCK_SPEED, self)
        self.game.start()
        self.playing = True

    def add_point_text(self):
        self.point_text = QtWidgets.QGraphicsTextItem()
        self.point_text.setPos(797, 11)
        self.addItem(self.point_text)
        self.update_point_text()

    def update_point_text(self):
        self.point_text.setHtml(
            "<font color='black' align='center' size='5'>Points: {}</font>".
            format(self.game.player.points))

    def add_time_text(self):
        self.time_text = QtWidgets.QGraphicsTextItem()
        self.time_text.setPos(700, 11)
        self.addItem(self.time_text)
        self.update_time_text()

    def update_time_text(self):
        self.time_text.setHtml(
            "<font color='black' align='center' size='5'>Time: {}</font>".
            format(self.game.time))

    def timerEvent(self, e):
        self.game.update()

    def keyPressEvent(self, e):
        pressed = e.key()
        if self.playing:

            if pressed in (LEFT, RIGHT):
                self.game.direction = pressed

            if pressed == SPACE:
                self.game.player.jump()

            if pressed == RETRY:
                if self.game.player.is_dead:
                    self.main_menu.construct_field_select()

            if pressed == PAUSE and not self.game.player.is_dead:
                if self.game.paused:
                    self.resume_game()
                else:
                    self.pause_game()

    def keyReleaseEvent(self, e):
        released = e.key()
        if self.playing:
            if released in (LEFT, RIGHT):
                self.game.direction = None

    def pause_game(self):
        self.game.paused = True
        self.game.timer.stop()
        self.display_pause_menu()
        self.timer.stop()

    def resume_game(self):
        self.game.paused = False
        self.game.timer.start(1000)
        self.hide_pause_menu()
        self.timer.start(CLOCK_SPEED, self)

    def display_pause_menu(self):
        if not self.pause_menu.open:
            self.pause_menu.add_pause_menu()
            self.pause_menu.open = True

    def hide_pause_menu(self):
        if self.pause_menu.open:
            self.pause_menu.remove_pause_menu()
            self.pause_menu.open = False

    def display_dead_menu(self):
        if not self.dead_menu.open:
            self.dead_menu.add_dead_menu()
            self.dead_menu.open = True

    def hide_dead_menu(self):
        if self.dead_menu.open:
            self.dead_menu.remove_dead_menu()
            self.dead_menu.open = False

    def display_win_menu(self, points, time):
        if not self.win_menu.open:
            self.win_menu.add_win_menu(points, time)
            self.win_menu.open = True

    def hide_win_menu(self):
        if self.win_menu.open:
            self.win_menu.remove_win_menu()
            self.win_menu.open = False

    def close_all_game_menus(self):
        self.pause_menu.open = False
        self.dead_menu.open = False
        self.win_menu.open = False
import gc
import globals
import pygame


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

    # Initial set up.
    fps_limit = 60
    clock = pygame.time.Clock()
    globals.init()  # initializes variables
    pygame.display.set_caption('Space Snakes')
    key_store = Keystore()
    scene = MainMenu()

    # Main game loop.
    while True:
        key_store.delta_time = clock.tick(fps_limit) / 1000.0

        if pygame.event.get(pygame.QUIT):
            break

        scene = scene.handle(key_store) or scene
        scene = scene.update() or scene
        scene.draw()
        pygame.display.flip()

    # Kill any RepeatTask threads and exit the game.
    for obj in gc.get_objects():
Esempio n. 15
0
from utilities.threading_helper import RepeatTask

import gc
import globals
import pygame

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

    # Initial set up.
    fps_limit = 60
    clock = pygame.time.Clock()
    globals.init()  # initializes variables
    pygame.display.set_caption('Space Snakes')
    key_store = Keystore()
    scene = MainMenu()

    # Main game loop.
    while True:
        key_store.delta_time = clock.tick(fps_limit) / 1000.0

        if pygame.event.get(pygame.QUIT):
            break

        scene = scene.handle(key_store) or scene
        scene = scene.update() or scene
        scene.draw()
        pygame.display.flip()

    # Kill any RepeatTask threads and exit the game.
    for obj in gc.get_objects():
 def __init__(self, browser):
     self.browser = browser
     self.wait = WebDriverWait(browser, 3)
     self.long_wait = WebDriverWait(browser, 15)
     self.main_menu = MainMenu(browser)
Esempio n. 17
0
class Game:
    controls_reversed = False
    score = 0
    time_passed = 0
    done = False
    screen = None
    obstacle_manager = None
    gameboard = None
    scoreboard = None
    topmenu = None
    gameovermenu = None
    state = GameState.MainMenu
    pump = None
    school_id = 1
    score_increment = 1

    def __init__(self, pump):
        pygame.init()
        self.clock = pygame.time.Clock()
        self.score_manager = ScoreManager(DB_FILE)
        self.pump = pump

    def start(self):
        self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), MODE)
        self.gameboard = GameBoard((GAME_SIZE, GAME_SIZE), self)
        self.scoreboard = ScoreBoard((WINDOW_WIDTH - GAME_SIZE, WINDOW_HEIGHT), self.score_manager)
        self.topmenu = TopMenu((GAME_SIZE, WINDOW_HEIGHT - GAME_SIZE))
        self.mainmenu = MainMenu((WINDOW_WIDTH, WINDOW_HEIGHT), self)
        self.gameovermenu = GameOverMenu((WINDOW_WIDTH, WINDOW_HEIGHT), self)

        while not self.done:
            key = pygame.key.get_pressed()
            left, right = self._get_movement(key)

            #if key[pygame.K_ESCAPE]:
            #    self.done = True

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.done = True

            if self.state == GameState.Running:
                self._tick(left, right)
            elif self.state == GameState.MainMenu:
                self._main_menu_tick(left, right)
            elif self.state == GameState.GameOver:
                self._game_over_tick()


            pygame.display.flip()

            self.time_passed = self.clock.tick(FPS)

        pygame.quit()

    def reverse_controls(self, reversed):
        self.controls_reversed = reversed

    def _get_movement(self, key):
        left = key[LEFT_KEY] == 1
        right = key[RIGHT_KEY] == 1

        if self.controls_reversed:
            left = not left
            right = not right

        return left, right

    def _main_menu_tick(self, select, switch):
        self.mainmenu.update(select, switch)
        self.screen.blit(self.mainmenu.render(), (0, 0))

    def _game_over_tick(self):
        self.screen.blit(self.gameovermenu.render(), (0,0))

    def _tick(self, left, right):
        direction = 0
        if not (left and right):
            if left:
                direction = -1
            elif right:
                direction = 1

        self.score_manager.increment_score(int(self.score_increment))
        self.score_increment += 0.002
        self.gameboard.set_player_direction(direction)
        self.gameboard.tick(self.time_passed)

        self.screen.blit(self.gameboard.render(), (0, WINDOW_HEIGHT - GAME_SIZE))
        self.screen.blit(self.scoreboard.render(), (GAME_SIZE, 0))
        self.screen.blit(self.topmenu.render(), (0, 0))

    def start_game(self, school):
        self.set_state(GameState.Running)
        self.gameboard.reset()
        self.scoreboard.reset()
        self.school_id = self.score_manager.get_school_id(school)
        self.gameboard.reset()
        self.score_increment = 1

    def stop_game(self):
        self.set_state(GameState.GameOver)
        score = self.score_manager.get_score()
        self.score_manager.save_game(self.school_id)
        self.gameovermenu.update(score)
        self.controls_reversed = False

    def set_state(self, state):
        self.state = state

    def drink(self):
        self.scoreboard.remove_life()
        self.pump.drink()
        if self.scoreboard.is_game_over():
            self.stop_game()
Esempio n. 18
0
def main():
    main_menu = MainMenu()
    main_menu.show()