class Game:
    BG = (255, 255, 255)

    def __init__(self):
        self.WIDTH = 1300
        self.HEIGHT = 900
        self.win = pygame.display.set_mode((self.WIDTH, self.HEIGHT))
        self.leaderboard = Leaderboard(100, 120)
        self.board = Board(310, 120)
        self.top_bar = TopBar(10, 10, 1280, 100)
        self.top_bar.change_round(1)

    def draw(self):
        self.win.fill(self.BG)
        self.leaderboard.draw(self.win)
        self.top_bar.draw(self.win)
        self.board.draw(self.win)
        pygame.display.update()

    def run(self):
        run = True
        clock = pygame.time.Clock()
        while run:
            clock.tick(30)
            self.draw()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    run = False
                    break

        pygame.quit()
Exemple #2
0
def start(currentUser):
    global win, curUsr, best
    curUsr = currentUser
    session = boto3.resource(
        'dynamodb',
        aws_access_key_id='AKIAIOPUXE2QS7QN2MMQ',
        aws_secret_access_key='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',
        region_name="ca-central-1")
    table = session.Table('highscores')

    try:
        response = table.get_item(Key={'peopleid': curUsr})
        best = response['Item']['quicktype']
    except:
        best = 10000000

    win = pygame.display.set_mode((w_width, w_height))
    pygame.display.set_caption('Quick Type')
    title = startfont1.render('Quick Type', 1, (255, 255, 255))

    startBtn = button('Start Game', 30, 250, 50, (40, 40, 40))
    infoBtn = button('Learn to Play', 30, 250, 50, (40, 40, 40))
    btns = [startBtn, infoBtn]
    run = True
    globalTable = Leaderboard(curUsr, 'quicktype', 'global', win, 300, 380,
                              150, 130)
    friendTable = Leaderboard(curUsr, 'quicktype', 'friend', win, 300, 380,
                              550, 130)
    while run:
        pygame.time.delay(50)
        win.fill(bg)
        globalTable.draw()
        friendTable.draw()
        win.blit(title, (w_width / 2 - title.get_width() / 2, 0))
        startBtn.draw(win, 175, w_height - 80)
        infoBtn.draw(win, w_width - 425, w_height - 80)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            if event.type == pygame.MOUSEMOTION:
                pos = pygame.mouse.get_pos()
                for btn in btns:
                    if btn.isMouseOver(pos):
                        btn.hover(win)
                    else:
                        btn.update(win)

            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                if startBtn.isMouseOver(pos):
                    run = False
                elif infoBtn.isMouseOver(pos):
                    showInfoScreen()
        pygame.display.update()

    win.fill(bg)
    pygame.display.update()
    main()
def mainScreen(usr, hover=False):
    global shopButton, title, curUsr
    curUsr = usr
    surf = pygame.Surface((1080, 600))
    w = title.get_width()
    h = title.get_height()
    surf.blit(back, (0, 0))
    surf.blit(title, ((1080 / 2 - (w / 2)), 50))
    # For Shop Button
    '''
    if hover == True:S
        text = font.render('Ball Shop', 1,(0, 0, 0))
    else:
        text = font.render('Ball Shop', 1, (51, 51, 153))
    surf.blit(text, (960, 12))
    shopButton = text.get_rect()
    shopButton[0] = 960
    shopButton[1] = 12'''
    # For course Button
    i = buttons[0]
    surf.blit(course1, (i[0], i[1]))
    text = font.render(i[4], 1, (51, 51, 153))
    surf.blit(text, (i[0] + ((i[3] - text.get_width()) / 2), i[1] + i[3] + 10))
    text = font.render('Best: ' + getBest(), 1, (51, 51, 153))
    surf.blit(text, (i[0] + ((i[3] - text.get_width()) / 2), i[1] + i[3] + 40))
    #text = font.render('Coins: ' + getCoins(), 1, (51,51,153))
    #surf.blit(text, (10, 10))

    #draw leaderboard

    globalTable = Leaderboard(curUsr, 'golf', 'global', surf, 300, 380, 90,
                              200)
    friendTable = Leaderboard(curUsr, 'golf', 'friend', surf, 300, 380, 680,
                              200)
    globalTable.draw((0, 0, 0))
    friendTable.draw((0, 0, 0))

    win.blit(surf, (0, 0))
    pygame.display.update()
Exemple #4
0
def main():
    # set window position
    a = 3
    b = 23
    os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (a, b)

    file = 'scores.csv'

    pg.init()

    pg.mixer.music.load('sounds/background.wav')
    pg.mixer.music.play(-1)

    start_screen = StartScreen(IMAGES_PATH + 'shuttle.ico',
                               IMAGES_PATH + 'galaxy.jpg', SCREEN_TITLE,
                               SCREEN_WIDTH, SCREEN_HEIGHT)
    action = start_screen.get_action()

    while action != 3:
        if action == 0:
            new_game = Game(IMAGES_PATH + 'shuttle.ico', file,
                            IMAGES_PATH + 'galaxy.jpg', SCREEN_TITLE,
                            SCREEN_WIDTH, SCREEN_HEIGHT)
            new_game.run_game_loop(0, 0)
            pg.mixer.music.load('sounds/background.wav')
            pg.mixer.music.play(-1)
        elif action == 1:
            # show leaderboard
            leaderboard = Leaderboard(IMAGES_PATH + 'shuttle.ico',
                                      IMAGES_PATH + 'galaxy.jpg', file,
                                      SCREEN_TITLE, SCREEN_WIDTH,
                                      SCREEN_HEIGHT)
            leaderboard.draw()
        action = start_screen.get_action()

    pg.quit()
    quit()
Exemple #5
0
class Game:
    BG = (255, 255, 255)
    COLORS = {
        (255, 255, 255): 0,
        (0, 0, 0): 1,
        (255, 0, 0): 2,
        (0, 255, 0): 3,
        (0, 0, 255): 4,
        (255, 255, 0): 5,
        (255, 140, 0): 6,
        (165, 42, 42): 7,
        (128, 0, 128): 8
    }

    def __init__(self, win, connection=None):
        pygame.font.init()
        self.connection = connection
        self.win = win
        self.leaderboard = Leaderboard(50, 125)
        self.board = Board(305, 125)
        self.top_bar = TopBar(10, 10, 1280, 100)
        self.top_bar.change_round(1)
        self.players = []
        self.skip_button = TextButton(85, 830, 125, 60, (255, 255, 0), "Skip")
        self.bottom_bar = BottomBar(305, 880, self)
        self.chat = Chat(1050, 125)
        self.draw_color = (0, 0, 0)
        self.drawing = False

    def add_player(self, player):
        self.players.append(player)
        self.leaderboard.add_player(player)

    def draw(self):
        self.win.fill(self.BG)
        self.leaderboard.draw(self.win)
        self.top_bar.draw(self.win)
        self.board.draw(self.win)
        self.skip_button.draw(self.win)
        if self.drawing:
            self.bottom_bar.draw(self.win)
        self.chat.draw(self.win)
        pygame.display.update()

    def check_clicks(self):
        """
        handles clicks on buttons and screen
        :return: None
        """
        mouse = pygame.mouse.get_pos()

        # Check click on skip button
        if self.skip_button.click(*mouse) and not self.drawing:
            skips = self.connection.send({1: []})

        clicked_board = self.board.click(*mouse)

        if clicked_board:
            self.board.update(*clicked_board, self.draw_color)
            self.connection.send(
                {8: [*clicked_board, self.COLORS[tuple(self.draw_color)]]})

    def run(self):
        run = True
        clock = pygame.time.Clock()
        while run:
            clock.tick(60)

            try:
                # get board
                response = self.connection.send({3: []})
                if response:
                    self.board.compressed_board = response
                    self.board.translate_board()

                # get time
                response = self.connection.send({9: []})
                self.top_bar.time = response

                # get chat
                response = self.connection.send({2: []})
                self.chat.update_chat(response)

                # get round info
                self.top_bar.word = self.connection.send({6: []})
                self.top_bar.round = self.connection.send({5: []})
                self.drawing = self.connection.send({11: []})
                self.top_bar.drawing = self.drawing
                self.top_bar.max_round = len(self.players)

                # get player updates
                '''response = self.connection.send({0:[]})
                self.players = []
                for player in response:
                    p = Player(player)
                    self.add_player(p)'''
            except:
                run = False
                break

            self.draw()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    run = False
                    break

                if pygame.mouse.get_pressed()[0]:
                    self.check_clicks()
                    self.bottom_bar.button_events()

                if event.type == pygame.KEYDOWN:
                    if not self.drawing:
                        if event.key == pygame.K_RETURN:
                            self.connection.send({0: [self.chat.typing]})
                            self.chat.typing = ""
                        else:
                            # gets the key name
                            key_name = pygame.key.name(event.key)

                            # converts to uppercase the key name
                            key_name = key_name.lower()
                            self.chat.type(key_name)

        pygame.quit()
Exemple #6
0
class Game:
    BG = (255, 255, 255)

    def __init__(self):
        self.WIDTH = 1300
        self.HEIGHT = 1000
        self.win = pygame.display.set_mode((self.WIDTH, self.HEIGHT))
        self.leaderboard = Leaderboard(50, 125)
        self.board = Board(305, 125)
        self.top_bar = TopBar(10, 10, 1280, 100)
        self.top_bar.change_round(1)
        self.players = [
            Player("Tim"),
            Player("Joe"),
            Player("Bill"),
            Player("Jeff"),
            Player("TBob")
        ]
        self.skip_button = TextButton(85, 830, 125, 60, (255, 255, 0), "Skip")
        self.bottom_bar = BottomBar(305, 880, self)
        self.chat = Chat(1050, 125)
        self.draw_color = (0, 0, 0)
        for player in self.players:
            self.leaderboard.add_player(player)

    def draw(self):
        self.win.fill(self.BG)
        self.leaderboard.draw(self.win)
        self.top_bar.draw(self.win)
        self.board.draw(self.win)
        self.skip_button.draw(self.win)
        self.bottom_bar.draw(self.win)
        self.chat.draw(self.win)
        pygame.display.update()

    def check_clicks(self):
        """
        handles clicks on buttons and screen
        :return: None
        """
        mouse = pygame.mouse.get_pos()

        # Check click on skip button
        if self.skip_button.click(*mouse):
            print("Clicked skip button")

        clicked_board = self.board.click(*mouse)

        if clicked_board:
            self.board.update(*clicked_board, self.draw_color)

    def run(self):
        run = True
        clock = pygame.time.Clock()
        while run:
            clock.tick(60)
            self.draw()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    run = False
                    break

                if pygame.mouse.get_pressed()[0]:
                    self.check_clicks()
                    self.bottom_bar.button_events()

                if event.type == pygame.KEYDOWN:
                    # gets the key name
                    key_name = pygame.key.name(event.key)

                    # converts to uppercase the key name
                    key_name = key_name.lower()
                    self.chat.type(key_name)

        pygame.quit()
class Game:
    def __init__(self, win, connection):
        """
        :param win: Window
        :param connection: Connection object
        """
        self.win = win
        self.connection = connection

        self.is_drawing = False
        self.players = []
        self.draw_color = COLORS[1]
        self.game_ended = False
        self.drawer = "No one"

        self.top_bar = TopBar(20, 20, 1040, 80, self)
        self.leaderboard = Leaderboard(20, 120, 270, 60)
        self.board = Board(310, 120, 6)
        self.chat = Chat(810, 120, 250, 580, 30)
        self.bottom_bar = BottomBar(20, 620, 770, 80, self)
        self.person_is_drawing = PersonIsDrawing(310, 620, 480, 80)

    def draw(self):
        """
        Draws Game on window
        :return: None
        """
        self.win.fill(COLORS[0])

        self.top_bar.draw(self.win)
        self.leaderboard.draw(self.win)
        self.board.draw(self.win)
        self.chat.draw(self.win)
        if self.is_drawing:
            self.bottom_bar.draw(self.win)
        else:
            self.person_is_drawing.draw(self.win, self.drawer)

        pygame.display.update()

    def handle_click(self):
        """
        Handles clicks on buttons on screen
        :return: None
        """
        mouse = pygame.mouse.get_pos()

        clicked_board = self.board.click(*mouse)
        if clicked_board and self.is_drawing:
            self.connection.send({8: [*clicked_board, COLORS.index(self.draw_color)]})

        if self.is_drawing:
            self.bottom_bar.handle_click(mouse)

    def get_data(self):
        """
        Gets and sets data from server
        :return: None
        """
        self.leaderboard.players = self.connection.send({-1: []})
        self.chat.content = self.connection.send({2: []})
        self.board.compressed_board = self.connection.send({3: []})
        self.top_bar.change_round(self.connection.send({5: []}))
        self.top_bar.word = self.connection.send({6: []})
        self.top_bar.time = self.connection.send({9: []})
        self.is_drawing = self.connection.send({10: []})
        self.drawer = self.connection.send({13: []})

    def run(self):
        """
        Runs the game by getting data from the server
        :return: None
        """
        run = True
        clock = pygame.time.Clock()
        while True:
            try:
                clock.tick(120)
                self.get_data()
                self.board.translate_board()
                self.draw()

                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        raise Exception("Player Quit")
                    if pygame.mouse.get_pressed()[0]:
                        self.handle_click()
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_RETURN and len(self.chat.typing):
                            self.connection.send({0: [self.chat.typing]})
                            self.chat.update_chat()
                        else:
                            key_name = pygame.key.name(event.key).upper()
                            self.chat.type(key_name, self.is_drawing)
            except Exception as e:
                print(f"Closed because {e}")
                break
        pygame.quit()
def start(currentUser):
    global win, curUsr, best
    curUsr = currentUser

    #Init amazon ws tables
    session = boto3.resource('dynamodb',
                             aws_access_key_id='AKIAIOPUXE2QS7QN2MMQ',
                             aws_secret_access_key='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',
                             region_name="ca-central-1"
                             )
    table = session.Table('highscores')

    #Try to get the users best score to display
    try:
        response = table.get_item(
            Key={
                'peopleid':curUsr
            }
        )
        best = response['Item']['integerrecall']
    except:
        best = -1

    #Create pygame window
    win = pygame.display.set_mode((w_width, w_height))
    pygame.display.set_caption('Integer Recall')
    title = startfont1.render('Integer Recall',1,(255,255,255))

    #Init buttons to display on screen
    startBtn = button('Start Game', 30, 250, 50, (64,64,64))
    infoBtn = button('Learn to Play', 30, 250, 50, (64,64,64))
    backBtn = button('< Back', 20, 100, 30, (64, 64, 64))
    btns = [startBtn, infoBtn, backBtn]
    run = True
    #Create leaderboard objects
    globalTable = Leaderboard(curUsr, 'integerrecall', 'global', win, 300, 380, 150, 130)
    friendTable = Leaderboard(curUsr, 'integerrecall', 'friend', win, 300, 380, 550, 130)

    #MAINLOOP for start screen
    while run:
        pygame.time.delay(50)
        win.fill(bg)
        #Show leaderbaord tables
        globalTable.draw((255,255,255),True)
        friendTable.draw((255,255,255),True)
        win.blit(title, (w_width / 2 - title.get_width() / 2, 0))
        startBtn.draw(win, 175, w_height - 80)
        infoBtn.draw(win, w_width - 425, w_height - 80)
        backBtn.draw(win, 20, 20)

        #Waitr for user to click start
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            if event.type == pygame.MOUSEMOTION:
                pos = pygame.mouse.get_pos()
                for btn in btns:
                    if btn.isMouseOver(pos):
                        btn.hover(win)
                    else:
                        btn.update(win)

            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                if startBtn.isMouseOver(pos):
                    run = False
                elif infoBtn.isMouseOver(pos):
                    showInfoScreen()
                elif backBtn.isMouseOver(pos):
                    backToLauncher()
        pygame.display.update()

    win.fill(bg)
    pygame.display.update()
    main()