Esempio n. 1
0
def drawBoard(my_score, devils_score):
    # draw score increments of 10
    font = pygame.font.SysFont(None, 48)
    for i in range(1, 11):
        x = dis_width / 15
        y = dis_height - (i * (dis_height / 10))
        img = font.render(str(i * 10), True, BLACK)
        dis.blit(img, (x, y))

    # Draw user and devil text
    my_x = dis_width / 3
    devil_x = dis_width / 3 * 2
    y = dis_height - 30
    user = font.render("User", True, BLUE)
    dis.blit(user, (my_x, y))
    devil = font.render("Devil", True, DARK_RED)
    dis.blit(devil, (devil_x, y))

    # draw buttons
    roll_die = Button(dis, LIGHT_GREY, dis_width / 2 - 15, dis_height / 2, 100, 50, "roll")
    roll_die.draw()
    roll_die.add_text("Roll", 48, BLACK)
    pass_turn = Button(dis, LIGHT_GREY, dis_width / 2 - 15, dis_height / 2 + dis_height / 10, 100, 50, "pass")
    pass_turn.draw()
    pass_turn.add_text("Pass", 48, BLACK)

    # draw player score bars
    pygame.draw.rect(dis, BLUE, [my_x, dis_height - ((dis_height / 10) * (my_score / 10)), dis_width / 10,
                                 (dis_height / 10) * (my_score / 10) - 30])
    pygame.draw.rect(dis, DARK_RED, [devil_x, dis_height - ((dis_height / 10) * (devils_score / 10)), dis_width / 10,
                                     (dis_height / 10) * (devils_score / 10) - 30])
class Confirmation_Menu(Surface):
    def __init__(self, text, pos, size, color, alpha, functions):
        super(Confirmation_Menu, self).__init__(pos, size, color, alpha)
        self.functions = functions + [lambda: self.set_response(True)]
        self.response_received = False

        self.main_text = Text(
            str(text),
            [self.pos[0] + self.size[0] / 2, self.pos[1] + self.size[1] / 2],
            (255, 255, 255), 20, "tahoma")
        self.confirm_button = Button([
            self.pos[0] + self.size[0] * 0.1, self.pos[1] + self.size[1] * 0.95
        ], [self.size[0] * 0.35, self.size[1] * 0.3], (0, 200, 0), (0, 255, 0),
                                     self.alpha, self.functions)
        self.confirm_button.add_text("Confirm", [
            self.confirm_button.get_size()[0] / 2,
            self.confirm_button.get_size()[1] / 2
        ], (255, 255, 255), 20, "tahoma")
        self.cancel_button = Button([
            self.pos[0] + self.size[0] * 0.5, self.pos[1] + self.size[1] * 0.95
        ], [self.size[0] * 0.35, self.size[1] * 0.3], (200, 0, 0), (255, 0, 0),
                                    self.alpha,
                                    [lambda: self.set_response(True)])
        self.cancel_button.add_text("Cancel", [
            self.cancel_button.get_size()[0] / 2,
            self.cancel_button.get_size()[1] / 2
        ], (255, 255, 255), 20, "tahoma")

    def update(self):
        super(Confirmation_Menu, self).update()

    def draw(self, surface):
        super(Confirmation_Menu, self).draw(surface)
        self.main_text.update()
        self.main_text.draw(surface)
        self.confirm_button.update()
        self.confirm_button.draw(surface)
        self.cancel_button.update()
        self.cancel_button.draw(surface)

    def set_response(self, bool):
        self.response_received = bool

    def get_response(self):
        return self.response_received