Advertisement
dmesticg

Untitled

Jun 17th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.14 KB | None | 0 0
  1. import random
  2.  
  3. class Deck: #!
  4. def __init__(self,numsuit,numcard):
  5. self.numsuit = numsuit
  6. self.numcard = numcard
  7. self.deck = [[True] * numsuit for i in range (numcard)]
  8.  
  9. def createCard(self): #!
  10. if self.deck.count:
  11. suitval = random.randint(0,self.numsuit-1)
  12. cardval = random.randint(0,self.numcard-1)
  13. while self.deck[cardval][suitval] == False:
  14. suitval = random.randint(0,self.numsuit-1)
  15. cardval = random.randint(0,self.numcard-1)
  16. self.deck[cardval][suitval] = False
  17. return((cardval,suitval))
  18.  
  19. def createHand(self,handSize):
  20. cards = []
  21. for i in range(handSize):
  22. card = Deck.createCard(self)
  23. cards.append(card)
  24. return(cards)
  25.  
  26. def changeHand(self,hand,indexList):
  27. print(self.deck)
  28. for i in range(len(indexList)):
  29. hand[indexList[i]] = Deck.createCard(self)
  30. return(hand)
  31.  
  32.  
  33. def setup():
  34. global restart_text,pause_text,throw_text,score_text,menuboxes,gameboxes,pokertable,pokertitle,start_text,whichmenu
  35. global bankamount,betamount,negatory_text,pository_text,amount_text,bet_text,check_text,fold_text,call_text,raise_text,balance_text
  36. global handsize,numberofplayers,backofcard,drawtwocards_text,deckimage,hand1,cardl,cardw,hand2,turn,turn_text,trueholder,trueholder1,thedeck,hand1,hand2
  37. global lel
  38. turn = 0
  39.  
  40. cardw = 80
  41. cardl = 110
  42. size(1000,650)
  43. #This is the amount of money each user wants to bet
  44. betamount = 0
  45. #Amount of money in bank
  46. bankamount = 100
  47. pokertable = loadImage("poker.jpg")
  48. pokertitle = loadImage("PokerTitle.png")
  49. backofcard = loadImage("backofcard.jpg")
  50. deckimage = loadImage("deck.png")
  51. start_text = [450,310,100,50,"START",color(255,99,71)]
  52.  
  53. bet_text = [780,100,200,50,"Bet",color(0,0,0)]
  54. negatory_text = [780,150,50,50,"-",color(50,50,50)]
  55. pository_text = [930,150,50,50,"+",color(50,50,50)]
  56. amount_text = [820,150,110,50,"$"+str(betamount),color(0,200,0)]
  57. check_text = [780,200,200,50,"check",color(139, 0, 255)]
  58. fold_text = [780,250,200,50,"fold",color(255, 0, 0)]
  59. call_text = [780,300,200,50,"call",color(255, 255, 0)]
  60. raise_text = [780,350,200,50,"raise",color( 255, 127, 0)]
  61. drawtwocards_text = [780,400,200,50,"change cards",color(0,0,0)]
  62. balance_text = [100,70,200,50,"balance:$"+str(bankamount),color(249,123,31)]
  63. turn_text = [780,450,200,50,"turn",color(0,0,0)]
  64.  
  65. whichmenu = 1
  66. menuboxes = [start_text]
  67.  
  68. handsize = 5
  69. numberofplayers =2
  70. trueholder = [False,False,False,False,False]
  71. thedeck = Deck(4,13)
  72. hand1 = thedeck.createHand(5)
  73. hand2 = thedeck.createHand(5)
  74.  
  75. cardw = 80
  76. cardl = 110
  77.  
  78. lel = True
  79.  
  80.  
  81. def draw():
  82. global whichmenu,trueholder
  83. global betamount,bankamount,bet_text,negatory_text,pository_text,amount_text,bet_text,check_text,fold_text,call_text,raise_text,balance_text
  84. global backofcard,handsize,numberofplayers,drawtwocards_text,deckimage,hand1,hand2, thedeck,turn,trueholder,trueholder1
  85. image(pokertable,-100,-50,1100,750)
  86. if whichmenu == 0:
  87. menu()
  88. elif whichmenu == 1:
  89. pokerTable()
  90. #this displays back of card
  91. #This displays the hand
  92.  
  93.  
  94.  
  95.  
  96.  
  97. def menu():
  98. global whichmenu
  99. background(0)
  100.  
  101. image(pokertable,0,0,1000,650)
  102. image(pokertitle,315,190,400,100)
  103. print(mouseX,mouseY)
  104. drawTextboxes(menuboxes)
  105. if isClicked(textboxes[0]):
  106. whichmenu = 1
  107.  
  108.  
  109.  
  110.  
  111. def pokerTable():
  112. global betamount,bankamount,bet_text,negatory_text,pository_text,amount_text,bet_text,check_text,fold_text,call_text,raise_text,balance_text
  113. global backofcard,handsize,numberofplayers,drawtwocards_text,deckimage,hand1,hand2, thedeck,turn,turn_text,trueholder,hand1
  114.  
  115. drawHand([[0,0],[0,0],[0,0],[0,0],[0,0]],1,backofcard,1152,1600)
  116. drawHand([[0,0],[0,0],[0,0],[0,0],[0,0]],0,backofcard,1152,1600)
  117. if turn == 1:
  118. drawHand(hand1,0,deckimage,80,110)
  119. else:
  120. drawHand(hand2,1,deckimage,80,110)
  121. gameboxes = [bet_text,negatory_text,pository_text,amount_text,bet_text, check_text,fold_text,call_text,raise_text,balance_text,drawtwocards_text,turn_text]
  122. drawTextboxes(gameboxes)
  123. betamount = getBet(gameboxes[2],gameboxes[1],betamount,bankamount)
  124. amount_text = [820,150,110,50,"$"+str(betamount),color(0,200,0)]
  125. if isClicked(gameboxes[11]):
  126. trueholder = [False,False,False,False,False]
  127. if turn ==0:
  128. turn = 1
  129. else:
  130. turn = 0
  131. if isClicked(gameboxes[10]):
  132. if turn == 1:
  133. indexes = [index for index in range(len(trueholder)) if trueholder[index] == True]
  134. hand1 = thedeck.changeHand(hand1,indexes)
  135. trueholder = [False,False,False,False,False]
  136. elif turn ==0:
  137. indexes = [index for index in range(len(trueholder)) if trueholder[index] == True]
  138. hand2 = thedeck.changeHand(hand2,indexes)
  139. trueholder = [False,False,False,False,False]
  140.  
  141. if isClicked(gameboxes[5]):
  142. check()
  143. elif isClicked(gameboxes[6]):
  144. fold()
  145. elif isClicked(gameboxes[7]):
  146. call()
  147. elif isClicked(gameboxes[8]):
  148. #Raise() is uppercase cuz raise() is a in-built function
  149. Raise()
  150.  
  151.  
  152.  
  153.  
  154. def Raise():
  155. pass
  156. def call():
  157. pass
  158.  
  159. def check():
  160. pass
  161.  
  162.  
  163. def fold():
  164. pass
  165.  
  166.  
  167.  
  168. def getBet(plusbox,minusbox,betamount,bankamount):
  169. if isClicked(minusbox) and betamount>1:
  170. betamount -=1
  171. elif isClicked(plusbox) and betamount<bankamount:
  172. betamount+=1
  173. return(betamount)
  174.  
  175.  
  176. def drawTextboxes(textboxes):
  177. textSize(30)
  178. fill(255)
  179. for i in range(len(textboxes)):
  180. fill(textboxes[i][5])
  181. rect(textboxes[i][0],textboxes[i][1],textboxes[i][2],textboxes[i][3])
  182. fill(255)
  183. text(textboxes[i][4],textboxes[i][0],textboxes[i][1]+35)
  184.  
  185. def drawtextboxes(textboxes):
  186. textSize(30)
  187. fill(255)
  188. for i in range(len(textboxes)):
  189. fill(textboxes[i][5])
  190. rect(textboxes[i][0],textboxes[i][1],textboxes[i][2],textboxes[i][3])
  191. fill(255)
  192. text(textboxes[i][4],textboxes[i][0],textboxes[i][1]+35)
  193.  
  194. def isClicked(info):
  195. clicked = False
  196. if mousePressed and mouseButton == LEFT:
  197. if info[0] < mouseX < info[0] + info[2] and info[1] < mouseY < info[1] + info[3]:
  198. clicked = True
  199. return clicked
  200.  
  201. def drawHand(hand,num,theimage,cardw,cardl):
  202. global backofcard,trueholder,lel
  203. for i in range(len(hand)):
  204. cardval = hand[i][0]
  205. suitval = hand[i][1]
  206.  
  207. textSize(30)
  208.  
  209. if isClicked([110+130*i,150+(num*250),115,160]) and sum(trueholder)<2 or trueholder[i]:
  210.  
  211. trueholder[i] = True
  212. copy(backofcard,0,0,1152,1600,110+130*i,150+(num*250),115,160)
  213.  
  214. else:
  215. copy(theimage, cardw*(cardval), cardl*suitval, cardw, cardl, 110+130*i, 150+(num*250), 115, 160)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement