Тёмный

How to Make A Deck of Cards using Python OOP 

TokyoEdtech
Подписаться 47 тыс.
Просмотров 11 тыс.
50% 1

In this video learn how to simulate a deck of playing cards using Python classes and OOP. Then, learn to render the cards using the Python turtle module.
Download the code here: github.com/wyn...
Introduction to OOP: • Intro to Classes and O...
NEED HELP?
🆘 Watch this first and then let me know in the comments below: • Help Me Help You
❤️❤️ SHOW SOME LOVE AND SUPPORT THE CHANNEL ❤️❤️
Click Join and Become a Channel Member Today!
Channel members can get preferential comment replies, early access to new content, members only live streams, and access to my private Discord.
❤️ / @tokyoedtech
LINKS
🗄️ GITHUB: github.com/wyn...
💬 Follow me on Twitter: / tokyoedtech
📜 Subscribe to my Newsletter: eepurl.com/dKgM8k
📝 Check out my Blog: christianthomp...
⬇️ Download Geany Editor: www.geany.org
LEARN MORE PYTHON
➡️Space Invaders: • Python Game Programmin...
➡️Snake Game: • Python Game Programmin...
➡️Pong: • Python Game Programmin...
➡️Space War: • Python Game Programmin...
➡️Intro to Python (for Java Coders): • Intro to Python for Ja...
➡️Space Arena - The Ultimate Python Turtle Graphics Game Tutorial: • Ultimate Python Turtle...
LEARN MORE JAVA
➡️Basic Java for Beginners: • Basic Java 1&2: Commen...
➡️Intro to AP Computer Science A: • AP Computer Science Un...
#Python #PlayingCards #Tutorial

Опубликовано:

 

5 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 44   
@zihaoli9683
@zihaoli9683 2 года назад
Thanks for the video! I'm also here for my OOP. Wish I had found your vids earlier.
@TokyoEdTech
@TokyoEdTech 2 года назад
Better late than never!
@aston.6487
@aston.6487 3 года назад
Hey. Can you make a begginer python series? I am sure many new pyhton coders (like me) will be interested
@TokyoEdTech
@TokyoEdTech 3 года назад
Here ya go: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-rxSyXBq9zq0.html
@aston.6487
@aston.6487 3 года назад
@@TokyoEdTech woah thanks a lot
@lalitkumarswain4382
@lalitkumarswain4382 3 года назад
Thank you so much! Will try it out. You make coding and programming so much fun!
@TokyoEdTech
@TokyoEdTech 3 года назад
Thanks - I try!
@evangoss5673
@evangoss5673 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 года назад
I wish more people saw this ;(
@TokyoEdTech
@TokyoEdTech 3 года назад
Thanks - me too!
@aryanahire2337
@aryanahire2337 3 года назад
@@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 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-JPAyj85tJ5E.html this is all i have, it doesn't go TOO in depth, but it shows how C isn't that complex.
@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!
@hardikxz
@hardikxz 3 года назад
Awesome, Could've added the "click to flip" feature.. coz I'm trying it now!!
@TokyoEdTech
@TokyoEdTech 3 года назад
Good luck!
@teacherinthailan6441
@teacherinthailan6441 3 года назад
Excellent!! Thank you so much once again.
@TokyoEdTech
@TokyoEdTech 3 года назад
No worries!
@026aleenaurooj9
@026aleenaurooj9 3 года назад
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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-qN4tjmVQjXI.html
@mishka5169
@mishka5169 3 года назад
Great video as usual :D
@TokyoEdTech
@TokyoEdTech 3 года назад
Thanks, Mishka!
@mishka5169
@mishka5169 3 года назад
@@TokyoEdTech :)
@Jonathan-xq6dv
@Jonathan-xq6dv 3 года назад
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
@shalomakolatse537
@shalomakolatse537 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.
@gotem370
@gotem370 2 года назад
what color syntax are you using? I like it.
@TokyoEdTech
@TokyoEdTech 2 года назад
Hiya - it is called Bespin.
@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
@ivand58
@ivand58 3 года назад
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 года назад
So, you used random( ) function... 🤔😏✅
@TokyoEdTech
@TokyoEdTech 3 года назад
Randomly, yes!
@SkyFly19853
@SkyFly19853 3 года назад
@@TokyoEdTech I thought so!
@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.
Далее
Simple Python Wordle Game Tutorial for Beginners
22:22
2 YEARS of PYTHON Game Development in 5 Minutes!
4:54
Просмотров 930 тыс.
skibidi toilet multiverse 042 Trailer
01:57
Просмотров 2,8 млн
Python OOP - Deck of Cards
17:14
Просмотров 157 тыс.
Python Game Tutorial: Minesweeper Basic Game Functions
57:55
Faster than Rust and C++: the PERFECT hash table
33:52
Просмотров 577 тыс.
Python Game Programming Tutorial: Space Invaders 1
8:20
Pygame in 90 Minutes - For Beginners
1:35:22
Просмотров 1,1 млн
C++ vs Rust: which is faster?
21:15
Просмотров 397 тыс.
Genetic Algorithms Explained By Example
11:52
Просмотров 330 тыс.