dmesticg

Untitled

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