Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from unicurses import *
- import sys
- import time
- from random import choice as rc
- import random
- def total(hand): #total
- aces = hand.count(11)
- t = sum(hand)
- if t > 21 and aces > 0:
- while aces > 0 and t > 21:
- t -= 10
- aces -= 1
- return t
- def random(one,two):
- import random
- number = random.randint(one,two)
- return number
- def number():
- number = int(random(9,10))
- if number >= 10 and number <= 12:
- value = 'T'
- elif number == 13:
- value = 'A'
- else:
- value = number
- return value
- def card():
- cardnumber = number()
- card = cardnumber
- return card
- def store10Cards():
- tenCards = [card(),
- card(),
- card(),
- card(),
- card(),
- card(),
- card(),
- card(),
- card(),
- card()]
- return tenCards
- stdscr = initscr()
- cards = store10Cards()
- c_template = '\n'.join([
- '┌────────────┐',
- '│{card} │',
- '│ │',
- '│ │',
- '│ │',
- '│ │',
- '│ │',
- '│ │',
- '│ │',
- '│ {card}│',
- '└────────────┘'])
- c_template10 = '\n'.join([
- '┌────────────┐',
- '│10 │',
- '│ │',
- '│ │',
- '│ │',
- '│ │',
- '│ │',
- '│ │',
- '│ │',
- '│ 10│',
- '└────────────┘'])
- scoreboard = '\n'.join([
- '┌────────────┐',
- '│ Player │',
- '│ │',
- '│ 4 │',
- '│ │',
- '│ │',
- '│ Computer │',
- '│ │',
- '│ 5 │',
- '│ │',
- '└────────────┘'])
- card1 = cards[0]
- card2 = cards[1]
- card3 = cards[2]
- card4 = cards[3]
- card5 = cards[4]
- card6 = cards[5]
- card7 = cards[6]
- card8 = cards[7]
- card9 = cards[8]
- card10 = cards[9]
- score_board = scoreboard
- if card1 == '10':
- card_string1 = c_template10
- elif card1 != '10':
- card_string1 = c_template.format(card=card1)
- if card1 == '10':
- card_string2 = c_template10
- elif card1 != '10':
- card_string2 = c_template.format(card=card2)
- if card1 == '10':
- card_string3 = c_template10
- elif card1 != '10':
- card_string3 = c_template.format(card=card3)
- if card1 == '10':
- card_string4 = c_template10
- elif card1 != '10':
- card_string4 = c_template.format(card=card4)
- if card1 == '10':
- card_string5 = c_template10
- elif card1 != '10':
- card_string5 = c_template.format(card=card5)
- if card1 == '10':
- card_string6 = c_template10
- elif card1 != '10':
- card_string6 = c_template.format(card=card6)
- if card1 == '10':
- card_string7 = c_template10
- elif card1 != '10':
- card_string7 = c_template.format(card=card7)
- if card1 == '10':
- card_string8 = c_template10
- elif card1 != '10':
- card_string8 = c_template.format(card=card8)
- if card1 == '10':
- card_string9 = c_template10
- elif card1 != '10':
- card_string9 = c_template.format(card=card9)
- if card1 == '10':
- card_string10 = c_template10
- elif card1 != '10':
- card_string10 = c_template.format(card=card10)
- def scoreboard():
- for i, line in enumerate(score_board.splitlines()):
- mvaddstr(12 + i, 1, line)
- endwin()
- def main1():
- clear()
- for i, line in enumerate(card_string1.splitlines()):
- mvaddstr(0 + i, 0, line)
- endwin()
- def main2():
- for i, line in enumerate(card_string2.splitlines()):
- mvaddstr(0 + i, 18, line)
- endwin()
- def main3():
- for i, line in enumerate(card_string3.splitlines()):
- mvaddstr(0 + i, 0, line)
- endwin()
- def main4():
- for i, line in enumerate(card_string4.splitlines()):
- mvaddstr(0 + i, 0, line)
- endwin()
- def main5():
- for i, line in enumerate(card_string5.splitlines()):
- mvaddstr(0 + i, 0, line)
- endwin()
- def main6():
- for i, line in enumerate(card_string6.splitlines()):
- mvaddstr(0 + i, 0, line)
- endwin()
- def main7():
- for i, line in enumerate(card_string7.splitlines()):
- mvaddstr(0 + i, 0, line)
- endwin()
- def main8():
- for i, line in enumerate(card_string8.splitlines()):
- mvaddstr(0 + i, 0, line)
- endwin()
- def main9():
- for i, line in enumerate(card_string9.splitlines()):
- mvaddstr(0 + i, 0, line)
- endwin()
- def main10():
- for i, line in enumerate(card_string10.splitlines()):
- mvaddstr(0 + i, 0, line)
- endwin()
- #if __name__ == '__main__':
- #main1()
- #deck = [] #deck of cards
- #cwin = 0 #computer wins
- #pwin = 0 #player wins
- #for i in range (2, 11):
- # for j in range ([24, 72][i == 10]):
- # deck.append(i)
- #stdscr = initscr() #Start the standard screen
- start_color() #Start the color service
- init_pair(1, COLOR_RED, 0) #color pair 1 is red text and no highlighting
- init_pair(2, COLOR_CYAN, 0) #color pair 2 is white text and no highlighting
- addstr('\n\n\n---------------------------------------------------------------------------', color_pair(1) | A_BOLD)
- addstr("\n\nAre You Ready To Try And Defeat The Undefeated Blackjack Master?\n\n\nThe First One To Win 10 Hands Wins!!! T's are 10s.\n\n\nWinning 1 Hand Does Not Mean You Win The Game.\n\n\nIt Is Possible To Win But Very Hard!!! Good Luck!!!\n\n\n", color_pair(2) | A_BOLD)
- addstr('---------------------------------------------------------------------------', color_pair(1) | A_BOLD)
- addstr('\n\nDo You Know The Rules Of Blackjack? (Y or N)\n\n', color_pair(2) | A_BOLD)
- addstr('---------------------------------------------------------------------------', color_pair(1) | A_BOLD)
- refresh() #refreshes
- cbreak() #lets user do Ctrl + C
- noecho() #Stops inputs from being shown
- a = getch() #Gets input
- while a == ord('q'): #Checks if input is q
- clear() #clears before exit
- exit() #quits
- if a == ord('n'): #Checks if input is n
- clear() #clears before displaying the next text
- addstr('\n\n-------------------------------------------------------------------------------------', color_pair(1) | A_BOLD)
- addstr('\n\nOk. That Is Ok. The Rules Are As Follows: \n\nThe Goal Is To Get To 21.\n\nYou Can Hit A Card (Receive Another) Or Stand And See What The Dealer Has And Does.\n\nThe Person With The Higest Value 21 Or Below Wins That Hand.\n\nAces Start As 11s But Change Automatticly To 1s If You Go Over 21 To Save You.\n\nIf You Get 21 Exactly You Get A Blackjack.\n\nA Blackjack Means You Automaticly Win Unless The Computer Gets A 21 And Ties You.\n\nBe Careful Not To Hit Too Many Times Because If You Go Over 21 You Lose That Hand.\n\nAny Face Card Is Automaticly A 10 At All Times.\n', color_pair(2) | A_BOLD)
- addstr('\n-------------------------------------------------------------------------------------\n\n\n', color_pair(1) | A_BOLD)
- refresh()
- time.sleep(16)
- a = '' #resets input variable
- b = '1'
- while a == ord('q'): #Checks if input is q
- clear() #Clears before exit
- exit() #quits
- while a == ord('y'): #Checks if input is y
- clear() #clears before displaying the next text
- addstr('\n\n\n\n\n----------------------------------------------------------------------------------', color_pair(1) | A_BOLD)
- addstr('\n\n\n Ok!!\n\n\n\n Have Fun!!\n\n\n\n Good Luck!!!\n\n\n', color_pair(2) | A_BOLD)
- addstr('----------------------------------------------------------------------------------\n\n\n', color_pair(1) | A_BOLD)
- refresh()
- time.sleep(3.85)
- b = '1'
- a = '' #resets input variable
- run_once = 0
- while b == '1':
- cbreak()
- scoreboard()
- main1()
- main2()
- #main3()
- a = getch()
- mvaddstr(2, 2, scoreboard)
- refresh()
- if run_once == 0:
- refresh()
- run_once = 1
- if a is not getch():
- b = '0'
- while a == 'q':
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement