Beispiel #1
0
    def draw(self):
        time.sleep(.5)
        gameDisplay.fill(black)
        choose = True
        self.draw_count += 1
        if self.draw_count == 5:
            self.war_games()
        else:
            while choose:
                for event in p.event.get():
                    if event.type == p.QUIT:
                        p.quit()
                        quit()

                large_text = p.font.SysFont("comicsansms", 50)
                text_surf, text_rect = __main__.text_objects(
                    "The Game was a Draw", large_text, white)
                text_rect.center = ((width_display / 2),
                                    (height_display * (1 / 4)))
                gameDisplay.blit(text_surf, text_rect)
                __main__.button("REMATCH!", white,
                                (width_display * (1 / 3)) - 100,
                                height_display / 2, 150, 100, dark_green,
                                green, 25, self.reset)
                __main__.button("QUIT!", white, (width_display * (2 / 3)) - 50,
                                height_display / 2, 150, 100, dark_red, red,
                                25, __main__.quit_game)

                clock.tick(15)
                p.display.update()
Beispiel #2
0
    def loser(self):
        time.sleep(.5)
        gameDisplay.fill(black)
        self.lose_count += 1
        choose = True
        while choose:
            for event in p.event.get():
                if event.type == p.QUIT:
                    p.quit()
                    quit()

            large_text = p.font.SysFont("comicsansms", 60)
            text_surf, text_rect = __main__.text_objects(
                "AI is the Winner!", large_text, white)
            text_rect.center = ((width_display / 2),
                                (height_display * (1 / 4)))
            gameDisplay.blit(text_surf, text_rect)
            __main__.button("REMATCH!", white, (width_display - 100) * (1 / 4),
                            height_display / 2, 150, 100, dark_green, green,
                            25, self.reset)
            __main__.button("QUIT!", white, (width_display - 100) * (3 / 4),
                            height_display / 2, 150, 100, dark_red, red, 25,
                            __main__.quit_game)

            clock.tick(15)
            p.display.update()
Beispiel #3
0
 def set_up(self):
     __main__.button("", black, 600, 20, 180, 560, black, black, 25, None)
     win1 = [("Win:"), 80]
     win2 = [(str(self.win_count)), 160]
     draw1 = [("Draw:"), 240]
     draw2 = [(str(self.draw_count)), 320]
     lose1 = [("Lose:"), 400]
     lose2 = [(str(self.lose_count)), 480]
     for i in [win1, win2, draw1, draw2, lose1, lose2]:
         x = 680
         y = i[1]
         i.pop(1)
         i = ''.join(i)
         large_text = p.font.SysFont("comicsansms", 50)
         text_surf, text_rect = __main__.text_objects(i, large_text, white)
         text_rect.center = (x, y)
         gameDisplay.blit(text_surf, text_rect)
     p.display.update()
     self.button_grid()
Beispiel #4
0
    def update_grid(self):
        for i in square_array:
            x = i[0]
            y = i[1]
            game_piece = i[2]
            ic = i[3]
            ac = i[4]

            small_text = p.font.SysFont("comicsansms", 150)
            text_surf, text_rect = __main__.text_objects(
                game_piece, small_text, self.colour)
            text_rect.center = ((x + (self.side_square / 1.75)),
                                (y + (self.side_square / 1.75)))

            p.draw.rect(gameDisplay, ic, (x, y, side_square, side_square))

            gameDisplay.blit(text_surf, text_rect)
        clock.tick(60)
        p.display.update()
        self.piece_checker()
Beispiel #5
0
def choose_piece():
    time.sleep(.2)
    choose = True
    while choose:
        for event in p.event.get():
            if event.type == p.QUIT:
                p.quit()
                quit()

        gameDisplay.fill(white)
        large_text = p.font.SysFont("comicsansms", 90)
        text_surf, text_rect = __main__.text_objects("Which Team", large_text,
                                                     black)
        text_rect.center = ((width_display / 2), (height_display * (1 / 4)))
        gameDisplay.blit(text_surf, text_rect)
        __main__.button("X", black, (width_display * (1 / 3)) - 100,
                        height_display / 2, 150, 100, dark_blue, blue, 45,
                        grid.set_x)
        __main__.button("O", black, (width_display * (2 / 3)) - 50,
                        height_display / 2, 150, 100, dark_pink, pink, 45,
                        grid.set_o)

        clock.tick(15)
        p.display.update()
Beispiel #6
0
 def war_games(self):
     gameDisplay.fill(black)
     p.mixer.Sound.play(war_games_wave)
     y_base = 5
     quote = ["A STRANGE GAME.", "THE ONLY WINNING MOVE", "IS NOT TO PLAY."]
     words_music = True
     while words_music:
         for line in quote:
             y_base += 1
             y = 50 * y_base
             x_base = 0
             for letter in line:
                 x_base += 1
                 x = 15 * x_base
                 large_text = p.font.SysFont("vgasys", 20)
                 text_surf, text_rect = __main__.text_objects(
                     letter, large_text, white)
                 text_rect = (x, y)
                 gameDisplay.blit(text_surf, text_rect)
                 clock.tick(10)
                 p.display.update()
         words_music = False
     time.sleep(.2)
     __main__.quit_game()
Beispiel #7
0
    def button_grid(self):
        global h, x_test, y_test
        draw = True
        while draw:
            for event in p.event.get():
                if event.type == p.QUIT:
                    p.quit()
                    quit()
                elif event.type == p.KEYDOWN:
                    if event.key == p.K_p:
                        __main__.paused()

            for i in square_array:
                x = i[0]
                y = i[1]
                game_piece = i[2]
                ic = i[3]
                ac = i[4]

                x_test = x
                y_test = y
                mouse = p.mouse.get_pos()
                click = p.mouse.get_pressed()

                small_text = p.font.SysFont("comicsansms", 150)
                text_surf, text_rect = __main__.text_objects(
                    game_piece, small_text, self.colour)
                text_rect.center = ((x + (self.side_square / 1.75)),
                                    (y + (self.side_square / 1.75)))

                if x + side_square > mouse[0] > x and y + side_square > mouse[
                        1] > y:
                    p.draw.rect(gameDisplay, ac,
                                (x, y, side_square, side_square))
                    if click[0] == 1:
                        time.sleep(.2)
                        for i in square_array:
                            square_x = i[0]
                            square_y = i[1]
                            piece_type = i[2]
                            place = i[5]
                            if square_x == x and square_y == y:
                                if game_piece == "X" or game_piece == "O":
                                    self.turn_count -= 1
                                    h = False
                                    self.piece_checker()
                                else:
                                    h = True
                                    square_array.remove(i)
                                    i.pop(2)
                                    i.pop(2)
                                    i.pop(2)
                                    i.insert(2, self.p_piece)
                                    i.insert(3, green)
                                    i.insert(4, green)
                                    square_array.insert(place, i)
                                    self.coded_board()
                        text_surf, text_rect = text_objects(
                            game_piece, small_text, self.colour)
                        gameDisplay.blit(text_surf, text_rect)
                else:
                    p.draw.rect(gameDisplay, ic,
                                (x, y, side_square, side_square))

                gameDisplay.blit(text_surf, text_rect)
            clock.tick(60)
            p.display.update()
def write_words():
    gameDisplay.fill(white)
    name = []
    question = str('Please enter your name:')
    write = True
    while write:
        large_text = p.font.SysFont("comicsansms", 60)
        small_text = p.font.SysFont("comicsansms", 50)
        text_surf, text_rect = __main__.text_objects(question, large_text,
                                                     black)
        text_rect.center = ((width_display / 2), (height_display * (1 / 3)))
        gameDisplay.blit(text_surf, text_rect)

        for event in p.event.get():
            if event.type == p.QUIT:
                __main__.quit_game()
            if event.type == p.KEYDOWN:
                letter = ''
                if event.key == p.K_RETURN:
                    __main__.game_loop()
                elif event.key == p.K_BACKSPACE:
                    nameS = name
                    nameS = list(nameS)
                    del nameS[-1]
                    nameS = "".join(nameS)
                    name = nameS
                elif event.key == p.K_SPACE:
                    letter = ' '
                elif event.key == p.K_a:
                    letter = 'a'
                elif event.key == p.K_b:
                    letter = 'b'
                elif event.key == p.K_c:
                    letter = 'c'
                elif event.key == p.K_d:
                    letter = 'd'
                elif event.key == p.K_e:
                    letter = 'e'
                elif event.key == p.K_f:
                    letter = 'f'
                elif event.key == p.K_g:
                    letter = 'g'
                elif event.key == p.K_h:
                    letter = 'h'
                elif event.key == p.K_i:
                    letter = 'i'
                elif event.key == p.K_j:
                    letter = 'j'
                elif event.key == p.K_k:
                    letter = 'k'
                elif event.key == p.K_l:
                    letter = 'l'
                elif event.key == p.K_m:
                    letter = 'm'
                elif event.key == p.K_n:
                    letter = 'n'
                elif event.key == p.K_o:
                    letter = 'o'
                elif event.key == p.K_p:
                    letter = 'p'
                elif event.key == p.K_q:
                    letter = 'q'
                elif event.key == p.K_r:
                    letter = 'r'
                elif event.key == p.K_s:
                    letter = 's'
                elif event.key == p.K_t:
                    letter = 't'
                elif event.key == p.K_u:
                    letter = 'u'
                elif event.key == p.K_v:
                    letter = 'v'
                elif event.key == p.K_w:
                    letter = 'w'
                elif event.key == p.K_x:
                    letter = 'x'
                elif event.key == p.K_y:
                    letter = 'y'
                elif event.key == p.K_z:
                    letter = 'z'
                name = ''.join(name)
                name = str(name) + str(letter)

            gameDisplay.fill(white)
            text_surf, text_rect = __main__.text_objects(
                question, large_text, black)
            text_rect.center = ((width_display / 2),
                                (height_display * (1 / 3)))
            gameDisplay.blit(text_surf, text_rect)

            text_surf, text_rect = __main__.text_objects(
                name, small_text, black)
            text_rect.center = ((width_display / 2),
                                (height_display * (1 / 2)))
            gameDisplay.blit(text_surf, text_rect)

        clock.tick(15)
        p.display.update()