예제 #1
0
 def generate(self, num):
     d = []
     for i in range(num):
         for j in range(14):
             d.append(card(self.vals[j], 'S'))
             d.append(card(self.vals[j], 'C'))
             d.append(card(self.vals[j], 'D'))
             d.append(card(self.vals[j], 'H'))
     return d
예제 #2
0
    def on_mouse_press(self, x, y, button, modifiers):
        """
        Called whenever the mouse button is clicked.
        """
        i=0
        if(self.draw==1 and self.turn=='p' and self.meld==False):

            while i <len(self.self_cards):
                if(self.self_cards[i].center_x-self.SCREEN_WIDTH*0.04<=x<=self.self_cards[i].center_x+self.SCREEN_WIDTH*0.04):
                    if(self.self_cards[i].center_y-self.SCREEN_HEIGHT*0.04<=y<=self.self_cards[i].center_y+self.SCREEN_HEIGHT*0.04):
                        self.self_cards[i].center_y=self.SCREEN_HEIGHT*0.5
                        self.self_cards[i].center_x=self.SCREEN_WIDTH*0.6
                        m=card(self.self_cards[i].no,self.self_cards[i].suit,self.GAME_CONFIG)
                        if (not (m.no==self.m.no and m.suit==self.m.suit)):
                            self.shown_deck.append(m)
                            self.self_cards[i].remove_from_sprite_lists()
                            self.draw=0
                            self.flg=0
                            self.turn='c'
                            break
                i+=1
        elif(self.draw==1 and self.turn=='p' and self.meld==True and len(self.meld_cards)<5):
            while i<(len(self.self_cards)):
                if(self.self_cards[i].center_x-self.SCREEN_WIDTH*0.04<=x<=self.self_cards[i].center_x+self.SCREEN_WIDTH*0.04):
                    if(self.self_cards[i].center_y-self.SCREEN_HEIGHT*0.04<=y<=self.self_cards[i].center_y+self.SCREEN_HEIGHT*0.04):
                        m=card(self.self_cards[i].no,self.self_cards[i].suit,self.GAME_CONFIG)
                        self.meld_cards.append(m)
                        self.self_cards[i].remove_from_sprite_lists()
                        self.flg=1
                        break
                i+=1

        elif(self.draw==0 and self.flg==0 and self.turn=='p'):
            if(self.shown_deck[-1].center_x-self.SCREEN_WIDTH*0.04<=x<=self.shown_deck[-1].center_x+self.SCREEN_WIDTH*0.04):
                if(self.shown_deck[-1].center_y-self.SCREEN_HEIGHT*0.04<=y<=self.shown_deck[-1].center_y+self.SCREEN_HEIGHT*0.04):
                    self.shown_deck[-1].center_y=self.SCREEN_HEIGHT*0.2
                    self.shown_deck[-1].center_x=self.SCREEN_WIDTH*self.g
                    self.m=card(self.shown_deck[-1].no,self.shown_deck[-1].suit,self.GAME_CONFIG)
                    self.self_cards.append(self.m)
                    self.shown_deck[-1].remove_from_sprite_lists()
                    self.draw=1
                    self.flg=1
            if(self.back_of_card.center_x-self.SCREEN_WIDTH*0.04<=x<=self.back_of_card.center_x+self.SCREEN_WIDTH*0.04):
                if(self.back_of_card.center_y-self.SCREEN_HEIGHT*0.04<=y<=self.back_of_card.center_y+self.SCREEN_HEIGHT*0.04):
                    if(len(self.hidden_deck)==1):
                        self.trigger_game_over()
                    else:    
                        self.hidden_deck[-1].center_y=self.SCREEN_HEIGHT*0.2
                        self.hidden_deck[-1].center_x=self.SCREEN_WIDTH*self.g
                        self.m=card(self.hidden_deck[-1].no,self.hidden_deck[-1].suit,self.GAME_CONFIG)
                        self.self_cards.append(self.m)
                        self.hidden_deck[-1].remove_from_sprite_lists()
                        self.draw=1
                        self.flg=1
예제 #3
0
 def create_cards(self):
     """ sets up cards in deck """
     l=['H','S','C','D']
     k=['A','2','3','4','5','6','7','8','9','10','J','Q','K']
     shuffle(l)
     shuffle(k)
     self.back_of_card=card('1','R',self.GAME_CONFIG)
     self.back_of_card.center_y = self.SCREEN_HEIGHT*0.5
     self.back_of_card.center_x = self.SCREEN_WIDTH*0.4
     
     for i in range(4):
         for j in range(13):
             self.m=card(k[j],l[i],self.GAME_CONFIG)
             self.cards.append(self.m)
예제 #4
0
 def meld_comp(self,i,j,k):
     self.meld_cards.append(self.comp_cards[i])
     self.meld_cards.append(self.comp_cards[j])
     self.meld_cards.append(self.comp_cards[k])
     z=arcade.SpriteList()
     for i in range(len(self.meld_cards)):
         m=card(self.meld_cards[i].no,self.meld_cards[i].suit,self.GAME_CONFIG,1)
         z.append(m)
     self.meld_list.append(z)
     while(len(self.meld_cards)>0):
         self.meld_cards[0].remove_from_sprite_lists()
예제 #5
0
    def draw_game(self):
        """ Draw all the sprites, along with the score. """

        # Draw the background texture
        arcade.draw_texture_rectangle(
            self.SCREEN_WIDTH // 2, 
            self.SCREEN_HEIGHT // 2,
            self.SCREEN_WIDTH, 
            self.SCREEN_HEIGHT, 
            self.background_ingame
            )

        
        output = f"{self.score}"
        arcade.draw_text(output, self.SCREEN_WIDTH*0.1, self.SCREEN_HEIGHT*0.95, (239, 182, 90), 28,align="center", anchor_x="center", anchor_y="center",)
        
        
        self.g=0.1
        #print(len(self.self_cards))
        for i in range(len(self.self_cards)):
            self.self_cards[i].center_y = self.SCREEN_HEIGHT*0.2
            self.self_cards[i].center_x = self.SCREEN_WIDTH*self.g
            self.self_cards[i].draw()
            self.g+=0.08
        self.g=0.1
        for i in range(len(self.comp_cards)):
            m=card('1','R',self.GAME_CONFIG)
            m.center_y = self.SCREEN_HEIGHT*0.8
            m.center_x = self.SCREEN_WIDTH*self.g
            self.g+=0.08
            m.draw()
        self.back_of_card.draw()
        if(len(self.shown_deck)!=0):
            self.shown_deck[-1].center_y=self.SCREEN_HEIGHT*0.5
            self.shown_deck[-1].center_x=self.SCREEN_WIDTH*0.6
            self.shown_deck[-1].draw()
        g=0.1
        for  i in range(len(self.meld_cards)):
            self.meld_cards[i].center_y=self.SCREEN_HEIGHT*0.55
            self.meld_cards[i].center_x=self.SCREEN_WIDTH*g
            self.meld_cards[i].draw()
            g+=0.08

        self.h=0.65
        for j in self.meld_list:
            g=0.8
            for  i in range(len(j)):
                j[i].center_y=self.SCREEN_HEIGHT*self.h
                j[i].center_x=self.SCREEN_WIDTH*g
                j[i].draw()
                g+=0.02
            self.h-=0.1
예제 #6
0
    def __init__(self):
        self.SUITS = ["Clubs", "Hearts", "Diamonds", "Spades"]
        self.RANKS = [
            "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen",
            "King", "Ace"
        ]

        self.deckStart = []
        for suit in self.SUITS:
            for rank in self.RANKS:
                self.deckStart.append(card(rank, suit))

        self.playDeck = copy.deepcopy(self.deckStart)
        random.shuffle(self.playDeck)
예제 #7
0
파일: Game.py 프로젝트: Godiez1/Poker
 def __init__(self, P1, P2 = None, P3 = None, P4 = None, P5 = None):
     self.P1 = P1
     self.P2 = P2
     self.P3 = P3
     self.P4 = P4
     self.P5 = P5
     self.deck = card()
     self.deck.deck.remove('Joker')
     self.make_Player()
     self.player_list = [self.P1, self.P2, self.P3, self.P4, self.P5]
     self.player_turple = (self.P1, self.P2, self.P3, self.P4, self.P5)
     self.pp_list = ['P1', 'P2', 'P3', 'P4', 'P5']
     self.pp_turple = ('P1', 'P2', 'P3', 'P4', 'P5')
     self.money_list = [self.P1.money, self.P2.money, self.P3.money, self.P4.money, self.P5.money]
     self.max_money = []
     self.dealer = []
예제 #8
0
 def mel(self):
     asc=0
     dsc=0
     eq=0
     f=0
     if(len(self.meld_cards)==3):
         if(self.meld_cards[0].num>self.meld_cards[1].num and self.meld_cards[0].suit==self.meld_cards[1].suit):
             for i in range(len(self.meld_cards)-1):
                 if(self.meld_cards[i].num!=self.meld_cards[i+1].num+1):
                         dsc=1
             if(dsc==1):
                 print("not dsc")
                 output = "Invalid Meld"
                 print(output)
                 while(len(self.meld_cards)>0):
                     m=card(self.meld_cards[0].no,self.meld_cards[0].suit,self.GAME_CONFIG)
                     self.self_cards.append(m)
                     self.meld_cards[0].remove_from_sprite_lists()                        
             else:
                 z=arcade.SpriteList()
                 for i in range(len(self.meld_cards)):
                     m=card(self.meld_cards[i].no,self.meld_cards[i].suit,self.GAME_CONFIG,1)
                     z.append(m)
                 self.meld_list.append(z)
                 while(len(self.meld_cards)>0):
                     self.meld_cards[0].remove_from_sprite_lists()
                     
         elif(self.meld_cards[0].num<self.meld_cards[1].num and self.meld_cards[0].suit==self.meld_cards[1].suit):
             for i in range(len(self.meld_cards)-1):
                 if(self.meld_cards[i].num!=self.meld_cards[i+1].num-1):
                     asc=1
                     break
             if(asc==1):
                 print("not asc")
                 output = "Invalid Meld"
                 print(output)
                 while(len(self.meld_cards)>0):
                     m=card(self.meld_cards[0].no,self.meld_cards[0].suit,self.GAME_CONFIG)
                     self.self_cards.append(m)
                     self.meld_cards[0].remove_from_sprite_lists()
             else:
                 z=arcade.SpriteList()
                 for i in range(len(self.meld_cards)):
                     m=card(self.meld_cards[i].no,self.meld_cards[i].suit,self.GAME_CONFIG,1)
                     z.append(m)
                 self.meld_list.append(z)
                 while(len(self.meld_cards)>0):
                     self.meld_cards[0].remove_from_sprite_lists()
         elif(self.meld_cards[0].num==self.meld_cards[1].num):
             for i in range(len(self.meld_cards)-1):
                 if(self.meld_cards[i].num!=self.meld_cards[i+1].num):
                     eq=1
                     break
             if(eq==1):
                 print("not eq")
                 for i in range(len(self.meld_cards)):
                     print(self.meld_cards[i].num)
                 output = "Invalid Meld"
                 print(output)
                 while(len(self.meld_cards)>0):
                     m=card(self.meld_cards[0].no,self.meld_cards[0].suit,self.GAME_CONFIG,1)
                     self.self_cards.append(m)
                     self.meld_cards[0].remove_from_sprite_lists()
             else:
                 z=arcade.SpriteList()
                 for i in range(len(self.meld_cards)):
                     m=card(self.meld_cards[i].no,self.meld_cards[i].suit,self.GAME_CONFIG,1)
                     z.append(m)
                 self.meld_list.append(z)
                 while(len(self.meld_cards)>0):
                     self.meld_cards[0].remove_from_sprite_lists()
         
         else:
             print("meld not possible")
             while(len(self.meld_cards)>0):
                 m=card(self.meld_cards[0].no,self.meld_cards[0].suit,self.GAME_CONFIG)
                 self.self_cards.append(m)
                 self.meld_cards[0].remove_from_sprite_lists()
         self.meld=False
     else:
         print("meld not possible")
         while(len(self.meld_cards)>0):
             m=card(self.meld_cards[0].no,self.meld_cards[0].suit,self.GAME_CONFIG)
             self.self_cards.append(m)
             self.meld_cards[0].remove_from_sprite_lists()
         self.meld=False
예제 #9
0
    def on_update(self,delta_time):
        draw_from_shown=False
        if(len(self.hidden_deck)<1 or len(self.self_cards)<3 or len(self.comp_cards)<3):
            self.trigger_game_over()
        if(self.turn=='c'):
            i=0
            while i<len(self.comp_cards)-1:
                j=i+1
                while j <len(self.comp_cards):
                    if(self.comp_cards[i].num==self.comp_cards[j].num):
                        if(self.shown_deck[-1].num==self.comp_cards[i].num):
                            draw_from_shown=True
                            break
                    if(self.comp_cards[i].num+1==self.comp_cards[j].num and self.comp_cards[i].suit==self.comp_cards[j].suit):
                        if((self.shown_deck[-1].num==self.comp_cards[i].num-1 or self.shown_deck[-1].num==self.comp_cards[j].num+1) and self.shown_deck[-1].suit==self.comp_cards[i].suit):
                            draw_from_shown=True
                            break
                    if(self.comp_cards[i].num-1==self.comp_cards[j].num and self.comp_cards[i].suit==self.comp_cards[j].suit):
                        if((self.shown_deck[-1].num==self.comp_cards[j].num-1 or self.shown_deck[-1].num==self.comp_cards[i].num+1) and self.shown_deck[-1].suit==self.comp_cards[i].suit):
                            draw_from_shown=True
                            break
                    if(self.comp_cards[i].num+2==self.comp_cards[j].num and self.comp_cards[i].suit==self.comp_cards[j].suit):
                        if((self.shown_deck[-1].num==self.comp_cards[i].num+1) and self.shown_deck[-1].suit==self.comp_cards[i].suit):
                            draw_from_shown=True
                            break
                    if(self.comp_cards[i].num-2==self.comp_cards[j].num and self.comp_cards[i].suit==self.comp_cards[j].suit):
                        if((self.shown_deck[-1].num==self.comp_cards[i].num-1) and self.shown_deck[-1].suit==self.comp_cards[i].suit):
                            draw_from_shown=True
                            break
                    j+=1
                i+=1
            if(draw_from_shown==True):
                self.g=0.1
                self.shown_deck[-1].center_y=self.SCREEN_HEIGHT*0.8
                self.shown_deck[-1].center_x=self.SCREEN_WIDTH*self.g
                self.m=card(self.shown_deck[-1].no,self.shown_deck[-1].suit,self.GAME_CONFIG,0,1)
                self.g+=0.08
                self.comp_cards.append(self.m)
                self.copy_of_shown=self.shown_deck[-1]
                self.shown_deck[-1].remove_from_sprite_lists()
            else:
                self.hidden_deck[-1].center_y=self.SCREEN_HEIGHT*0.8
                self.hidden_deck[-1].center_x=self.SCREEN_WIDTH*self.g
                self.m=card(self.hidden_deck[-1].no,self.hidden_deck[-1].suit,self.GAME_CONFIG,0,1)
                self.comp_cards.append(self.m)
                self.hidden_deck[-1].remove_from_sprite_lists()


            i=0
            j=0
            k=0
            while(i<len(self.comp_cards)):
                j=i+1
                while(j<len(self.comp_cards)):
                    k=j+1
                    flg=0
                    while(k<len(self.comp_cards)):
                        
                        if(self.comp_cards[i].num==self.comp_cards[j].num):
                            if(self.comp_cards[k].num==self.comp_cards[i].num):
                                self.meld_comp(i,j,k)
                                flg=1                                
                        if(self.comp_cards[i].num+1==self.comp_cards[j].num and self.comp_cards[i].suit==self.comp_cards[j].suit):
                            if((self.comp_cards[k].num==self.comp_cards[i].num-1 or self.comp_cards[k].num==self.comp_cards[j].num+1) and self.shown_deck[-1].suit==self.comp_cards[i].suit):
                                self.meld_comp(i,j,k)
                                flg=1
                        if(self.comp_cards[i].num-1==self.comp_cards[j].num and self.comp_cards[i].suit==self.comp_cards[j].suit):
                            if((self.shown_deck[-1].num==self.comp_cards[j].num-1 or self.shown_deck[-1].num==self.comp_cards[i].num+1) and self.shown_deck[-1].suit==self.comp_cards[i].suit):
                                self.meld_comp(i,j,k)
                                flg=1
                        if(flg==0):
                            k+=1
                    j+=1
                i+=1
            max_card=self.comp_cards[0]
            if(draw_from_shown==True):
                for i in range(len(self.comp_cards)):
                        if(max_card.num<self.comp_cards[i].num and not (max_card.no==self.copy_of_shown.no and max_card.suit==self.copy_of_shown.suit)):
                            max_card=self.comp_cards[i]
                m=card(max_card.no,max_card.suit,self.GAME_CONFIG)
                self.shown_deck.append(m)
                i=0
                while(i <len(self.comp_cards)):
                    if(max_card.no==self.comp_cards[i].no and max_card.suit==self.comp_cards[i].suit):
                        self.comp_cards[i].remove_from_sprite_lists()
                        break
                    i+=1
            else:
                for i in range(len(self.comp_cards)):
                        if(max_card.num<self.comp_cards[i].num):
                            max_card=self.comp_cards[i]
                
                m=card(max_card.no,max_card.suit,self.GAME_CONFIG)
                self.shown_deck.append(m)
                i=0
                while(i<len(self.comp_cards)):
                    if(max_card.num==self.comp_cards[i].num and max_card.suit==self.comp_cards[i].suit):
                        self.comp_cards[i].remove_from_sprite_lists()
                        break
                    i+=1

            if(len(self.comp_cards)<=1):
                self.trigger_game_over()
            self.turn='p'