Exemple #1
0
 def startgame(self, mode):
     self.mode = mode
     self.question, self.answer, self.answerList = self.math.get_question(
         self.mode, self.difficulty)
     random.shuffle(self.answerList)
     for i in range(len(self.answerList)):
         if self.answerList[i] == self.answer:
             self.index = i
     self.qlabel = Label(self.question, 30, (0, 0, 0), (255, 255, 255),
                         width / 2, 25)
     for i in range(len(self.circlelist)):
         self.answerLabels.append(
             Label(str(self.answerList[i]), 25, (0, 0, 0),
                   self.circle_color, self.circlelist[i].x,
                   self.circlelist[i].y))
     self.stage = "game"
     self.set_timer()
    def __init__(self):
        self.run = True
        self.item_list = []

        self.points = 0
        self.mouse_down = 0
        self.stage = TITLE_STAGE

        # label variables
        self.game_label = Label("Trash Heroes", 32, BLACK, WHITE, width / 2,
                                200)
        self.instructions_label = Label("Instructions", 20, BLACK, WHITE,
                                        width / 2, 450)
        self.play_label = Label("Play Game", 20, BLACK, WHITE, width / 2, 650)
        self.the_instructions = Label("The Instructions", 32, BLACK, WHITE,
                                      width / 2, 200)

        self.sentence1 = Label(
            "The objective is to catch the falling items in the correct bin.",
            20, BLACK, WHITE, width / 2, 350)
        self.sentence2 = Label(
            "You can move the bin with the right and left arrows.", 20, BLACK,
            WHITE, width / 2, 425)
        self.sentence3 = Label(
            "You can switch bins with these keybinds: 1 = Trash Can, 2 = Recycling Bin, 3 = Yard Trimmings Bin.",
            20, BLACK, WHITE, width / 2, 500)

        self.score = Label("Score: " + str(self.points), 32, BLACK, WHITE,
                           width / 2, 50)

        self.play_again = Label("Play Again", 20, BLACK, WHITE, width / 2, 600)
        self.final_score = Label("Your Final Score", 32, BLACK, WHITE,
                                 width / 2, 250)

        self.back_to_start = Label("Return to Title Screen", 20, BLACK, WHITE,
                                   width / 2, 700)
        self.bg_color = WHITE
        self.music = pygame.mixer.music.load("sound.mp3")
        pygame.mixer.music.play(-1)
        self.wrongsound = pygame.mixer.Sound("wrong.wav")
        self.rightsound = pygame.mixer.Sound("correct.wav")

        # Create items
        for i in range(30):
            self.item_list.append(
                Image(random.randrange(35, 885), -200 - 500 * i))
        self.can = Can()
        self.hitcan = self.item_list[0]
class Game:
    def __init__(self):
        self.run = True
        self.item_list = []

        self.points = 0
        self.mouse_down = 0
        self.stage = TITLE_STAGE

        # label variables
        self.game_label = Label("Trash Heroes", 32, BLACK, WHITE, width / 2,
                                200)
        self.instructions_label = Label("Instructions", 20, BLACK, WHITE,
                                        width / 2, 450)
        self.play_label = Label("Play Game", 20, BLACK, WHITE, width / 2, 650)
        self.the_instructions = Label("The Instructions", 32, BLACK, WHITE,
                                      width / 2, 200)

        self.sentence1 = Label(
            "The objective is to catch the falling items in the correct bin.",
            20, BLACK, WHITE, width / 2, 350)
        self.sentence2 = Label(
            "You can move the bin with the right and left arrows.", 20, BLACK,
            WHITE, width / 2, 425)
        self.sentence3 = Label(
            "You can switch bins with these keybinds: 1 = Trash Can, 2 = Recycling Bin, 3 = Yard Trimmings Bin.",
            20, BLACK, WHITE, width / 2, 500)

        self.score = Label("Score: " + str(self.points), 32, BLACK, WHITE,
                           width / 2, 50)

        self.play_again = Label("Play Again", 20, BLACK, WHITE, width / 2, 600)
        self.final_score = Label("Your Final Score", 32, BLACK, WHITE,
                                 width / 2, 250)

        self.back_to_start = Label("Return to Title Screen", 20, BLACK, WHITE,
                                   width / 2, 700)
        self.bg_color = WHITE
        self.music = pygame.mixer.music.load("sound.mp3")
        pygame.mixer.music.play(-1)
        self.wrongsound = pygame.mixer.Sound("wrong.wav")
        self.rightsound = pygame.mixer.Sound("correct.wav")

        # Create items
        for i in range(30):
            self.item_list.append(
                Image(random.randrange(35, 885), -200 - 500 * i))
        self.can = Can()
        self.hitcan = self.item_list[0]

    def drawgame(self):
        for item in self.item_list:
            item.draw(win)
        self.can.draw(win)
        self.score.changetext("Score: " + str(self.points))
        self.score.draw(win)
        pygame.display.update()

    def correct(self):
        self.points += 1
        self.score.changecolor(GREEN)
        self.rightsound.play()

    def wrong(self):
        self.score.changecolor(RED)
        self.wrongsound.play()

    def rungame(self):
        while self.run:
            win.fill(self.bg_color)
            pygame.time.delay(10)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.run = False
            self.key = pygame.key.get_pressed()
            self.x, self.y = pygame.mouse.get_pos()

            if self.stage == TITLE_STAGE:
                pygame.event.get()
                if pygame.mouse.get_pressed() == BLACK:
                    self.mouse_down = 0
                if pygame.mouse.get_pressed() == (1, 0,
                                                  0) and self.mouse_down == 0:
                    if self.instructions_label.in_rect:
                        self.stage = INSTRUCTION_STAGE
                        self.instructions_label.in_rect = False
                    elif self.play_label.in_rect:
                        self.stage = GAME_STAGE
                        self.play_again.in_rect = False
                self.instructions_label.checkcursor(self.x, self.y, GRAY)
                self.play_label.checkcursor(self.x, self.y, GRAY)
                self.game_label.draw(win)
                self.instructions_label.draw(win)
                self.play_label.draw(win)
                pygame.display.update()

            if self.stage == INSTRUCTION_STAGE:
                pygame.event.get()
                if pygame.mouse.get_pressed() == (1, 0, 0):
                    if self.play_label.in_rect:
                        self.stage = GAME_STAGE
                self.play_label.checkcursor(self.x, self.y, GRAY)
                self.the_instructions.draw(win)
                self.sentence1.draw(win)
                self.sentence2.draw(win)
                self.sentence3.draw(win)
                self.play_label.draw(win)
                pygame.display.update()

            if self.stage == GAME_STAGE:
                # movement
                if self.key[pygame.K_LEFT]:
                    self.can.x -= 10
                if self.key[pygame.K_RIGHT]:
                    self.can.x += 10

                # bin switch
                if self.key[pygame.K_1]:
                    self.can.change("trash")
                if self.key[pygame.K_2]:
                    self.can.change("recycle")
                if self.key[pygame.K_3]:
                    self.can.change("garden")

                # can touch conditions
                for item in self.item_list:
                    if item.y + 40 > 700 and item.y + 40 < 750 and item.visible:
                        if item.x > self.can.x and item.x < self.can.x + 170:
                            item.visible = False
                            self.hitcan = item
                            if self.can.form == "trash":
                                if item.index == 0:
                                    self.correct()
                                else:
                                    self.wrong()
                            if self.can.form == "recycle":
                                if item.index == 1:
                                    self.correct()
                                else:
                                    self.wrong()
                            if self.can.form == "garden":
                                if item.index == 2:
                                    self.correct()
                                else:
                                    self.wrong()
                    if self.hitcan.y > 900:
                        self.score.changecolor(BLACK)

                # difficulty increasing with skill
                if self.item_list[5].y < 1000:
                    self.speed = 2
                if self.item_list[5].y > 1000 and self.item_list[5].y < 1100:
                    if self.points > 3:
                        self.speed = 3
                if self.item_list[10].y > 1000 and self.item_list[10].y < 1100:
                    if self.points > 7:
                        self.speed = 4
                if self.item_list[15].y > 1000 and self.item_list[15].y < 1100:
                    if self.points > 12:
                        self.speed = 5
                if self.item_list[20].y > 1000 and self.item_list[20].y < 1100:
                    if self.points > 17:
                        self.speed = 6

                for item in self.item_list:
                    item.y += self.speed
                if self.item_list[29].y > 1000:
                    self.stage = 3
                    self.final_score.changetext("Your final score was " +
                                                str(self.points) + " / " +
                                                str(len(self.item_list)) + ".")
                self.drawgame()
            if self.stage == END_STAGE:
                pygame.event.get()
                if pygame.mouse.get_pressed() == (1, 0, 0):
                    if self.play_again.in_rect:
                        self.stage = GAME_STAGE
                        self.item_list = []
                        for i in range(30):
                            self.item_list.append(
                                Image(random.randrange(35, 885),
                                      -200 - 500 * i))
                        self.can.change("trash")
                        self.points = 0
                        self.play_again.in_rect = False
                    elif self.back_to_start.in_rect:
                        self.stage = TITLE_STAGE
                        self.item_list = []
                        for i in range(30):
                            self.item_list.append(
                                Image(random.randrange(35, 885),
                                      -200 - 500 * i))
                        self.can.change("trash")
                        self.points = 0
                        self.mouse_down = 1
                        self.back_to_start.in_rect = False
                self.play_again.checkcursor(self.x, self.y, GRAY)
                self.back_to_start.checkcursor(self.x, self.y, GRAY)
                self.final_score.draw(win)
                self.play_again.draw(win)
                self.back_to_start.draw(win)
                pygame.display.update()
        quit()
Exemple #4
0
if output_type in ['a', 'q', 'r']:
    # we'll need a page no matter what after this point
    page = None
    if output_type in ['a', 'q']:
        if label_type == '3x10':
            page = FullPage()               # page object for mailing labels (up to 30/page)
        elif label_type == '2x10':
            page = FullPage(lab_horiz_ct=2) # page object for mailing labels (up to 20/page)

    if output_type in ['a', 'r']:
        # we've got a call list...let's print some addresses
        # use Qrz class (we definitely dont have 1)
        qrz = Qrz(AGENT, FPATH)
        qrz.login()
        # also need a Label obj
        label = Label(p=page, q=qrz)
        # print call addresses
        # QRZ does not like call suffixes
        seq = label.call_address_printing(call_list, output_type, label_type, nskip)
    elif output_type == 'q':
        # we've got a call list...let's print some qso lists
        # use Cqrlog class (we may already have 1)
        if cqrl_db == None:
            cqrl_db = Cqrlog(IDENT, VERS, FPATH)
            if not cqrl_db.working:
                print >>sys.stderr, 'Could not connect to cqrlog DB...exiting'
                sys.exit()

        # also need a Label obj
        label = Label(p=page, c=cqrl_db)
        seq = label.call_qsolist_printing(call_list, label_type, nskip)
Exemple #5
0
 def set_timer(self):
     self.start_time = pygame.time.get_ticks()
     self.timer_label = Label("Time Left: " + str(int(30)), 25, (0, 0, 0),
                              (255, 255, 255), width * 0.1, 25)
Exemple #6
0
    def __init__(self):
        self.run = True
        self.circlelist = []
        self.bg_color = (255, 255, 255)
        self.hover_color = (66, 167, 245)
        self.circle_color = (23, 230, 216)
        self.bg = pygame.image.load("background.jpg")
        self.tooclose = False
        self.math = Math()
        self.points = 0
        self.points_label = Label("Points: " + str(self.points), 25, (0, 0, 0),
                                  (255, 255, 255), width * 0.9, 25)

        self.game_title_label = Label("Quick Maths", 40, (0, 0, 0),
                                      (255, 255, 255), width / 2, 150)
        self.choose_mode_label = Label("Choose Mode", 40, (0, 0, 0),
                                       (255, 255, 255), width / 2, 150)
        self.add_label = Label("Addition", 25, (0, 0, 0), (255, 255, 255),
                               width / 5, 550)
        self.subtract_label = Label("Subtraction", 25, (0, 0, 0),
                                    (255, 255, 255), 2 * (width / 5), 550)
        self.multiply_label = Label("Multiplication", 25, (0, 0, 0),
                                    (255, 255, 255), 3 * (width / 5), 550)
        self.divide_label = Label("Division", 25, (0, 0, 0), (255, 255, 255),
                                  4 * (width / 5), 550)
        self.end_label = Label(
            "You ended up with " + str(self.points) + " points.", 35,
            (0, 0, 0), (255, 255, 255), width / 2, 150)
        self.play_again_label = Label("Play Again", 25, (0, 0, 0),
                                      (255, 255, 255), width / 2, 650)
        self.choose_diff_label = Label("Choose Level", 32, (0, 0, 0),
                                       (255, 255, 255), width / 2, 500)
        self.diff_1_label = Label("1", 30, (0, 0, 0), (255, 255, 255),
                                  width * 0.35, 600)
        self.diff_2_label = Label("2", 30, (0, 0, 0), (255, 255, 255),
                                  width * 0.45, 600)
        self.diff_3_label = Label("3", 30, (0, 0, 0), (255, 255, 255),
                                  width * 0.55, 600)
        self.diff_4_label = Label("4", 30, (0, 0, 0), (255, 255, 255),
                                  width * 0.65, 600)

        self.stage = "start"
        for i in range(5):
            self.circlelist.append(Circle(width, height))
        self.allcircles = Circle(width, height)
        self.allcircles.changepos(self.circlelist)
        self.allcircles.tp()
        self.answerLabels = []
        self.mousenotpressed = True
        self.circlemove = False
        self.circlesteps = 0
        self.new_question = False
        self.wrongsound = pygame.mixer.Sound("wrong.wav")
        self.rightsound = pygame.mixer.Sound("correct.wav")
Exemple #7
0
class Game:
    def __init__(self):
        self.run = True
        self.circlelist = []
        self.bg_color = (255, 255, 255)
        self.hover_color = (66, 167, 245)
        self.circle_color = (23, 230, 216)
        self.bg = pygame.image.load("background.jpg")
        self.tooclose = False
        self.math = Math()
        self.points = 0
        self.points_label = Label("Points: " + str(self.points), 25, (0, 0, 0),
                                  (255, 255, 255), width * 0.9, 25)

        self.game_title_label = Label("Quick Maths", 40, (0, 0, 0),
                                      (255, 255, 255), width / 2, 150)
        self.choose_mode_label = Label("Choose Mode", 40, (0, 0, 0),
                                       (255, 255, 255), width / 2, 150)
        self.add_label = Label("Addition", 25, (0, 0, 0), (255, 255, 255),
                               width / 5, 550)
        self.subtract_label = Label("Subtraction", 25, (0, 0, 0),
                                    (255, 255, 255), 2 * (width / 5), 550)
        self.multiply_label = Label("Multiplication", 25, (0, 0, 0),
                                    (255, 255, 255), 3 * (width / 5), 550)
        self.divide_label = Label("Division", 25, (0, 0, 0), (255, 255, 255),
                                  4 * (width / 5), 550)
        self.end_label = Label(
            "You ended up with " + str(self.points) + " points.", 35,
            (0, 0, 0), (255, 255, 255), width / 2, 150)
        self.play_again_label = Label("Play Again", 25, (0, 0, 0),
                                      (255, 255, 255), width / 2, 650)
        self.choose_diff_label = Label("Choose Level", 32, (0, 0, 0),
                                       (255, 255, 255), width / 2, 500)
        self.diff_1_label = Label("1", 30, (0, 0, 0), (255, 255, 255),
                                  width * 0.35, 600)
        self.diff_2_label = Label("2", 30, (0, 0, 0), (255, 255, 255),
                                  width * 0.45, 600)
        self.diff_3_label = Label("3", 30, (0, 0, 0), (255, 255, 255),
                                  width * 0.55, 600)
        self.diff_4_label = Label("4", 30, (0, 0, 0), (255, 255, 255),
                                  width * 0.65, 600)

        self.stage = "start"
        for i in range(5):
            self.circlelist.append(Circle(width, height))
        self.allcircles = Circle(width, height)
        self.allcircles.changepos(self.circlelist)
        self.allcircles.tp()
        self.answerLabels = []
        self.mousenotpressed = True
        self.circlemove = False
        self.circlesteps = 0
        self.new_question = False
        self.wrongsound = pygame.mixer.Sound("wrong.wav")
        self.rightsound = pygame.mixer.Sound("correct.wav")

    def drawgame(self):
        win.blit(self.bg, [0, 0])
        if self.stage == "start":
            self.game_title_label.draw(win)
            self.choose_diff_label.draw(win)
            self.diff_1_label.draw(win)
            self.diff_2_label.draw(win)
            self.diff_3_label.draw(win)
            self.diff_4_label.draw(win)

        if self.stage == "choose mode":
            self.choose_mode_label.draw(win)
            self.add_label.draw(win)
            self.subtract_label.draw(win)
            self.multiply_label.draw(win)
            self.divide_label.draw(win)

        if self.stage == "game":
            for circle in self.circlelist:
                circle.draw(win)
            self.qlabel.draw(win)
            for label in self.answerLabels:
                label.draw(win)
            self.points_label.draw(win)
            self.timer_label.draw(win)

        if self.stage == "end":
            self.end_label.draw(win)
            self.play_again_label.draw(win)

    def set_timer(self):
        self.start_time = pygame.time.get_ticks()
        self.timer_label = Label("Time Left: " + str(int(30)), 25, (0, 0, 0),
                                 (255, 255, 255), width * 0.1, 25)

    def startgame(self, mode):
        self.mode = mode
        self.question, self.answer, self.answerList = self.math.get_question(
            self.mode, self.difficulty)
        random.shuffle(self.answerList)
        for i in range(len(self.answerList)):
            if self.answerList[i] == self.answer:
                self.index = i
        self.qlabel = Label(self.question, 30, (0, 0, 0), (255, 255, 255),
                            width / 2, 25)
        for i in range(len(self.circlelist)):
            self.answerLabels.append(
                Label(str(self.answerList[i]), 25, (0, 0, 0),
                      self.circle_color, self.circlelist[i].x,
                      self.circlelist[i].y))
        self.stage = "game"
        self.set_timer()

    def rungame(self):
        while self.run:
            win.fill(self.bg_color)
            pygame.time.delay(10)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.run = False
            self.x, self.y = pygame.mouse.get_pos()

            if self.stage == "start":
                pygame.event.get()
                if pygame.mouse.get_pressed() == (0, 0, 0):
                    self.mousenotpressed = True
                if pygame.mouse.get_pressed() == (1, 0,
                                                  0) and self.mousenotpressed:
                    self.mousenotpressed = False
                    if self.diff_1_label.in_rect:
                        self.stage = "choose mode"
                        self.difficulty = 1
                    if self.diff_2_label.in_rect:
                        self.stage = "choose mode"
                        self.difficulty = 2
                    if self.diff_3_label.in_rect:
                        self.stage = "choose mode"
                        self.difficulty = 3
                    if self.diff_4_label.in_rect:
                        self.stage = "choose mode"
                        self.difficulty = 4

                elif pygame.mouse.get_pressed() == (1, 0, 0):
                    self.mousenotpressed = False
                self.diff_1_label.checkcursor(self.x, self.y, self.hover_color)
                self.diff_2_label.checkcursor(self.x, self.y, self.hover_color)
                self.diff_3_label.checkcursor(self.x, self.y, self.hover_color)
                self.diff_4_label.checkcursor(self.x, self.y, self.hover_color)
            if self.stage == "choose mode":
                pygame.event.get()
                if pygame.mouse.get_pressed() == (0, 0, 0):
                    self.mousenotpressed = True
                if pygame.mouse.get_pressed() == (1, 0,
                                                  0) and self.mousenotpressed:
                    self.mousenotpressed = False
                    if self.add_label.in_rect:
                        self.startgame("addition")

                    if self.subtract_label.in_rect:
                        self.startgame("subtraction")
                    if self.multiply_label.in_rect:
                        self.startgame("multiplication")
                    if self.divide_label.in_rect:

                        self.startgame("division")
                elif pygame.mouse.get_pressed() == (1, 0, 0):
                    self.mousenotpressed = False
                self.add_label.checkcursor(self.x, self.y, self.hover_color)
                self.subtract_label.checkcursor(self.x, self.y,
                                                self.hover_color)
                self.multiply_label.checkcursor(self.x, self.y,
                                                self.hover_color)
                self.divide_label.checkcursor(self.x, self.y, self.hover_color)

            if self.stage == "game":
                self.time_now = pygame.time.get_ticks()
                self.time_diff = (self.time_now - self.start_time) / 1000
                self.timer_label = Label(
                    "Time Left: " + str(int(30 - self.time_diff)), 25,
                    (0, 0, 0), (255, 255, 255), width * 0.1, 25)
                if 30 - self.time_diff <= 0:
                    self.stage = "end"
                    self.end_label = Label(
                        "You ended up with " + str(self.points) + " points.",
                        35, (0, 0, 0), (255, 255, 255), width / 2, 150)

                pygame.event.get()
                if pygame.mouse.get_pressed() == (0, 0, 0):
                    self.mousenotpressed = True
                if pygame.mouse.get_pressed() == (1, 0,
                                                  0) and self.mousenotpressed:
                    self.mousenotpressed = False
                    for i in range(len(self.circlelist)):
                        self.xdiff = abs(self.x - self.circlelist[i].x)
                        self.ydiff = abs(self.y - self.circlelist[i].y)
                        if (self.xdiff**2 + self.ydiff**
                                2)**0.5 < 50 and self.circlemove == False:
                            if self.circlelist[i] == self.circlelist[
                                    self.index]:
                                self.points += 1
                                self.circlelist[i].changecolor((0, 255, 0))
                                self.answerLabels[i] = Label(
                                    str(self.answerList[i]), 25, (0, 0, 0),
                                    (0, 255, 0), self.circlelist[i].x,
                                    self.circlelist[i].y)
                                self.rightsound.play()

                            else:
                                if self.points > 0:
                                    self.points -= 1
                                self.circlelist[i].changecolor((255, 0, 0))
                                self.answerLabels[i] = Label(
                                    str(self.answerList[i]), 25, (0, 0, 0),
                                    (255, 0, 0), self.circlelist[i].x,
                                    self.circlelist[i].y)
                                self.circlelist[self.index].changecolor(
                                    (0, 255, 0))
                                self.answerLabels[self.index] = Label(
                                    str(self.answerList[self.index]), 25,
                                    (0, 0, 0), (0, 255, 0),
                                    self.circlelist[self.index].x,
                                    self.circlelist[self.index].y)
                                self.wrongsound.play()
                            self.allcircles.changepos(self.circlelist)
                            self.circlemove = True

                if self.circlemove:
                    self.allcircles.slide(45)
                    self.circlesteps += 1
                    for i in range(len(self.answerLabels)):
                        self.answerLabels[i].changepos(self.circlelist[i].x,
                                                       self.circlelist[i].y)
                    if self.circlesteps == 45:
                        self.circlemove = False
                        self.circlesteps = 0
                        self.new_question = True
                if self.new_question:
                    for circle in self.circlelist:
                        circle.changecolor(self.circle_color)

                    self.new_question = False
                    self.question, self.answer, self.answerList = self.math.get_question(
                        self.mode, self.difficulty)
                    random.shuffle(self.answerList)
                    for i in range(len(self.answerList)):
                        if self.answerList[i] == self.answer:
                            self.index = i

                    self.points_label = Label("Points: " + str(self.points),
                                              25, (0, 0, 0), (255, 255, 255),
                                              width * 0.9, 25)
                    self.qlabel = Label(self.question, 30, (0, 0, 0),
                                        (255, 255, 255), width / 2, 25)
                    self.answerLabels = []
                    for i in range(len(self.circlelist)):
                        self.answerLabels.append(
                            Label(str(self.answerList[i]), 25, (0, 0, 0),
                                  self.circle_color, self.circlelist[i].x,
                                  self.circlelist[i].y))

                elif pygame.mouse.get_pressed() == (1, 0, 0):
                    self.mousenotpressed = False

            if self.stage == "end":
                pygame.event.get()
                if pygame.mouse.get_pressed() == (0, 0, 0):
                    self.mousenotpressed = True
                if pygame.mouse.get_pressed() == (1, 0,
                                                  0) and self.mousenotpressed:
                    self.mousenotpressed = False
                    if self.play_again_label.in_rect:
                        self.stage = "start"
                        self.points = 0
                        self.allcircles.changepos(self.circlelist)
                        self.answerLabels = []
                        self.play_again_label.in_rect = False
                        self.add_label.in_rect = False
                        self.subtract_label.in_rect = False
                        self.multiply_label.in_rect = False
                        self.divide_label.in_rect = False
                        self.diff_1_label.in_rect = False
                        self.diff_2_label.in_rect = False
                        self.diff_3_label.in_rect = False
                        self.diff_4_label.in_rect = False
                elif pygame.mouse.get_pressed() == (1, 0, 0):
                    self.mousenotpressed = False
                self.play_again_label.checkcursor(self.x, self.y,
                                                  self.hover_color)

            self.drawgame()

            pygame.display.update()
        pygame.quit()
Exemple #8
0
    def rungame(self):
        while self.run:
            win.fill(self.bg_color)
            pygame.time.delay(10)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.run = False
            self.x, self.y = pygame.mouse.get_pos()

            if self.stage == "start":
                pygame.event.get()
                if pygame.mouse.get_pressed() == (0, 0, 0):
                    self.mousenotpressed = True
                if pygame.mouse.get_pressed() == (1, 0,
                                                  0) and self.mousenotpressed:
                    self.mousenotpressed = False
                    if self.diff_1_label.in_rect:
                        self.stage = "choose mode"
                        self.difficulty = 1
                    if self.diff_2_label.in_rect:
                        self.stage = "choose mode"
                        self.difficulty = 2
                    if self.diff_3_label.in_rect:
                        self.stage = "choose mode"
                        self.difficulty = 3
                    if self.diff_4_label.in_rect:
                        self.stage = "choose mode"
                        self.difficulty = 4

                elif pygame.mouse.get_pressed() == (1, 0, 0):
                    self.mousenotpressed = False
                self.diff_1_label.checkcursor(self.x, self.y, self.hover_color)
                self.diff_2_label.checkcursor(self.x, self.y, self.hover_color)
                self.diff_3_label.checkcursor(self.x, self.y, self.hover_color)
                self.diff_4_label.checkcursor(self.x, self.y, self.hover_color)
            if self.stage == "choose mode":
                pygame.event.get()
                if pygame.mouse.get_pressed() == (0, 0, 0):
                    self.mousenotpressed = True
                if pygame.mouse.get_pressed() == (1, 0,
                                                  0) and self.mousenotpressed:
                    self.mousenotpressed = False
                    if self.add_label.in_rect:
                        self.startgame("addition")

                    if self.subtract_label.in_rect:
                        self.startgame("subtraction")
                    if self.multiply_label.in_rect:
                        self.startgame("multiplication")
                    if self.divide_label.in_rect:

                        self.startgame("division")
                elif pygame.mouse.get_pressed() == (1, 0, 0):
                    self.mousenotpressed = False
                self.add_label.checkcursor(self.x, self.y, self.hover_color)
                self.subtract_label.checkcursor(self.x, self.y,
                                                self.hover_color)
                self.multiply_label.checkcursor(self.x, self.y,
                                                self.hover_color)
                self.divide_label.checkcursor(self.x, self.y, self.hover_color)

            if self.stage == "game":
                self.time_now = pygame.time.get_ticks()
                self.time_diff = (self.time_now - self.start_time) / 1000
                self.timer_label = Label(
                    "Time Left: " + str(int(30 - self.time_diff)), 25,
                    (0, 0, 0), (255, 255, 255), width * 0.1, 25)
                if 30 - self.time_diff <= 0:
                    self.stage = "end"
                    self.end_label = Label(
                        "You ended up with " + str(self.points) + " points.",
                        35, (0, 0, 0), (255, 255, 255), width / 2, 150)

                pygame.event.get()
                if pygame.mouse.get_pressed() == (0, 0, 0):
                    self.mousenotpressed = True
                if pygame.mouse.get_pressed() == (1, 0,
                                                  0) and self.mousenotpressed:
                    self.mousenotpressed = False
                    for i in range(len(self.circlelist)):
                        self.xdiff = abs(self.x - self.circlelist[i].x)
                        self.ydiff = abs(self.y - self.circlelist[i].y)
                        if (self.xdiff**2 + self.ydiff**
                                2)**0.5 < 50 and self.circlemove == False:
                            if self.circlelist[i] == self.circlelist[
                                    self.index]:
                                self.points += 1
                                self.circlelist[i].changecolor((0, 255, 0))
                                self.answerLabels[i] = Label(
                                    str(self.answerList[i]), 25, (0, 0, 0),
                                    (0, 255, 0), self.circlelist[i].x,
                                    self.circlelist[i].y)
                                self.rightsound.play()

                            else:
                                if self.points > 0:
                                    self.points -= 1
                                self.circlelist[i].changecolor((255, 0, 0))
                                self.answerLabels[i] = Label(
                                    str(self.answerList[i]), 25, (0, 0, 0),
                                    (255, 0, 0), self.circlelist[i].x,
                                    self.circlelist[i].y)
                                self.circlelist[self.index].changecolor(
                                    (0, 255, 0))
                                self.answerLabels[self.index] = Label(
                                    str(self.answerList[self.index]), 25,
                                    (0, 0, 0), (0, 255, 0),
                                    self.circlelist[self.index].x,
                                    self.circlelist[self.index].y)
                                self.wrongsound.play()
                            self.allcircles.changepos(self.circlelist)
                            self.circlemove = True

                if self.circlemove:
                    self.allcircles.slide(45)
                    self.circlesteps += 1
                    for i in range(len(self.answerLabels)):
                        self.answerLabels[i].changepos(self.circlelist[i].x,
                                                       self.circlelist[i].y)
                    if self.circlesteps == 45:
                        self.circlemove = False
                        self.circlesteps = 0
                        self.new_question = True
                if self.new_question:
                    for circle in self.circlelist:
                        circle.changecolor(self.circle_color)

                    self.new_question = False
                    self.question, self.answer, self.answerList = self.math.get_question(
                        self.mode, self.difficulty)
                    random.shuffle(self.answerList)
                    for i in range(len(self.answerList)):
                        if self.answerList[i] == self.answer:
                            self.index = i

                    self.points_label = Label("Points: " + str(self.points),
                                              25, (0, 0, 0), (255, 255, 255),
                                              width * 0.9, 25)
                    self.qlabel = Label(self.question, 30, (0, 0, 0),
                                        (255, 255, 255), width / 2, 25)
                    self.answerLabels = []
                    for i in range(len(self.circlelist)):
                        self.answerLabels.append(
                            Label(str(self.answerList[i]), 25, (0, 0, 0),
                                  self.circle_color, self.circlelist[i].x,
                                  self.circlelist[i].y))

                elif pygame.mouse.get_pressed() == (1, 0, 0):
                    self.mousenotpressed = False

            if self.stage == "end":
                pygame.event.get()
                if pygame.mouse.get_pressed() == (0, 0, 0):
                    self.mousenotpressed = True
                if pygame.mouse.get_pressed() == (1, 0,
                                                  0) and self.mousenotpressed:
                    self.mousenotpressed = False
                    if self.play_again_label.in_rect:
                        self.stage = "start"
                        self.points = 0
                        self.allcircles.changepos(self.circlelist)
                        self.answerLabels = []
                        self.play_again_label.in_rect = False
                        self.add_label.in_rect = False
                        self.subtract_label.in_rect = False
                        self.multiply_label.in_rect = False
                        self.divide_label.in_rect = False
                        self.diff_1_label.in_rect = False
                        self.diff_2_label.in_rect = False
                        self.diff_3_label.in_rect = False
                        self.diff_4_label.in_rect = False
                elif pygame.mouse.get_pressed() == (1, 0, 0):
                    self.mousenotpressed = False
                self.play_again_label.checkcursor(self.x, self.y,
                                                  self.hover_color)

            self.drawgame()

            pygame.display.update()
        pygame.quit()