Advertisement
Guest User

a

a guest
Aug 8th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.51 KB | None | 0 0
  1. from unicurses import *
  2. import sys
  3. import time
  4. from random import choice as rc
  5. import random
  6.  
  7. def total(hand): #total
  8. aces = hand.count(11)
  9. t = sum(hand)
  10. if t > 21 and aces > 0:
  11. while aces > 0 and t > 21:
  12. t -= 10
  13. aces -= 1
  14. return t
  15.  
  16.  
  17. def random(one,two):
  18. import random
  19. number = random.randint(one,two)
  20. return number
  21.  
  22.  
  23. def number():
  24. number = int(random(9,10))
  25. if number >= 10 and number <= 12:
  26. value = 'T'
  27. elif number == 13:
  28. value = 'A'
  29. else:
  30. value = number
  31. return value
  32.  
  33.  
  34. def card():
  35. cardnumber = number()
  36. card = cardnumber
  37. return card
  38.  
  39. def store10Cards():
  40. tenCards = [card(),
  41. card(),
  42. card(),
  43. card(),
  44. card(),
  45. card(),
  46. card(),
  47. card(),
  48. card(),
  49. card()]
  50. return tenCards
  51.  
  52.  
  53. stdscr = initscr()
  54. cards = store10Cards()
  55.  
  56. c_template = '\n'.join([
  57. '┌────────────┐',
  58. '│{card} │',
  59. '│ │',
  60. '│ │',
  61. '│ │',
  62. '│ │',
  63. '│ │',
  64. '│ │',
  65. '│ │',
  66. '│ {card}│',
  67. '└────────────┘'])
  68.  
  69. c_template10 = '\n'.join([
  70. '┌────────────┐',
  71. '│10 │',
  72. '│ │',
  73. '│ │',
  74. '│ │',
  75. '│ │',
  76. '│ │',
  77. '│ │',
  78. '│ │',
  79. '│ 10│',
  80. '└────────────┘'])
  81. scoreboard = '\n'.join([
  82. '┌────────────┐',
  83. '│ Player │',
  84. '│ │',
  85. '│ 4 │',
  86. '│ │',
  87. '│ │',
  88. '│ Computer │',
  89. '│ │',
  90. '│ 5 │',
  91. '│ │',
  92. '└────────────┘'])
  93.  
  94. card1 = cards[0]
  95. card2 = cards[1]
  96. card3 = cards[2]
  97. card4 = cards[3]
  98. card5 = cards[4]
  99. card6 = cards[5]
  100. card7 = cards[6]
  101. card8 = cards[7]
  102. card9 = cards[8]
  103. card10 = cards[9]
  104.  
  105. score_board = scoreboard
  106.  
  107. if card1 == '10':
  108. card_string1 = c_template10
  109. elif card1 != '10':
  110. card_string1 = c_template.format(card=card1)
  111.  
  112. if card1 == '10':
  113. card_string2 = c_template10
  114. elif card1 != '10':
  115. card_string2 = c_template.format(card=card2)
  116.  
  117. if card1 == '10':
  118. card_string3 = c_template10
  119. elif card1 != '10':
  120. card_string3 = c_template.format(card=card3)
  121.  
  122. if card1 == '10':
  123. card_string4 = c_template10
  124. elif card1 != '10':
  125. card_string4 = c_template.format(card=card4)
  126.  
  127. if card1 == '10':
  128. card_string5 = c_template10
  129. elif card1 != '10':
  130. card_string5 = c_template.format(card=card5)
  131.  
  132. if card1 == '10':
  133. card_string6 = c_template10
  134. elif card1 != '10':
  135. card_string6 = c_template.format(card=card6)
  136.  
  137. if card1 == '10':
  138. card_string7 = c_template10
  139. elif card1 != '10':
  140. card_string7 = c_template.format(card=card7)
  141.  
  142. if card1 == '10':
  143. card_string8 = c_template10
  144. elif card1 != '10':
  145. card_string8 = c_template.format(card=card8)
  146.  
  147. if card1 == '10':
  148. card_string9 = c_template10
  149. elif card1 != '10':
  150. card_string9 = c_template.format(card=card9)
  151.  
  152. if card1 == '10':
  153. card_string10 = c_template10
  154. elif card1 != '10':
  155. card_string10 = c_template.format(card=card10)
  156.  
  157. def scoreboard():
  158. for i, line in enumerate(score_board.splitlines()):
  159. mvaddstr(12 + i, 1, line)
  160. endwin()
  161.  
  162. def main1():
  163. clear()
  164. for i, line in enumerate(card_string1.splitlines()):
  165. mvaddstr(0 + i, 0, line)
  166. endwin()
  167.  
  168. def main2():
  169. for i, line in enumerate(card_string2.splitlines()):
  170. mvaddstr(0 + i, 18, line)
  171. endwin()
  172.  
  173. def main3():
  174. for i, line in enumerate(card_string3.splitlines()):
  175. mvaddstr(0 + i, 0, line)
  176. endwin()
  177.  
  178. def main4():
  179. for i, line in enumerate(card_string4.splitlines()):
  180. mvaddstr(0 + i, 0, line)
  181. endwin()
  182.  
  183. def main5():
  184. for i, line in enumerate(card_string5.splitlines()):
  185. mvaddstr(0 + i, 0, line)
  186. endwin()
  187.  
  188. def main6():
  189. for i, line in enumerate(card_string6.splitlines()):
  190. mvaddstr(0 + i, 0, line)
  191. endwin()
  192.  
  193. def main7():
  194. for i, line in enumerate(card_string7.splitlines()):
  195. mvaddstr(0 + i, 0, line)
  196. endwin()
  197.  
  198. def main8():
  199. for i, line in enumerate(card_string8.splitlines()):
  200. mvaddstr(0 + i, 0, line)
  201. endwin()
  202.  
  203. def main9():
  204. for i, line in enumerate(card_string9.splitlines()):
  205. mvaddstr(0 + i, 0, line)
  206. endwin()
  207.  
  208. def main10():
  209. for i, line in enumerate(card_string10.splitlines()):
  210. mvaddstr(0 + i, 0, line)
  211. endwin()
  212.  
  213.  
  214. #if __name__ == '__main__':
  215. #main1()
  216.  
  217.  
  218. #deck = [] #deck of cards
  219.  
  220. #cwin = 0 #computer wins
  221. #pwin = 0 #player wins
  222.  
  223. #for i in range (2, 11):
  224. # for j in range ([24, 72][i == 10]):
  225. # deck.append(i)
  226.  
  227. #stdscr = initscr() #Start the standard screen
  228.  
  229. start_color() #Start the color service
  230.  
  231. init_pair(1, COLOR_RED, 0) #color pair 1 is red text and no highlighting
  232. init_pair(2, COLOR_CYAN, 0) #color pair 2 is white text and no highlighting
  233.  
  234. addstr('\n\n\n---------------------------------------------------------------------------', color_pair(1) | A_BOLD)
  235. 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)
  236. addstr('---------------------------------------------------------------------------', color_pair(1) | A_BOLD)
  237. addstr('\n\nDo You Know The Rules Of Blackjack? (Y or N)\n\n', color_pair(2) | A_BOLD)
  238. addstr('---------------------------------------------------------------------------', color_pair(1) | A_BOLD)
  239.  
  240. refresh() #refreshes
  241.  
  242. cbreak() #lets user do Ctrl + C
  243.  
  244. noecho() #Stops inputs from being shown
  245.  
  246. a = getch() #Gets input
  247.  
  248. while a == ord('q'): #Checks if input is q
  249. clear() #clears before exit
  250. exit() #quits
  251.  
  252. if a == ord('n'): #Checks if input is n
  253.  
  254. clear() #clears before displaying the next text
  255.  
  256. addstr('\n\n-------------------------------------------------------------------------------------', color_pair(1) | A_BOLD)
  257. 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)
  258. addstr('\n-------------------------------------------------------------------------------------\n\n\n', color_pair(1) | A_BOLD)
  259.  
  260. refresh()
  261.  
  262. time.sleep(16)
  263.  
  264. a = '' #resets input variable
  265.  
  266. b = '1'
  267.  
  268. while a == ord('q'): #Checks if input is q
  269. clear() #Clears before exit
  270. exit() #quits
  271.  
  272. while a == ord('y'): #Checks if input is y
  273.  
  274. clear() #clears before displaying the next text
  275.  
  276. addstr('\n\n\n\n\n----------------------------------------------------------------------------------', color_pair(1) | A_BOLD)
  277. 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)
  278. addstr('----------------------------------------------------------------------------------\n\n\n', color_pair(1) | A_BOLD)
  279.  
  280. refresh()
  281.  
  282. time.sleep(3.85)
  283.  
  284. b = '1'
  285.  
  286. a = '' #resets input variable
  287.  
  288. run_once = 0
  289.  
  290. while b == '1':
  291. cbreak()
  292. scoreboard()
  293. main1()
  294. main2()
  295. #main3()
  296. a = getch()
  297. mvaddstr(2, 2, scoreboard)
  298. refresh()
  299. if run_once == 0:
  300. refresh()
  301. run_once = 1
  302. if a is not getch():
  303. b = '0'
  304. while a == 'q':
  305. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement