Exemplo n.º 1
0
def instruction_screen(screen, sound, current_screen, gameDisplay):
    screen.fill(white)
    screen.blit(edit.text("How to play?", yellow, 100), (54, 16))
    screen.blit(edit.text("How to play?", yellow, 100), (46, 24))
    screen.blit(edit.text("How to play?", dark_black, 100), (50, 20))
    inst = pygame.image.load("instructions2.png")
    screen.blit(inst, (0, 0))
    brain = pygame.image.load("brain.png")
    screen.blit(brain, (530, 440))

    # button back to main screen
    pygame.draw.rect(gameDisplay, blue, (50, 600, 200, 50))
    edit.hover(50, 600, 250, 650, 200, 50, dark_black, sound, current_screen, gameDisplay)
    screen.blit(edit.text("I got it", gray, 20), (110, 615))

    if pygame.mouse.get_pressed()[0]:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]
        if 50 <= mouseX <= 250 and 600 <= mouseY <= 650:
            current_screen = 0  # main screen
Exemplo n.º 2
0
def main(screen, gameDisplay):
    global current_screen, sound
    # print("main screen")
    screen.fill(white)
    # screen.blit(bg, (-70, -20))
    img1 = pygame.image.load("brain6.png")
    img2 = pygame.image.load("brain3.png")
    screen.blit(img2, (0, 440))
    screen.blit(img1, (560, 370))
    screen.blit(edit.text("Master Mind", yellow, 100), (64, 34))
    screen.blit(edit.text("Master Mind", yellow, 100), (56, 26))
    screen.blit(edit.text("Master Mind", dark_black, 100), (60, 30))
    mouse = pygame.mouse

    # button instrukcje:
    pygame.draw.rect(gameDisplay, blue, (250, 200, 300, 50))
    edit.hover(250, 200, 550, 250, 300, 50, dark_blue, sound, current_screen,
               gameDisplay)
    screen.blit(edit.text("How to play?", white, 20), (330, 215))

    screen.blit(edit.text("Choose a difficulty", yellow, 36), (223, 297))
    screen.blit(edit.text("Choose a difficulty", yellow, 36), (217, 303))
    screen.blit(edit.text("Choose a difficulty", dark_black, 36), (220, 300))
    # button easy:
    pygame.draw.rect(gameDisplay, black, (250, 350, 300, 50))
    edit.hover(250, 350, 550, 400, 300, 50, dark_black, sound, current_screen,
               gameDisplay)
    screen.blit(edit.text("Easy", gray, 20), (370, 365))

    # button medium:
    pygame.draw.rect(gameDisplay, black, (250, 420, 300, 50))
    edit.hover(250, 420, 550, 470, 300, 50, dark_black, sound, current_screen,
               gameDisplay)
    screen.blit(edit.text("Medium", gray, 20), (355, 435))

    # button hard:
    pygame.draw.rect(gameDisplay, black, (250, 490, 300, 50))
    edit.hover(250, 490, 550, 540, 300, 50, dark_black, sound, current_screen,
               gameDisplay)
    screen.blit(edit.text("Hard", gray, 20), (370, 505))

    # button AI
    pygame.draw.rect(gameDisplay, black, (250, 560, 300, 50))
    edit.hover(250, 560, 550, 610, 300, 50, dark_black, sound, current_screen,
               gameDisplay)
    screen.blit(edit.text("AI GAME", gray, 20), (355, 575))

    if mouse.get_pressed()[0]:
        mouseX = mouse.get_pos()[0]
        mouseY = mouse.get_pos()[1]
        if 250 <= mouseX <= 550 and 200 <= mouseY <= 250:
            current_screen = 1  # instructions
        elif 250 <= mouseX <= 550 and 350 <= mouseY <= 400:
            current_screen = 2  # easy
        elif 250 <= mouseX <= 550 and 420 <= mouseY <= 470:
            current_screen = 3  # medium
        elif 250 <= mouseX <= 550 and 490 <= mouseY <= 540:
            current_screen = 4  # hard
        elif 250 <= mouseX <= 550 and 560 <= mouseY <= 610:
            current_screen = 5  # hard
Exemplo n.º 3
0
def medium_game(screen,gameDisplay):
    global kod, code, moving, last, sound

    if kod == 0:
        kod = 1
        code = code_generate.code_generate("medium")
        # print(code)
    global checking
    global current_screen
    global ball
    global count
    global c1, c2, c3, c4, c5, c6
    global level
    screen.fill(white)
    # board
    board = pygame.image.load("board.png")
    screen.blit(board, (0, 0))
    brain = pygame.image.load("brain2-cloud.png")
    screen.blit(brain, (520, 200))
    pos = pygame.mouse.get_pos()
    if level < 11:
        for i in range(level + 1):
            for j in range(4):
                if ball[i][j] != 0:
                    if i < 6:
                        screen.blit(pygame.image.load(str(ball[i][j]) + ".png"), (j * 74 + 85, 559 - i * 45))
                    else:
                        screen.blit(pygame.image.load(str(ball[i][j]) + ".png"), (j * 74 + 85, 559 - i * 45.5))
                else:
                    continue

    # ball = pygame.draw.circle(gameDisplay, yellow, pos, 20)
    # button back to main screen

    if moving != -1 and pygame.mouse.get_pressed()[0]:
        #print(pos)
        if pos[1] < (557 + (level + 1) * 50) and pos[1] > ((557 - (level + 1) * 50)):
            # print("aaa")
            """
            tutaj cwiczymy przenoszenie kulkow przy uzyciu moving (globalnie)
            po wyjsciu z ekranu trzeba czyscic moving na -1
            trzeba zrobic cos ala siatka zeby rozroznic na ktore miejsce trafia kulka + zmiany kolorow
            po ponownym kliknieciu na druga kulke
            powodzenia!

            dodaj blokade na nakladanie pilkow 

          """
            if pos[0] >= 90 and pos[0] <= 115:
                if ball[level][0] == 0:
                    ball[level][0] = moving
                    last.append(0)
                else:
                    moving = -1
                    count -= 1
            elif pos[0] >= 160 and pos[0] <= 185:
                if ball[level][1] == 0:
                    ball[level][1] = moving
                    last.append(1)
                else:
                    moving = -1
                    count -= 1
            elif pos[0] >= 240 and pos[0] <= 260:
                if ball[level][2] == 0:
                    ball[level][2] = moving
                    last.append(2)
                else:
                    moving = -1
                    count -= 1
            elif pos[0] >= 315 and pos[0] <= 335:
                if ball[level][3] == 0:
                    ball[level][3] = moving
                    last.append(3)
                else:
                    moving = -1
                    count -= 1
            else:
                moving = -1
                count -= 1
            moving = -1
        else:
            moving = -1
            count -= 1
    pygame.draw.rect(gameDisplay, blue, (550, 50, 200, 50))
    edit.hover(550, 50, 750, 100, 200, 50, dark_black,sound, current_screen, gameDisplay)
    screen.blit(edit.text("Main Menu", gray, 20), (590, 65))
    if pygame.mouse.get_pressed()[0]:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]

        if 550 <= mouseX <= 750 and 50 <= mouseY <= 100:
            current_screen = 0  # main screen
    # button new game
    pygame.draw.rect(gameDisplay, blue, (550, 120, 200, 50))
    edit.hover(550, 120, 750, 170, 200, 50, dark_black,sound, current_screen, gameDisplay)
    screen.blit(edit.text("New Game", gray, 20), (595, 135))
    if pygame.mouse.get_pressed()[0]:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]
        if 550 <= mouseX <= 750 and 120 <= mouseY <= 170:
            time.sleep(1)
            # print("new game")
            count = 0
            kod = 0
            checking = 0
            last=[]
            moving=-1
            while level > 0:
                hint[level] = [0, 0]
                level -= 1

            ball = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
                    [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    pygame.draw.rect(gameDisplay, blue, (550, 600, 200, 50))
    if count == 4:
        edit.hover(550, 600, 750, 650, 200, 50, dark_black,sound, current_screen, gameDisplay)
    screen.blit(edit.text("Check", gray, 20), (615, 615))
    if pygame.mouse.get_pressed()[0]:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]
        if 550 <= mouseX <= 750 and 600 <= mouseY <= 650 and count == 4:
            # print("sprawdzam")
            checking = 1
            level += 1
            count = 0

    # undo button
    pygame.draw.rect(gameDisplay, blue, (550, 530, 200, 50))
    if count > 0:
        edit.hover(550, 530, 750, 580, 200, 50, dark_black,sound, current_screen, gameDisplay)
    screen.blit(edit.text("Undo", gray, 20), (622, 545))
    if pygame.mouse.get_pressed()[0]:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]
        if 550 <= mouseX <= 750 and 530 <= mouseY <= 580 and count > 0:
            # print("cofam")
            if len(last) > 0:
                count -= 1
                ball[level][last[len(last) - 1]] = 0
                last.pop()
            else:
                count -= 1
                ball[level][count] = 0
    if pygame.mouse.get_pressed()[0]:
        pressed_color = screen.get_at(pos)
        """
    red - 1 : (255, 39, 1, 255) 
    yellow - 2 : (255, 251, 1, 255)
    green - 3 : (1, 249, 1, 255)
    blue - 4 : (1, 253, 255, 255)
    purple - 5 : (149, 56, 255, 255)
    pink - 6 : (255, 48, 147, 255)
    """

        # print(pressed_color, pos)
        if count < 4:
            if pressed_color == (255, 39, 1, 255) and (pos[0] > 70 and pos[0] < 110 and pos[1] > 610 and pos[1] < 650):
                # print("red", pygame.mouse.get_pressed())
                moving = 1
                count += 1
            elif pressed_color == (255, 251, 1, 255) and (
                                    pos[0] > 142 and pos[0] < 182 and pos[1] > 610 and pos[1] < 650):
                # print("yellow")
                moving = 2
                count += 1
            elif pressed_color == (1, 249, 1, 255) and (
                                    pos[0] > 220 and pos[0] < 260 and pos[1] > 610 and pos[1] < 650):
                # print("green")
                moving = 3
                count += 1
            elif pressed_color == (1, 253, 255, 255) and (
                                    pos[0] > 290 and pos[0] < 330 and pos[1] > 610 and pos[1] < 650):
                # print("blue")
                moving = 4
                count += 1
            elif pressed_color == (149, 56, 255, 255) and (
                                    pos[0] > 370 and pos[0] < 410 and pos[1] > 610 and pos[1] < 650):
                # print("purple")
                moving = 5
                count += 1
            elif pressed_color == (255, 48, 147, 255) and (
                                    pos[0] > 440 and pos[0] < 480 and pos[1] > 610 and pos[1] < 650):
                # print("pink")
                moving = 6
                count += 1
    if level < 11:
        for i in range(level + 1):
            for j in range(count):
                if ball[i][j] != 0:
                    if i < 6:
                        screen.blit(pygame.image.load(str(ball[i][j]) + ".png"), (j * 74 + 85, 559 - i * 45))
                    else:
                        screen.blit(pygame.image.load(str(ball[i][j]) + ".png"), (j * 74 + 85, 559 - i * 45.5))
                else:
                    break
                    # print(checking)

    if level < 11:
        if count == 4:
            hint[level] = check.check2(ball[level],code)
        # print(hint)
        for i in range(level):
            if hint[i][0] == 0 and hint[i][1] == 0:
                continue
            else:
                screen.blit(pygame.image.load(str(hint[i][0]) + str(hint[i][1]) + ".png"), (410, 560 - i * 48 + i * 2))
                # print("dodano")
            if hint[i][1] == 4:
                # print("wygrana")
                sound=0
                current_screen = 6  # wygrana

        checking = 0
    if level == 11:
        current_screen = 7
        sound=0
    if moving >= 0:
        pin = screen.blit(pygame.image.load(str(moving) + ".png"), (pos[0] - 18, pos[1] - 18))
        pygame.display.update()

    return 0
Exemplo n.º 4
0
def hard_game(screen, gameDisplay):
    global kod, code, moving, sound

    if kod == 0:
        kod = 1
        code = code_generate.code_generate("hard")
        #print(code)
    global checking
    global current_screen
    global ball
    global count
    global c1, c2, c3, c4, c5, c6
    global level
    global last
    screen.fill(white)
    # board
    board = pygame.image.load("board-hard.png")
    screen.blit(board, (0, 0))
    brain = pygame.image.load("brain5-cloud.png")
    screen.blit(brain, (525, 170))
    pos = pygame.mouse.get_pos()
    if level < 11:
        for i in range(level + 1):
            for j in range(4):
                if ball[i][j] != 0:
                    if i < 6:
                        screen.blit(pygame.image.load(str(ball[i][j]) + ".png"), (j * 74 + 85, 559 - i * 45))
                    else:
                        screen.blit(pygame.image.load(str(ball[i][j]) + ".png"), (j * 74 + 85, 559 - i * 45.5))
                else:
                    continue

    # ball = pygame.draw.circle(gameDisplay, yellow, pos, 20)
    # button back to main screen
    #print(moving)

    if moving != -1 and pygame.mouse.get_pressed()[0]:
        #print(pos)
        if pos[1] < (557 + (level + 1) * 50) and pos[1] > ((557 - (level + 1) * 50)):

            if pos[0] >= 90 and pos[0] <= 115:
                if ball[level][0]==0:
                   ball[level][0] = moving
                   last.append(0)
                else:
                    moving=-1
                    count-=1
            elif pos[0] >= 160 and pos[0] <= 185:
                 if ball[level][1]==0:
                    ball[level][1] = moving
                    last.append(1)
                 else:
                    moving=-1
                    count-=1
            elif pos[0] >= 240 and pos[0] <= 260:
                if ball[level][2]==0:
                   ball[level][2] = moving
                   last.append(2)
                else:
                    moving=-1
                    count-=1
            elif pos[0] >= 315 and pos[0] <= 335:
                if ball[level][3]==0:
                   ball[level][3] = moving
                   last.append(3)
                else:
                    moving=-1
                    count-=1
            else:
                moving = -1
                count -= 1
            moving = -1
        else:
            moving = -1
            count -= 1
    pygame.draw.rect(gameDisplay, blue, (550, 50, 200, 50))
    edit.hover(550, 50, 750, 100, 200, 50, dark_black,sound, current_screen, gameDisplay)
    screen.blit(edit.text("Main Menu", gray, 20), (590, 65))
    if pygame.mouse.get_pressed()[0]:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]

        if 550 <= mouseX <= 750 and 50 <= mouseY <= 100:
            current_screen = 0  # main screen
    # button new game
    pygame.draw.rect(gameDisplay, blue, (550, 120, 200, 50))
    edit.hover(550, 120, 750, 170, 200, 50, dark_black,sound, current_screen, gameDisplay)
    screen.blit(edit.text("New Game", gray, 20), (595, 135))
    if pygame.mouse.get_pressed()[0]:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]
        if 550 <= mouseX <= 750 and 120 <= mouseY <= 170:
            time.sleep(1)
            # print("new game")
            count = 0
            kod = 0
            checking = 0
            last=[]
            moving=-1
            while level > 0:
                hint[level] = [0, 0]
                level -= 1

            ball = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
                    [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    pygame.draw.rect(gameDisplay, blue, (550, 600, 200, 50))
    if count >= 4:
        edit.hover(550, 600, 750, 650, 200, 50, dark_black,sound, current_screen, gameDisplay)
    screen.blit(edit.text("Check", gray, 20), (615, 615))
    if pygame.mouse.get_pressed()[0]:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]
        if 550 <= mouseX <= 750 and 600 <= mouseY <= 650 and count == 4:
            # print("sprawdzam")
            checking = 1
            level += 1
            count = 0

    # undo button
    pygame.draw.rect(gameDisplay, blue, (550, 530, 200, 50))
    if count > 0:
        edit.hover(550, 530, 750, 580, 200, 50, dark_black,sound, current_screen, gameDisplay)
    screen.blit(edit.text("Undo", gray, 20), (622, 545))
    if pygame.mouse.get_pressed()[0]:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]
        if 550 <= mouseX <= 750 and 530 <= mouseY <= 580 and count > 0:
            # print("cofam")
            if len(last)>0:
                count -= 1
                ball[level][last[len(last)-1]] = 0
                last.pop()
            else:
                count -= 1
                ball[level][count] = 0
    if pygame.mouse.get_pressed()[0]:
        pressed_color = screen.get_at(pos)
        """
red - 1 : (255, 39, 1, 255) 
yellow - 2 : (255, 251, 1, 255)
green - 3 : (1, 249, 1, 255)
blue - 4 : (1, 253, 255, 255)
purple - 5 : (149, 56, 255, 255)
pink - 6 : (255, 48, 147, 255)
"""

        #print(pressed_color, pos, count)
        if count < 4:
            if pressed_color == (255, 39, 1, 255) and (pos[1] > 610 and pos[1] < 650):
                # print("red")
                # ball[level][count] = 1
                moving = 1
                count += 1
            elif pressed_color == (255, 251, 1, 255) and (pos[1] > 610 and pos[1] < 650):
                # print("yellow")
                # ball[level][count] = 2
                moving = 2
                count += 1
            elif pressed_color == (1, 249, 1, 255) and (pos[1] > 610 and pos[1] < 650):
                # print("green")
                # ball[level][count] = 3
                moving = 3
                count += 1
            elif pressed_color == (1, 253, 255, 255) and (pos[1] > 610 and pos[1] < 650):
                # print("blue")
                # ball[level][count] = 4
                moving = 4
                count += 1
            elif pressed_color == (149, 56, 255, 255) and (pos[1] > 610 and pos[1] < 650):
                # print("purple")
                # ball[level][count] = 5
                moving = 5
                count += 1
            elif pressed_color == (255, 48, 147, 255) and (pos[1] > 610 and pos[1] < 650):
                # print("pink")
                # ball[level][count] = 6
                moving = 6
                count += 1
            elif pressed_color == (3, 59, 199, 255) and (pos[1] > 610 and pos[1] < 650):
                #print("empty")
                # ball[level][count] = 0
                moving = 7
                count += 1
    if level < 11:
        for i in range(level + 1):
            for j in range(count):
                if ball[i][j] != 0:
                    if i < 6:
                        screen.blit(pygame.image.load(str(ball[i][j]) + ".png"), (j * 74 + 85, 559 - i * 45))
                    else:
                        screen.blit(pygame.image.load(str(ball[i][j]) + ".png"), (j * 74 + 85, 559 - i * 45.5))
                else:
                    continue
                    # print(checking)

    if level < 11:
        if count == 4:
            hint[level] = check.check2(ball[level],code)
        # print(hint)
        for i in range(level):
            if hint[i][0] == 0 and hint[i][1] == 0:
                continue
            else:
                screen.blit(pygame.image.load(str(hint[i][0]) + str(hint[i][1]) + ".png"), (410, 560 - i * 48 + i * 2))
                # print("dodano")
            if hint[i][1] == 4:
                # print("wygrana")
                sound=0
                current_screen = 6  # wygrana
        checking = 0
    if level == 11:
        current_screen = 7
        sound=0

    if moving >= 0:
        pin = screen.blit(pygame.image.load(str(moving) + ".png"), (pos[0] - 18, pos[1] - 18))
        pygame.display.update()
    return 0