Exemple #1
0
    def play(self):
        while True:
            gf.check_events(stats=self.stats,
                            play_button=self.play_button,
                            hs_button=self.hs_button,
                            ship=self.ship,
                            sound=self.sound)
            if self.stats.game_active:
                self.ship.update()
                self.barriers.update()
                self.aliens.update()

            self.screen.fill(self.settings.bg_color)
            self.ship.draw()
            self.aliens.draw()
            self.barriers.draw()
            self.sb.show_score()
            if not self.stats.game_active:
                menu = Main_Menu(screen=self.screen)
                menu.draw()
                self.play_button.draw()
                self.hs_button.draw()
                self.sound.pause_bg()
                if self.stats.show_high_score:
                    self.sb.show_score()
            else:
                if not self.sound.playing_bg: self.sound.unpause_bg()
            pg.display.flip()
Exemple #2
0
    def __init__(self):
        pygame.init()
        self.width = 1024
        self.height = 768
        self.screen = pygame.display.set_mode((self.width, self.height))
        self.screen.blit(sprites("Sprites").load("Loading"), (0, 0))
        pygame.display.update()
        self.running = True

        self.AllSprites = sprites("Sprites")
        self.AllSprites.loadAll()

        self.clock = pygame.time.Clock()
        self.state = "Menu"
        self.sounds = soundManager("Sound")
        self.mainMenu = Main_Menu(self.screen, self.width, self.height, self.AllSprites, self.sounds)
        self.game = game(self.screen, self.width, self.height, self.AllSprites, self.sounds)
        
        self.lobby = None
        self.multiGame = None

        self.fontsize = 10
        self.font = pygame.font.Font(os.path.join('Fonts', 'nasalization-rg.ttf'), self.fontsize)

        pygame.event.set_blocked(pygame.NOEVENT)
Exemple #3
0
    def __authenticate(self, email, password):
        '''To Authenticate using IMAP Server'''

        # Show the authenticating message
        utils.show_status_message(self.__stdscr,
                                  "Authenticating....",
                                  isLoading=True)
        try:
            email = email.strip()
            password = password.strip()
            self.__is_valid(email, password)
            # Authenticate using email and password, it throws exception if something went wrong
            IMAP(email, password)
            # Store in .bashbird directory
            cred = Credentials()
            cred.store_credentials(email, password)
            utils.show_status_message(self.__stdscr,
                                      "Authentication Successful",
                                      time_to_show=1)
            # Show main menu after authentication is completed
            main_menu = Main_Menu(self.__stdscr)
            main_menu.show()

        except Exception as e:
            utils.show_status_message(self.__stdscr, str(e), time_to_show=3)
def level_01():
    pygame.init()
    
    res = (1290, 712)
    screen = pygame.display.set_mode(res)
    
    my_font = pygame.freetype.Font("NotoSans-Regular.ttf", 23)
    
    Button_Set = []
    Button_Set.append(Button((255,255,0),5,670, 140, 30, 'EXIT'))
    
    pos_x = [360,490,620,750]
    random.shuffle(pos_x)
    pos_y = [50, 255, 460]
    random.shuffle(pos_y)
    Card_Set = []
    card_x = 0
    card_y = 0
    
    for i in range(12):
        Card_Set.append(Card((0, 255, 0), pos_x[card_x], pos_y[card_y], 125, 200,i//2+1))
        card_x += 1
        if (card_x > 3):
            card_x = 0
            card_y += 1


    
    pos = pygame.mouse.get_pos()
    mb = pygame.mouse.get_pressed()
    
    for card in Card_Set:
        card.draw(screen)
    
    num_cards_selected = 0
    card_shape = 0
    score = 0
    p_attempt = 0
    pair_set = 6
    
    while (True):
        screen.fill((0,0,20))
        
        my_font.render_to(screen, (20, 20), ('Score:' + str(score)), (255,255,0))
        pos = pygame.mouse.get_pos()
        mb = pygame.mouse.get_pressed()
        for button in Button_Set:
            button.draw(screen)
            if button.isOver(pos):
                button.color = (255, 255 ,255)
            else:
                button.color = (255,255,0)

        for card in Card_Set:
            if card.selected == False:
                
                if card.isOver(pos):
                    card.color = (255, 255 ,255)
                    card.draw(screen)
                    if (mb[0]):
                        
                        if num_cards_selected == 3:
                            num_cards_selected = 0
                            pass
                        
                        card.selected = True
                        num_cards_selected += 1
                        
                        if num_cards_selected == 2:
                            p_attempt += 1

                            if card_shape == card.pair:
                                if card.selected == True:
                                    c1 = None
                                    c2 = None  
                                    for c in Card_Set:
                                        if card.pair == c.pair:
                                            if c1 != None:
                                                c2 = c
                                            else:
                                                c1 = c
                                    Card_Set.remove(c1)
                                    Card_Set.remove(c2)
                                    
                        # Adds value to score, resets attempt values and removes one pair from the level       
                                    score += 100
                                    num_cards_selected = 0
                                    p_attempt = 0
                                    pair_set -= 1
                            for i in range (1, p_attempt+1):
                                if i == 1:
                                    continue
                                else:
                                    score -= 20*(p_attempt-1)
                                    if score < 0:
                                        score = 0
                                    break        
                else:
                    card.color = (0, 255, 0) 
                    card.draw(screen)
                
            else:
                if num_cards_selected == 3:
                    card.selected = False
                    continue
                
                
                card_shape = card.pair
                
                card.shape_draw(screen, card.pair)   
                    
                if card.isOver(pos):
                    card.color = (255, 255 ,255)
                    card.draw(screen, 2)
                else:
                    card.color = card.RGB[card.pair-1]
                    card.draw(screen, 2)
            
        for event in pygame.event.get():
            if (event.type == pygame.QUIT):
                exit()

        if pair_set == 0:
            my_font.render_to(screen, (1290//2-button.width, 720//2-button.height//2), 'CONGRATULATIONS!', random.choice(card.RGB))))
            

        if event.type == pygame.MOUSEBUTTONDOWN:
            for button in Button_Set:
                if button.isOver(pos):
                    if button.text == 'EXIT':
                        return Main_Menu(True)

        pygame.display.flip()
def main():
  playing = False
  splash_img_x = 800
  splash_img_y = 329

  # Initialize pygame, with the default parameters
  pygame.init()
  # Define the size/resolution of our window
  res = (1280, 720)

  # Create a window and a display surface
  # Caption and icon
  pygame.display.set_caption("Shuffle")
  pygame.display.set_icon(pygame.image.load("resources/shuffle_icon.png"))
  screen = pygame.display.set_mode(res)
  
  # Main Menu
  main_menu = Main_Menu(res)

  # Start Music Player
  music_player = Music_Player(res)

  # Load Splash Image
  splash_img = pygame.image.load("resources/shuffle.png")

  font = pygame.font.Font("resources/fonts/NotoSans-Regular.ttf", 20)

  # Start High Scores Manager
  hs_manager = High_Scores_Manager()

  game = None
  action = None

  # Game loop, runs forever
  while (True):
    for event in pygame.event.get():
      if (event.type == pygame.QUIT):
        exit()
      if (event.type == pygame.MOUSEBUTTONDOWN):
        pos = pygame.mouse.get_pos()
        music_player.handle_clicks(pos)
        if (not playing):
          action = main_menu.handle_clicks(pos)
          if action == "exit":
            exit()
          elif action == "high_scores":
            hs_manager.toggle_display()
          elif (action != None):
            size = action.split('x')
            game = Game((int(size[0]), int(size[1])), hs_manager, res)
            playing = True
        else:
          playing = game.handle_click(pos)

    screen.fill((0, 0, 20))

    # Music
    if not music_player.is_busy():
      music_player.load_next_song()
      music_player.play()

    music_player.display(screen)

    if (not playing):
      screen.blit(splash_img, (int(res[0] / 2) - int(splash_img_x / 2), int(res[1] / 4) - int(splash_img_y / 2))) # Display Splash Image
      main_menu.display(screen, font)
      hs_manager.display_high_scores(screen, font)
    else:
      game.display(screen, font, res)

    pygame.display.flip()
Exemple #6
0
class ScumInvaders:
    def __init__(self):
        pygame.init()
        self.width = 1024
        self.height = 768
        self.screen = pygame.display.set_mode((self.width, self.height))
        self.screen.blit(sprites("Sprites").load("Loading"), (0, 0))
        pygame.display.update()
        self.running = True

        self.AllSprites = sprites("Sprites")
        self.AllSprites.loadAll()

        self.clock = pygame.time.Clock()
        self.state = "Menu"
        self.sounds = soundManager("Sound")
        self.mainMenu = Main_Menu(self.screen, self.width, self.height, self.AllSprites, self.sounds)
        self.game = game(self.screen, self.width, self.height, self.AllSprites, self.sounds)
        
        self.lobby = None
        self.multiGame = None

        self.fontsize = 10
        self.font = pygame.font.Font(os.path.join('Fonts', 'nasalization-rg.ttf'), self.fontsize)

        pygame.event.set_blocked(pygame.NOEVENT)
        
    def game_loop(self):
        while self.running:

            pygame.event.pump()
            if pygame.event.peek(pygame.QUIT):
                    self.running = False

            if (self.state == "Menu"):
                self.mainMenu.draw()
                self.state = self.mainMenu.update()

                if self.state == "Exit":
                    self.running = False
                
                elif self.state == "Lobby":
                    self.mainMenu.state = "Login"
                    self.lobby = Lobby(self.screen, self.width, self.height, self.AllSprites, self.sounds, self.mainMenu.username, self.mainMenu.socket)
                    self.sounds.playNewMusic('newlobby.ogg')


                elif self.state == "Game":
                    self.game.reset()
            
            elif (self.state == "Lobby"):
                self.lobby.draw()
                output = self.lobby.update()
                if "multiGame" in output:
                    self.screen.blit(self.AllSprites.getSprite("Loading"), (0, 0))
                    self.state = "multiGame"
                    self.multiGame = multiGame(self.screen, self.width, self.height, self.AllSprites,\
                        self.sounds, int(output[-2]), int(output[-1]), self.mainMenu.ip.input, self.lobby.currentRoom, self.lobby.socket)

                else:
                    if output == "Menu":
                        self.sounds.playNewMusic('mainMenu.ogg')
                        self.mainMenu.socket.send("STOP")
                        self.mainMenu.state = "Login"
                        self.mainMenu.connected = False
                        self.mainMenu.loginPressed = False
                        self.mainMenu.loginStatus = ""

                    self.state = output

            elif (self.state == "Game"):
                self.game.draw()
                self.state = self.game.update()

                if self.state == "Exit":
                    self.running = False
            
                elif self.state == "Menu":
                    self.mainMenu.state = "Main"
                    self.sounds.playNewMusic('mainMenu.ogg')

            elif (self.state == "multiGame"):
                self.multiGame.draw()
                self.state = self.multiGame.update()

                if self.state == "Exit":
                    self.running = False

                elif self.state == "Score":
                    self.state = "Lobby"
                    self.lobby.state = "Score"
                    self.lobby.score = self.multiGame.playerList[self.multiGame.clientPlayerNum].score
                    self.sounds.playNewMusic('mainMenu.ogg')
                    
                elif self.state == "Lobby":
                    self.lobby.state = "Room"
                    self.sounds.playNewMusic('newlobby.ogg')

            self.screen.blit(self.font.render(str(int(self.clock.get_fps())), True, pygame.Color(255,255,255)), (0, 0))	
            pygame.display.update()
            self.clock.tick(60)
        
        try:
            self.mainMenu.socket.send("STOP")

        except:
            pass

        pygame.quit()
Exemple #7
0
from main_menu import Main_Menu

Main_Menu().main()