Python Forum
Implementation Pyramid Solitaire
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Implementation Pyramid Solitaire
#1
You must create a class map to represent a playing card in the pyramid.
Create a class deck for submission deck of cards in the pyramid.
Here's the code I wrote, but the teacher said that we should implement this class using design patterns, help please.

import random
 
 
class Card(object):
    def __init__(self):
        self.list = ['в™*', 'в™Ј', '♥', '♦']
        self.cards = []
        self.cart = []
        for card_num in range(0, 52):
            r = str(card_num % 13)
            if r == '0':
                r = 'K'
            if r == '1':
                r = 'A'
            if r == '12':
                r = 'Q'
            if r == '11':
                r = 'J'
            index = int((card_num / 13) % 13)
            self.cards.append((r, self.list[index]))
 
    def draw(self):
        next = self.cards.pop(random.randint(0, len(self.cards) - 1))
        return next
 
    def deck(self):
        c = Card()
        for i in range(0, 52):
            self.cart.append(c.draw())
 
 
        print(30*' ',self.cart[0])
        print(25*' ',self.cart[1:3])
        print(20*' ',self.cart[4:7])
        print(15*' ',self.cart[7:11])
        print(10*' ',self.cart[11:16])
        print(5*' ',self.cart[16:22])
        print(self.cart[23:30])
        print(30 * "---")
        print(self.cart[31:])
 
c = Card()
c.deck()
The deck should be sinhletonom to have accidentally got 5 aces when you do something. There is a deck implement iterator that give the current map. Also, as I understand it, the cards have rozpyhatys pyramid in rows, each row can be created churez factory classes. And the output of each line by designer says teacher but I have not quite mastered the design patterns.
Reply


Messages In This Thread
Implementation Pyramid Solitaire - by qwerty - Feb-27-2017, 11:16 AM
RE: Implementation Pyramid Solitaire - by qwerty - Feb-27-2017, 11:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help with my assignment please - game of Solitaire Muzz 6 6,762 Sep-28-2021, 07:36 PM
Last Post: Underscore
  print a * pyramid drogers10940 5 4,782 Apr-26-2020, 09:25 PM
Last Post: prothej227
  Pyramid of leters of n levels DanyMont1505 4 2,237 Sep-27-2019, 07:56 PM
Last Post: woooee
  Pyramid gamingingrs 1 2,321 Oct-16-2018, 02:56 PM
Last Post: j.crater
  Pyramid of Solitaires qwerty 1 3,511 Mar-22-2017, 04:10 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020