def __init__(self):
        """
       Initialize game object
        """

        # Initialize game and create a screen object.
        pygame.init()
        # Initialize settings and screen object.
        self.settings = Settings()
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Alien Invasion")
        self.play_button = Button(self, "Play")

        # create the Ship.
        self.ship = Ship(self.settings, self.screen)
        # Make a group to store the bullets.
        self.bullets = Group()
        self.aliens = Group()
        self.create_fleet()

        # Create a Game stats and scoreboard instance.
        self.stats = GameStats(self)
        self.sb = Scoreboard(self)
        self.game_paused = True
Esempio n. 2
0
def chatter():
    """
    Message хүлээж аваад хариу өгөх хаяг
    :return:
    """
    if Settings.get_reciever_format() == 'json':
        if not request.json:
            abort(400)
        start_time = int(round(time.time() * 1000))
        incoming = request.json
        if incoming['message']['type'] == 'text':
            if len(incoming['message']['content']) > 1:
                incoming['message']['content'] = BayesClassifierCore.answer(
                    incoming['message']['content'])
            else:
                incoming['message'][
                    'content'] = Settings.get_default_unknown_text()
        elif incoming['message']['type'] == 'btn':
            abort(400)
        end_time = int(round(time.time() * 1000))
        incoming['message']['time'] = str(end_time - start_time)
        return json.dumps(incoming)
    elif Settings.get_reciever_format() == 'xml':
        return
    elif Settings.get_reciever_format() == 'form-data':
        return
Esempio n. 3
0
 def make_connection():
     """
     DBMS тэй холболт үүсгэх
     :return:
     """
     if DatabaseWorker.isConnected is False:
         if Settings.get_db_engine() == 'mongodb':
             DatabaseWorker.db = MongoClient(
                 Settings.get_db_host(),
                 Settings.get_db_port())[Settings.get_db_name()]
             DatabaseWorker.isConnected = True
Esempio n. 4
0
    def __init__(self):
        super().__init__()
        self.settings = Settings()

        self.iconbitmap(os.path.join(SCRIPT_PATH, 'favicon.ico'))
        self.title('Evernote Dump')
        self.geometry("500x600")
Esempio n. 5
0
 def __init__(self):
   # Get settings class
   self.settings = Settings()
   # Set initial player queue
   self.queue = ''
   self.queue_addition = ''
   self.merge_sound_counter = 0
   self.merge = ''
Esempio n. 6
0
def play():
    # Initialization.
    pygame.mixer.pre_init(44100, -16, 2, 512)
    pygame.mixer.init()
    pygame.mixer.music.load('assets/sounds/music.wav')
    pygame.mixer.music.set_volume(0.3)
    pygame.mixer.music.play(-1)
    pygame.init()
    pygame.display.set_caption('Space Invaders')
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    stats = Stats(settings)
    high_score_screen = HighScoreScreen(screen, stats)
    bullets = Group()
    lasers = Group()
    bunkers = Group()
    alien_fleet = AlienFleet(settings, screen, lasers)
    scoreboard = Scoreboard(settings, screen, stats, alien_fleet, bullets)
    ship = Ship(settings, screen, stats, scoreboard, high_score_screen,
                alien_fleet, bullets, lasers)
    start_screen = StartScreen(settings, screen, stats, high_score_screen,
                               scoreboard, ship, alien_fleet, bunkers)
    main_clock = pygame.time.Clock()

    # Game loop.
    playing = True
    while playing:
        game_helper.on_event(stats, start_screen, high_score_screen, ship)
        game_helper.on_collision(settings, stats, scoreboard, ship,
                                 alien_fleet, bullets, lasers, bunkers)
        game_helper.on_update(stats, ship, alien_fleet, bullets, lasers)
        game_helper.draw(settings, screen, stats, scoreboard, start_screen,
                         high_score_screen, ship, alien_fleet, bullets, lasers,
                         bunkers)
        main_clock.tick(60)
Esempio n. 7
0
 def __init__(self, synth, step):
   # Get settings class
   self.settings = Settings()
   self.synth = synth
   self.step = step
Esempio n. 8
0
 def __init__(self, step):
   # Get settings class
   self.settings = Settings()
   self.step = step
   self.sample_string = ''
   self.current_step_samples = ''
Esempio n. 9
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import sys


from gui import load_gui
from dump import run_parse
from utilities.settings import Settings

if __name__ == "__main__":
    settings = Settings()
    arg_parser = argparse.ArgumentParser(prog='Evernote Dump',
                                         description='Evernote Dump exports and extracts evernote notes and '
                                                     'attachments from .enex files. All notes and attachments '
                                                     'will keep their original file created and accessed dates. '
                                                     'Notes will be converted to markdown format. Tags and other '
                                                     'embedded information will be formatted and added to the end '
                                                     'of each note. Evernote Dump works by streaming the .enex file '
                                                     'through a parser so even extremely large .enex files '
                                                     'should work. ')
    arg_parser.add_argument('enex', nargs='*',
                            help='Filename of exported Evernote .enex file. Multiple files or "*" wildcards can be '
                                 'used if your terminal supports wildcard expansion.')
    arg_parser.add_argument('-p', action='store_true',
                            help='Preserve original filenames for attachments.')
    arg_parser.parse_args(namespace=settings)

    if len(sys.argv) == 1:
        load_gui()
    else:
class AlienInvasion:
    """
    Class representing the game.
    """
    def __init__(self):
        """
       Initialize game object
        """

        # Initialize game and create a screen object.
        pygame.init()
        # Initialize settings and screen object.
        self.settings = Settings()
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Alien Invasion")
        self.play_button = Button(self, "Play")

        # create the Ship.
        self.ship = Ship(self.settings, self.screen)
        # Make a group to store the bullets.
        self.bullets = Group()
        self.aliens = Group()
        self.create_fleet()

        # Create a Game stats and scoreboard instance.
        self.stats = GameStats(self)
        self.sb = Scoreboard(self)
        self.game_paused = True

    def run_game(self):
        """
        Main function to be executed.
        """

        # Start the main loop for the game.
        while True:
            self.check_events()
            if self.stats.game_active and self.game_paused:
                self.ship.update()
                self.update_bullets()
                self.update_aliens()
            self.update_screen()

    def get_number_of_rows(self, ship_height, alien_height):
        """
        Determine the number of rows of aliens that fit on the screen.
        """
        available_space_y = self.settings.screen_height - 3 * alien_height - ship_height
        number_of_rows = int(available_space_y / (2 * alien_height))
        return number_of_rows

    def get_number_of_aliens_x(self, alien_width):
        """
        Determine the number of aliens that fit in a row.
        """
        available_space_x = self.settings.screen_width - 2 * alien_width
        number_of_aliens_x = int(available_space_x / (2 * alien_width))
        return number_of_aliens_x

    def create_alien(self, alien_number, row_number):
        """
        Create one alien.
        """
        alien = Alien(self)
        alien_width = alien.rect.width
        alien.x = alien_width + 2 * alien_width * alien_number
        alien.rect.x = alien.x
        alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
        self.aliens.add(alien)

    def create_fleet(self):
        """
        Create a full fleet of aliens.
        """
        # Create one alien to check the size and the number.
        alien = Alien(self)
        number_of_aliens_x = self.get_number_of_aliens_x(alien.rect.width)
        number_of_rows = self.get_number_of_rows(self.ship.rect.height,
                                                 alien.rect.height)
        # Create the fleet of the aliens.
        for row_number in range(number_of_rows):
            for alien_number in range(number_of_aliens_x):
                self.create_alien(alien_number, row_number)

    def check_key_down_events(self, event):
        """
        Respond to key presses.
        """
        if event.key == pygame.K_RIGHT:
            # Move the ship to the right.
            self.ship.moving_right = True
        elif event.key == pygame.K_LEFT:
            self.ship.moving_left = True
        elif event.key == pygame.K_SPACE:
            self.fire_bullet()
        elif event.key == pygame.K_p:
            self.start_game()

    def check_key_up_events(self, event):
        """
        Respond to key releases.
        """
        if event.key == pygame.K_RIGHT:
            # Move the ship to the right.
            self.ship.moving_right = False
        elif event.key == pygame.K_LEFT:
            self.ship.moving_left = False
        elif event.key == pygame.K_ESCAPE:
            self.game_paused = not self.game_paused

    def check_events(self):
        """
        Respond to key presses and mouse events.
        """
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.settings.update_high_score(self)
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = pygame.mouse.get_pos()
                self.check_play_button(mouse_pos)
            elif event.type == pygame.KEYDOWN:
                self.check_key_down_events(event)
            elif event.type == pygame.KEYUP:
                self.check_key_up_events(event)

    def check_play_button(self, mouse_pos):
        """
        Start the new game if play was clicked.
        """
        mouse_x, mouse_y = mouse_pos
        button_clicked = self.play_button.rect.collidepoint(mouse_x, mouse_y)
        if button_clicked:
            self.start_game()

    def start_game(self):
        """
        Start a new game.
        """
        if not self.stats.game_active:

            self.stats.game_active = True
            pygame.mouse.set_visible(False)
            self.stats.reset_stats()
            # Empty the list of aliens and bullets.
            self.aliens.empty()
            self.bullets.empty()

            self.sb.prep_all()
            # Create a new fleet and center the ship.
            self.create_fleet()
            self.ship.center_ship()

    def update_bullets(self):
        """
        Update position of bullets and get rid of old ones.
        """
        # Update bullets position.
        self.bullets.update()
        # Get rid of bullets that have disappeared.
        for bullet in self.bullets.copy():
            if bullet.rect.bottom <= 0:
                self.bullets.remove(bullet)
        self.check_bullet_alien_collisions()

    def check_bullet_alien_collisions(self):
        """
        Respond to bullet-alien collisions.
        """
        collisions = pygame.sprite.groupcollide(self.bullets, self.aliens,
                                                True, True)
        if collisions:
            for aliens in collisions.values():
                self.stats.score += self.settings.alien_reward * len(aliens)
            self.sb.prep_score()
            self.check_high_score()

        if len(self.aliens) == 0:
            # Destroy all bullets and create a new fleet.
            self.bullets.empty()
            self.settings.increase_speed()
            self.stats.level += 1
            self.sb.prep_level()
            self.create_fleet()

    def fire_bullet(self):
        """
        Fire a bullet if the limit is not yet reached.
        """
        if len(self.bullets
               ) < self.settings.bullets_allowed and self.stats.game_active:
            new_bullet = Bullet(self)
            self.bullets.add(new_bullet)

    def update_screen(self):
        """
        Update images on the screen and flip to the new screen.
        """

        # Redraw the screen during each pass through the loop.
        self.screen.fill(self.settings.bg_color)
        self.sb.show_score()
        if self.stats.game_active:
            # Redraw all bullets behind ship and aliens.
            for bullet in self.bullets.sprites():
                bullet.draw_bullet()

            self.ship.blitme()
            self.aliens.draw(self.screen)

        else:
            self.play_button.draw_button()

        # Make the most recently drawn screen visible.
        pygame.display.flip()

    def check_fleet_edges(self):
        """
        Respond properly if any alien reached an edge.
        """
        for alien in self.aliens.sprites():
            if alien.check_edges():
                self.change_fleet_direction()
                break

    def change_fleet_direction(self):
        """
        Drop the entire fleet and change the fleet's direction.
        """
        for alien in self.aliens.sprites():
            alien.rect.y += self.settings.fleet_drop_speed
        self.settings.fleet_direction *= -1

    def update_aliens(self):
        """
        Check if the fleet is at an edge, and then update the positions.
        """
        self.check_fleet_edges()
        self.aliens.update()

        # Now check for alien ship collisions.
        if pygame.sprite.spritecollideany(self.ship, self.aliens):
            self.lose_a_life()
        # Check if aliens hit the bottom.
        self.check_aliens_bottom()

    def lose_a_life(self):
        """
        Respond to ship being hit by alien.
        """
        if self.stats.ships_left > 0:
            # Decrement the number of ships left.
            self.stats.ships_left -= 1
        else:
            self.stats.game_active = False
            pygame.mouse.set_visible(True)

        # Empty the list of aliens and bullets.
        self.aliens.empty()
        self.bullets.empty()
        self.sb.prep_ships()

        # Create a new fleet and center the ship.
        self.create_fleet()
        self.ship.center_ship()

        sleep(0.5)

    def check_aliens_bottom(self):
        """
        Check if aliens hit the bottom.
        """
        screen_rect = self.screen.get_rect()
        for alien in self.aliens.sprites():
            if alien.rect.bottom >= screen_rect.bottom:
                # Treat this a loosing a life.
                self.lose_a_life()
                break

    def check_high_score(self):
        """
        Check to see if there is a new high score.
        """
        if self.stats.score > self.stats.high_score:
            self.stats.high_score = self.stats.score
            self.sb.prep_high_score()
Esempio n. 11
0
 def __init__(self, name, settings):
     self._settings = Settings(settings, name)
     self._check_required_fields()
Esempio n. 12
0
 def setUp(self) -> None:
     self.s = Settings()
Esempio n. 13
0
import json
import inquirer
from utilities.settings import Settings

# Get settings class
settings = Settings()

# Get our samples available to edit
samples = Settings().samples

# def main_screen_prompt():
#   main_screen = [
#     inquirer.List(
#       'main_screen',
#       message="What would you like to` edit?",
#       choices=['bpm','samples'],
#     ),

#   ]
#   return inquirer.prompt(main_screen)

# settings_to_edit = main_screen_prompt()


# NOTE: Here is where we will plan to get settings and sequence imputs to rewrite settings file.
def sample_prompt(samples):
    question_sample = [
        inquirer.List(
            'sample',
            message="What sample to edit?",
            choices=samples.keys(),
Esempio n. 14
0
import json
import time
import requests

app = Flask(__name__)


@app.route('/')
def hello_world():
    """
    :return: index
    """
    return 'Hello World!'


@app.route('/chatter', methods=[Settings.get_reciever_method()])
def chatter():
    """
    Message хүлээж аваад хариу өгөх хаяг
    :return:
    """
    if Settings.get_reciever_format() == 'json':
        if not request.json:
            abort(400)
        start_time = int(round(time.time() * 1000))
        incoming = request.json
        if incoming['message']['type'] == 'text':
            if len(incoming['message']['content']) > 1:
                incoming['message']['content'] = BayesClassifierCore.answer(
                    incoming['message']['content'])
            else:
Esempio n. 15
0
 def __init__(self, settings):
     self.settings = Settings(settings)
     self.sites = [Site(name, settings) for name in self.settings.names]
     self._setup_process()