Exemplo n.º 1
0
    def saveChanged(self):
        if self.lineEdit.text() == 'База данных не выбрана':
            return False
        DB = self.lineEdit.text()
        tableName = self.lineEdit_2.text()

        rows = self.tableWidget.rowCount()
        columns = self.tableWidget.columnCount()

        newData = []
        for rowCount in range(rows):
            buff = []
            for colCount in range(columns):
                try:
                    buff.append(self.tableWidget.item(rowCount, colCount).text())
                except:
                    buff.append('NULL')
            newData.append(buff)

        try:
            functions.push(DB, tableName, newData)
        except:
            errorWin = QtWidgets.QErrorMessage(self)
            errorWin.showMessage('Таблица не выбрана, изменять нечего')
Exemplo n.º 2
0
def main():
    global playing
    print("Welcome to Blackjack")

    player_name = input("What's your name? ")
    player_hand = classes.Hand(player_name)
    dealer_hand = classes.Hand("dealer")

    while True:
        try:
            player_total = int(input("How much are you bringing to the table? "))
            player_chips = classes.Chips(player_total)
            break
        except:
            print("We are sorry, this is an inappropriate value for your chips.")

    while True:
        deck = classes.Deck()
        deck.shuffle()

        functions.take_bet(player_chips)
        print("\n")

        player_hand.add_card(deck.deal())
        player_hand.add_card(deck.deal())

        dealer_hand.add_card(deck.deal())
        dealer_hand.add_card(deck.deal())

        functions.show_some(player_hand, dealer_hand)
        while playing:
            playing = functions.player_action(deck, player_hand)
            print("\n")
            functions.show_some(player_hand, dealer_hand)

            if player_hand.value > 21:
                functions.player_busts(player_hand, dealer_hand, player_chips)
                break
            


        if player_hand.value <= 21:
            functions.show_all(player_hand, dealer_hand)
            input("Press Enter to Continue ...")

            if dealer_hand.value < 17:
                print("The dealer has elected to hit:")
                dealer_hand.add_card(deck.deal())
                functions.show_all(player_hand, dealer_hand)
                input("Press Enter to Continue ...")

            if dealer_hand.value > 21:
                functions.dealer_busts(player_hand, dealer_hand, player_chips)

            elif dealer_hand.value > player_hand.value:
                functions.dealer_wins(player_hand, dealer_hand, player_chips)

            elif dealer_hand.value == player_hand.value:
                functions.push(player_hand, dealer_hand, player_chips)

            else:
                functions.player_wins(player_hand, dealer_hand, player_chips)

        if player_chips.total == 0:
            print("You have no more chips to play with, thank you for playing.")
            break

        action = input("Do you wish to play again? (y/n) ")

        if action[0].lower() == "n":
            break

        player_hand.clean_hand()
        dealer_hand.clean_hand()
        playing = True
Exemplo n.º 3
0
    # Asks the player if he wants another card, loops as long as the player wants more cards
    while functions.playing:
        functions.hit_or_stand(deck, player)
        # stops the game and shows the cards if the player busted
        if functions.bust(player):
            functions.show_all(player, dealer)
            functions.dealer_wins(chips)
            break
        # shows the cards after each new card drawn
        else:
            functions.show_some(player, dealer)
    # Dealer draws until he has equal or more points than the player
    while dealer.value <= player.value:
        if dealer.value < 21:
            functions.hit(deck, dealer)

    # Shows all the cards
    functions.show_all(player, dealer)

    # Decides the game winner
    if functions.bust(dealer):
        functions.player_wins(chips)
    elif player.value == dealer.value:
        functions.push()

    # Asks the player if he wants to continue playing
    if functions.replay(chips) == 'n':
        break
    else:
        functions.playing = True
Exemplo n.º 4
0
        #show all cards
        show(player_hand, dealer_hand)

        #Winning scenarios

        if dealer_hand.value > 21:
            dealer_busts(player_hand, dealer_hand, player_chips)

        elif dealer_hand.value > player_hand.value:
            dealer_wins(player_hand, dealer_hand, player_chips)

        elif dealer_hand.value < player_hand.value:
            player_wins(player_hand, dealer_hand, player_chips)

        else:
            push(player_hand, dealer_hand)

    print("\nPlayer you have {} chips available".format(player_chips.total))

    #Ask to play again

    ask = input("Want to play again? y/n").lower()

    if ask[0] == 'y':
        print("OK! Get ready for next round!")
        playable = True
    else:
        print("Thank You for playing!")
        break
Exemplo n.º 5
0
    while playing:
        hit_or_stand(the_deck, player)
        show_some(player, dealer)

        if player.value > 21:
            player_busts(player, dealer, player_chips)
            break

    if player.value <= 21:
        while dealer.value >= 17:
            hit(the_deck, dealer)
            show_all(player, dealer)
        if dealer.value > 21:
            dealer_busts(player, dealer, player_chips)
        elif dealer.value > player.value:
            dealer_wins(player, dealer, player_chips)
        elif dealer.value < player.value:
            player_wins(player, dealer, player_chips)
        else:
            push(player, dealer)

    new_game = input("Would you like to play another hand? Enter Y or N")

    if new_game[0].lower() == 'y':
        playing = True
        continue
    else:
        print("Thanks for playing!")
        break