How to Make A Deck of Cards using Python OOP

Поделиться
HTML-код
  • Опубликовано: 16 ноя 2024

Комментарии • 44

  • @aston.6487
    @aston.6487 3 года назад +4

    Hey. Can you make a begginer python series? I am sure many new pyhton coders (like me) will be interested

    • @TokyoEdTech
      @TokyoEdTech  3 года назад +2

      Here ya go: ruclips.net/video/rxSyXBq9zq0/видео.html

    • @aston.6487
      @aston.6487 3 года назад +2

      @@TokyoEdTech woah thanks a lot

  • @zihaoli9683
    @zihaoli9683 2 года назад +2

    Thanks for the video! I'm also here for my OOP. Wish I had found your vids earlier.

  • @lalitkumarswain4382
    @lalitkumarswain4382 3 года назад +1

    Thank you so much! Will try it out. You make coding and programming so much fun!

  • @evangoss5673
    @evangoss5673 2 года назад +2

    This was such a great video . Really helped me with my OOP.

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      Thanks - glad to hear it! Keep on codin'!

  • @aryanahire2337
    @aryanahire2337 3 года назад +3

    I wish more people saw this ;(

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Thanks - me too!

    • @aryanahire2337
      @aryanahire2337 3 года назад +1

      @@TokyoEdTech Love your vids dude. Not 100% sure if you know C but it would be cool if you made a series on something lower level (C/C++). Because I use C to make games and its actually way simpler than most people think it is (with SDL at least its simple).

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      @@aryanahire2337 Thanks! I'm not very good at C. It's cool you can use SDL to make games with C.. Do you have any recommended resources?

    • @aryanahire2337
      @aryanahire2337 3 года назад

      @@TokyoEdTech ruclips.net/video/JPAyj85tJ5E/видео.html this is all i have, it doesn't go TOO in depth, but it shows how C isn't that complex.

  • @hardikxz
    @hardikxz 3 года назад

    Awesome, Could've added the "click to flip" feature.. coz I'm trying it now!!

  • @veraprohaska8801
    @veraprohaska8801 3 года назад

    Love the video, also the existential moment of reflecting life at 18:13 dw theres always a next time:)

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Thanks - good to reflect before it is too late!

  • @026aleenaurooj9
    @026aleenaurooj9 3 года назад +1

    I have a problem but it is not related to this video, i wan'na ask how can i move my character move upward. Can you please tell me with a simplest code, btw great videos. :)

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      I have a series of videos on object motion - they should answer your question: ruclips.net/video/qN4tjmVQjXI/видео.html

  • @mishka5169
    @mishka5169 3 года назад +1

    Great video as usual :D

  • @Jonathan-xq6dv
    @Jonathan-xq6dv 3 года назад +1

    Hi, I dont know if you will respond but my cards, in the end, does align in a row, but the top left and bottom right symbol and numbers stacks onto of each other on the middle card. It also clears in the middle when It usually reaches the middle card out of the 5. Any ideas?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Hiya, I'd need to see the code to be able to help.

    • @Jonathan-xq6dv
      @Jonathan-xq6dv 3 года назад

      @@TokyoEdTech I really appreciate the help, thankyou.
      import turtle
      import time
      import random
      wn = turtle.Screen()
      wn.bgcolor('black')
      wn.setup(600,600)
      wn.title("Deck of cards")
      pen = turtle.Turtle()
      #pen.speed(0.5)
      pen.hideturtle()
      #Create classes
      class Card():
      def __init__(self, name, suit):
      self.name = name
      self.suit = suit
      self.symbols = {'D':'♦','C':'♣','H':'♥','S':'♠'}

      def print_card(self):
      print(f"{self.name}{self.symbols[self.suit]}")

      #Border
      def rendering(self, x, y, pen):
      #DRAW BORDER
      pen.penup()
      pen.goto(x, y)
      pen.color('blue')
      pen.goto(x- 50, y +75)
      pen.begin_fill()
      pen.pendown()
      pen.goto(x +50, y+75) # I fixed the attribute error but indenting the def print_card and makeing the card.print_card lower
      pen.goto(x+50, y-75)
      pen.goto(x-50, y-75)
      pen.goto(x-50, y +75)
      pen.penup()
      pen.end_fill()
      #Draw suit in mid
      pen.color('white')
      pen.goto(x-18, y-30)
      pen.write(self.symbols[self.suit], False, font=("Courrier New", 48 , 'normal'))
      #Draw top left number
      pen.goto(-40, y+40)
      pen.write(self.name, False, font=("Courrier New", 18 , 'normal'))
      pen.goto(-40, y+22)
      pen.write(self.symbols[self.suit], False, font=("Courrier New", 18 , 'normal'))
      #Draw bottom right number
      pen.goto(+30, y-55)
      pen.write(self.name, False, font=("Courrier New", 18 , 'normal'))
      pen.goto(+30, y-75)
      pen.write(self.symbols[self.suit], False, font=("Courrier New", 18 , 'normal'))


      #prints the A thing in terminal and is interchangable to the actual card
      #card = Card('A','S')
      #card.print_card()
      #card.rendering(0, 0, pen)
      class Deck():
      def __init__(self):
      self.cards = []
      names = ('A', 'K', 'Q', 'J', 'T', "9", '8', '7', '6', '5', '4', '3', '2')
      suits = ('D', 'C', 'H', 'S')
      for name in names:
      for suit in suits:
      card = Card(name, suit)
      self.cards.append(card)
      def reset_cards(self):
      self.cards = []
      names = ('A', 'K', 'Q', 'J', 'T', "9", '8', '7', '6', '5', '4', '3', '2')
      suits = ('D', 'C', 'H', 'S')
      for name in names:
      for suit in suits:
      card = Card(name, suit)
      self.cards.append(card)
      self.shuffle()
      #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
      def shuffle(self):
      random.shuffle(self.cards)
      def get_card(self):
      card = self.cards.pop()
      return card
      #Create deck
      deck = Deck() #pop a card off
      #Shuffle deck
      deck.shuffle()
      start_x = -250
      for x in range(5):
      card = deck.get_card()
      card.rendering(start_x + x * 125, 0, pen)
      #time.sleep(0)
      #pen.clear()
      #Render 10 cards in a row
      wn.mainloop()
      #for card in deck.cards:
      #card.print_card()
      #card.rendering(0, 0, pen)
      Since I couldn't figure out why this was happening, I worked ahead a bit, so that's why theres the def reset_cards.
      Sorry for not sending the code earlier

  • @teacherinthailan6441
    @teacherinthailan6441 3 года назад

    Excellent!! Thank you so much once again.

  • @jimrakel418
    @jimrakel418 3 года назад

    Enjoy your video except I have one problem. When I run the program, instead of the spade symbol, it prints out "\u2660". I have spent hours comparing your code to what I typed and it is all the same. What could be the problem? Thanks.

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      That's odd. My best guess is that whatever font you are using doesn't have the symbol for some reason..

    • @WinWinStudio
      @WinWinStudio 3 года назад

      @@TokyoEdTech i'm not gonna make it without errors

  • @gotem370
    @gotem370 2 года назад

    what color syntax are you using? I like it.

    • @TokyoEdTech
      @TokyoEdTech  2 года назад +1

      Hiya - it is called Bespin.

  • @peaceheis
    @peaceheis 3 года назад

    5:19 are you aware of __repr__ as a way to allow you to simply call print() with any object? thats the more “pythonic” way, and I’d say it looks better...

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Yep. Thanks for the suggestion. I don't use it with my students though.

  • @ivand58
    @ivand58 3 года назад +1

    what about pen.forward() and pen.right() instead of pen.goto() ? For me they look more natural.

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      If that's what works best for you, then go for it. However, I think you'll find that using goto will make it easier to port this to a different rendering system such as pygame.

  • @SkyFly19853
    @SkyFly19853 3 года назад +1

    So, you used random( ) function... 🤔😏✅

  • @muhammadmaaz1828
    @muhammadmaaz1828 3 года назад

    Can u make ludo game

    • @muhammadmaaz1828
      @muhammadmaaz1828 3 года назад

      Multiplayer ludo gamr

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Probably not, although I do want to make a board game someday.