示例#1
0
    def __init__(self):
        '''Constructor for the Demo class.'''
        initialise_db()

        self._clock = pg.time.Clock()
        self._keys = Keys()
        self._eventhandler = EventHandler(self._keys)

        self._screen = initialise_demo_display()
        self._renderer = Renderer(self._screen)
        self._title_screen = TitleScreen(self._renderer)
        self._help_screen = HelpScreen(self._renderer)

        self._party = create_demo_party()

        self.battle = False
        self.title = False
        self.help = False
示例#2
0
 def open_file(self, path):
     # TODO unicode
     # path = unicode(path)
     self.pattern = jef.Pattern(path)
     # TODO Check this
     self.info_popup.update_values(self.pattern)
     qApp.setOverrideCursor(Qt.WaitCursor)
     self.path = path
     self.colorDockWidget.set_pattern(self.pattern)
     self.canvas.setRenderer(
         Renderer(self.pattern, self.colorModel, self.stitches_only))
     self.setWindowTitle(
         "{} - Viewer for Janome Embroidery Files [*]".format(path))
     qApp.restoreOverrideCursor()
示例#3
0
def main():
    height = 22
    width = 18
    display_height = height * 25
    display_width = width * 25
    display = pygame.display.set_mode((display_width, display_height))

    pygame.display.set_caption("Tetris")

    level = Level()
    event_queue = EventQueue()
    renderer = Renderer(display, level)
    clock = Clock()
    game_loop = GameLoop(level, renderer, event_queue, clock)

    pygame.init()
    game_loop.start()
示例#4
0
def main():
    """Start the game.

    Read display size, set title and create classes needed for UI.

    """
    pygame.init()
    display_info = pygame.display.Info()
    display_width = display_info.current_w
    display_heigth = display_info.current_h
    display = pygame.display.set_mode((display_width, display_heigth))
    pygame.display.set_caption(TITLE)

    audio = AudioService()
    renderer = Renderer(display, display_width, display_heigth)
    event_queue = EventQueueService()
    clock = ClockService(FPS)
    info = InformationService()
    user_interface = UI(audio, renderer, event_queue, clock, info)

    user_interface.start_menu()
示例#5
0
class Demo:
    '''A class that functions as the demo itself.

    attr:
        clock: Pygame Clock object
        keys: Keys object
        eventhandler: EventHandler object
        screen: Pygame display
        renderer: Renderer object
        titlescreen: TitleScreen object
        party: lst; party formation used in the demo
        battle: bool; tells whether the demo is on battle state
        title: bool; tells whether the demo is on title state
        help: bool; tells whether to display the help menu
    '''
    def __init__(self):
        '''Constructor for the Demo class.'''
        initialise_db()

        self._clock = pg.time.Clock()
        self._keys = Keys()
        self._eventhandler = EventHandler(self._keys)

        self._screen = initialise_demo_display()
        self._renderer = Renderer(self._screen)
        self._title_screen = TitleScreen(self._renderer)
        self._help_screen = HelpScreen(self._renderer)

        self._party = create_demo_party()

        self.battle = False
        self.title = False
        self.help = False

    def loop(self):
        '''The main game loop.'''
        self.title = True
        running = True

        while running:
            self._eventhandler.check_input()
            if self._keys.QUIT:
                running = False
            if self.battle:
                self._new_battle()
            if self.help:
                self._help_loop()
            if self.title:
                self._title_loop()
            self._keys.reset_keys()

        conn = get_db_connection()
        drop_tables(conn)
        conn.close()

    def _render(self):
        '''Updates the game display. Called once per loop.'''
        self._renderer.update_display()

    def _new_battle(self):
        '''Creates a new Battle object, and runs the battle loop.'''
        battle = Battle(
            self._clock, self._renderer,
            self._eventhandler, self._party
            )
        battle.loop()
        self.battle = False
        if not self._keys.QUIT:
            self.title = True
            self._party = create_demo_party()

    def _help_loop(self):
        '''Displays the help screen.'''
        self._keys.reset_keys()

        while self.help:
            self._eventhandler.check_input()
            if self._keys.QUIT or self._keys.BACK:
                self.help = False
                if self._keys.BACK:
                    self.title = True
            self._help_screen.render()
            self._render()
            self._clock.tick(FPS)

    def _title_loop(self):
        '''Loops the title screen menu if on title status.'''
        self._title_screen.menu.active = True
        self._title_screen.menu.reset_cursor()
        self._keys.reset_keys()

        while self.title:
            self._eventhandler.check_input()
            if self._keys.QUIT:
                self.title = False
            action = self._title_screen.update(self._keys)
            self._keys.reset_keys()
            if action == 'battle':
                self.battle = True
                self.title = False
            elif action == 'help':
                self.help = True
                self.title = False
            elif action == 'quit':
                self._keys.QUIT = True
            self._title_screen.render()
            self._render()
            self._clock.tick(FPS)

        self._title_screen.menu.reset_buttons()
示例#6
0
class Game:
    '''Luokka, joka siirtelee sovelluksen näkymää
    alkunäytön, pelisääntöjen, peliohjeiden ja pelitilan välillä.

    Attributes:
        height: Ruudukon korkeus
        width: Ruudukon leveys
        coefficient: Ruudukon kerroin
        display_height: Näytön korkeus
        display_width: Näytön leveys
        screen: Pygame-näyttö
        score_repository: ScoreRepository-olio
        event_queue: EventQueue-olio
        event_handler: EventHandler-olio
        clock: Clock-olio
        renderer: Renderer-olio
        field: Field-olio
        block_setter: BlockSetter-olio
        gameloop: Gameloop-olio
        '''
    def __init__(self, score_repository=default_score_repository):
        '''Luokan konstruktori, joka alustaa kaikki tarvittavat oliot
        näytön näyttämistä ja uuden pelikierroksen aloittamista varten.

        Args:
            score_repository: Oletuksena ScoreRepository-olio
        '''
        self._height = len(FIELD)
        self._width = len(FIELD[0])
        self._coefficient = CELL_SIZE // 2.5
        self._display_height = self._width * CELL_SIZE
        self._display_width = self._height * CELL_SIZE

        pygame.init()
        self._screen = pygame.display.set_mode(
            (self._display_width, self._display_height))
        pygame.display.set_caption("Tetris")

        self._score_repository = score_repository
        self._event_queue = EventQueue()
        self._event_handler = EventHandler()
        self._clock = Clock()
        self._renderer = Renderer(self._screen, self._height, self._width,
                                  self._coefficient, CELL_SIZE,
                                  self._score_repository, self._clock,
                                  self._event_handler, self._event_queue)
        self._field = Field(FIELD)
        self._block_setter = BlockSetter()
        self._gameloop = Gameloop(self._event_queue, self._event_handler,
                                  self._clock, self._renderer, self._field,
                                  self._block_setter)

    def start_screen(self):
        '''Näyttää aloitusnäytön, siirtyy muihin käyttöliittymän tiloihin käyttäjän syötteen
        perusteella, käsittelee tietokannan tietoja, alustaa uuden ruudukon ja kutsuu itsensä
        '''
        self._renderer.show_start_screen()

        score = self._event_handler.handle_menu_events(self._event_queue,
                                                       self._renderer,
                                                       self._gameloop)

        if score == "DELETE":
            if self._event_handler.ensure_deleting(self._renderer,
                                                   self._event_queue):
                self._score_repository.delete_all()
        elif score:
            self._score_repository.add_new_score(score[0], score[1])

        self.initialize()
        self.start_screen()

    def initialize(self):
        '''Alustaa ruudukon uutta pelikierrosta varten
        '''
        FIELD = [[0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
        self._field = Field(FIELD)
        self._gameloop = Gameloop(self._event_queue, self._event_handler,
                                  self._clock, self._renderer, self._field,
                                  self._block_setter)
示例#7
0
class Game:
    """A class to handle the overall game and transitioning from game to menu.

    Attributes:
        labs: The array of Lab objects fetched from the lab database.
        renderer: The Renderer object to render games and menus.
        event_handler: The EventHandler object to interpret keyboard input from the player.
        running: A boolean value to tell whether the game is running. When this value is
        false, the game closes.
        playing: A boolean value to tell whether a game is being played. True displays a lab
        to play.
        main_menu: A Main Menu object to be displayed to the player.
        game_over_menu: A Game Over Menu to be displayed to the player.
        lab_selection_menu: A Lab Selection Menu to be displayed to the player.
        lab_size_menu: A Lab Size Menu to be displayed to the player.
        lab: The chosen lab to be played.
        curr_menu: The current menu being displayed to the player.
    """
    def __init__(self):
        """The class contructor, which creates a new Game.
        """

        pygame.init()
        self.labs = lab_repository.find_all()
        self.renderer = Renderer(self)
        self.event_handler = EventHandler()
        self.lab_designer = LabDesigner(self, 2)
        self.running, self.playing, self.designing = True, False, False
        self.main_menu = MainMenu(self)
        self.game_over_menu = GameOverMenu(self)
        self.lab_selection_menu = LabSelectionMenu(self)
        self.lab_size_menu = LabSizeMenu(self)
        self.lab = self.labs[0]
        self.curr_menu = self.main_menu

    def run(self):
        """The method to run a Game; either a game is being played or a menu is being displayed.
        """

        while self.playing:
            self._play()

        if self.designing:
            self._design()

        self.lab.reset_lab()
        self.labs = lab_repository.find_all()
        self.lab_selection_menu.update_lab_selection_menu()

    def _play(self):
        """The method to play a chosen lab. This method handles player input,
            checks whether a player has won or lost, and renders the lab.
        """

        if self.lab.rat_got_cheese():
            self.game_over_menu.status = "You win"
            self.curr_menu = self.game_over_menu
            self.playing = False

        if self.lab.rat_hit_trap():
            self.game_over_menu.status = "You lose"
            self.curr_menu = self.game_over_menu
            self.playing = False

        self.event_handler.handle_events()

        if self.event_handler.quit_key:
            self.running, self.playing = False, False
        if self.event_handler.left_key:
            self.lab.move_rat(x_change=-SCALE)
        if self.event_handler.right_key:
            self.lab.move_rat(x_change=SCALE)
        if self.event_handler.up_key:
            self.lab.move_rat(y_change=-SCALE)
        if self.event_handler.down_key:
            self.lab.move_rat(y_change=SCALE)

        self.renderer.render_lab(self.lab)

    def _design(self):
        """The method to initiate designing a lab. This method passes the display
            over to the LabDesigner object.
        """

        self.lab_designer.start()