Exemple #1
0
def com():
    """this is the computer algorithm which is totally random """
    global discardpile
    global stockpile

    # sort_cards(computer_cards)
    pile = random.choice([0, 1])
    print(computer_cards)
    print(pile)

    if pile == 0:
        #choose from dicard pile
        card = discardpile[len(discardpile) - 1]
        computer_cards.append(card)
        discardpile.remove(card)
        #choose any random card and drops it
        card = computer_cards[int(random.randint(1, 13)) - 1]
        computer_cards.remove(card)
        discardpile.append(card)

    if pile == 1:
        #choose from stockpile
        card = stockpile[0]
        computer_cards.append(card)
        stockpile.remove(card)
        #choose any random card and drops it
        card = computer_cards[int(random.randint(1, 13)) - 1]
        computer_cards.remove(card)
        discardpile.append(card)
    if com_declare(computer_cards) == True:
        #if computer was successful in making a set
        textbox(screen, "The computer won the game")
Exemple #2
0
def pickDiscardPile(deck):
    """picks the card from the dicardpile"""
    if (len(deck) == 13):
        card = discardpile[len(discardpile) - 1]
        deck.append(card)
        discardpile.remove(card)
        textbox(screen, "Enter to continue.")
        while key1() != K_RETURN:
            pass
    else:
        textbox(screen, "Number of cards is 14.Connot pick.Enter to continue.")
        while key1() != K_RETURN:
            pass
Exemple #3
0
def pickStockPile(deck):
    """picks the card from the stockpile"""
    if (len(deck) == 13):
        card = stockpile[0]
        deck.append(card)
        stockpile.remove(card)
        textbox(screen, "Enter to continue.")
        while key1() != K_RETURN:
            pass
    else:
        textbox(screen, "Number of cards is 14.Connot pick.Enter to continue.")
        while key1() != K_RETURN:
            pass
Exemple #4
0
def drop_card(deck):
    """choose the card from the deck you want to drop from the deck
	the choosen card moves to the dicardpile"""
    global turn
    print("Drop card")
    global discardpile
    if (len(deck) < 14):
        textbox(screen, "Length should be 14. Enter to continue.")
        # fontobject = pygame.font.Font(None,29)
        while key1() != K_RETURN:
            pass
        return
    drop = input1("Drop card number", screen)
    card = deck[int(drop) - 1]
    deck.remove(card)
    discardpile.append(card)
    turn = 1
Exemple #5
0
def declarePlayer(deck):
    """checks the condition whether the in sequence or not"""
    if (declare(deck)):
        print("Win")
        winmusic = pygame.mixer.music.load(
            str(os.path.join(os.getcwd(), "sound", "win" + '.mp3')))
        pygame.mixer.music.play()
        textbox(screen, "You win. Enter to exit")
        while key1() != K_RETURN:
            pass
        exit()
    else:
        print("Lose")
        losemuisc = pygame.mixer.music.load(
            str(os.path.join(os.getcwd(), "sound", "lose" + '.mp3')))
        pygame.mixer.music.play()
        textbox(screen, "You lose. Enter to exit.")
        while key1() != K_RETURN:
            pass
        exit()
Exemple #6
0
def spaceKey(dispW,dispH,screenInfo,gameDisplay,clock,sf,hit,M,direc,npcCol,NPCs):
    done = False
    ptr = NPCs
    if direc == 'ri':
        if M[hit[1]][hit[2]+1] ==2:
            textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,sf[str((hit[1],hit[2]+1))])
        elif M[hit[1]][hit[2]+2] ==2:
            textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,sf[str((hit[1],hit[2]+2))])
        elif npcCol[1]:
            while not done:
                if ptr.h[2]<hit[3] and ptr.h[2]>hit[2]-3:
                    if ptr.h[0]==hit[1]:
                        textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,ptr.k)
                        done = True
                if ptr.n != False:
                    ptr=ptr.n
                else:
                    done = True

    elif direc == 'le':
        if M[hit[0]][hit[2]+1] ==2:
            textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,sf[str((hit[0],hit[2]+1))])
        elif M[hit[0]][hit[2]+2] ==2:
            textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,sf[str((hit[0],hit[2]+2))])
        elif npcCol[0]:
            while not done:
                if ptr.h[2]<hit[3] and ptr.h[2]>hit[2]-3:
                    if ptr.h[1]==hit[0]:
                        textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,ptr.k)
                        done = True
                if ptr.n != False:
                    ptr=ptr.n
                else:
                    done = True

    elif direc == 'up':
        if M[hit[0]+1][hit[2]] ==2:
            textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,sf[str((hit[0]+1,hit[2]))])
        elif M[hit[0]+2][hit[2]] ==2:
            textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,sf[str((hit[0]+2,hit[2]))])
        elif npcCol[2]:
            while not done:
                if ptr.h[0]<hit[1] and ptr.h[0]>hit[0]-3:
                    if ptr.h[3]==hit[2]:
                        textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,ptr.k)
                        done = True
                if ptr.n != False:
                    ptr=ptr.n
                else:
                    done = True

    elif direc == 'do':
        if M[hit[0]+1][hit[3]] ==2:
            textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,sf[str((hit[0]+1,hit[3]))])
        elif M[hit[0]+2][hit[3]] ==2:
            textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,sf[str((hit[0]+2,hit[3]))])
        elif npcCol[3]:
            while not done:
                if ptr.h[0]<hit[1] and ptr.h[0]>hit[0]-3:
                    if ptr.h[2]==hit[3]:
                        textbox(dispW,dispH,screenInfo,gameDisplay,clock,sf,ptr.k)
                        done = True
                if ptr.n != False:
                    ptr=ptr.n
                else:
                    done = True
Exemple #7
0
def blkscreen(dispW, dispH, screenInfo, gameDisplay, clock):
    gameDisplay.fill((0, 0, 0))
    pygame.display.update()
    sf = shelve.open('misc1')
    textbox(dispW, dispH, screenInfo, gameDisplay, clock, sf, 'blkScrn')