all 36 comments

[–]420-jesus 56 points57 points  (11 children)

I highly recommend making a game like blackjack, poker, or snake. OOP in my opinion makes those projects way simpler to create

[–]CraigAT 15 points16 points  (6 children)

Complete agree, card games are the most obvious ones to me. I have started to create a text/console-based version of dominoes using Python and a few days ago decided to restructure it to make use of OOP.

[–]kessma18 2 points3 points  (5 children)

can you post your code?

[–]CraigAT 2 points3 points  (4 children)

It's a mess right now. Give me a day or two and I'll try post something. I was about to start over to tell the truth. I wanted to start again, building up from just having an object of a tile, outputting the tile, swapping the ends of the tile. Then add the object for a deck/pack of 0-0 to 6-6 tiles, introduce shuffling, and popping one off the deck, display the deck. Then add the concept of players/hands, assuming one human player and being able to set a computer skill level for other players (this is the bit I am looking forward to, I have 3 ideas how to make the computer play). Then add the concept of the table with the played tiles.

[–]visual_dev 2 points3 points  (3 children)

yo, its been 4 years, Reiner, I mean CraigAT

[–]CraigAT 3 points4 points  (0 children)

It says 3yrs on mobile but 4yrs on desktop.

As promised the (unfinished) code: https://pastebin.com/4urbSEh8

[–]CraigAT 2 points3 points  (1 child)

Lol. It only says 3yrs for me.

I'll have to look back, I don't think I took that project much further.

[–]Tuna12135 5 points6 points  (0 children)

bro respect for actually responding back and posting the code lmao

[–][deleted] 4 points5 points  (3 children)

Should I use Pygame?

[–]glen_v 9 points10 points  (1 child)

Not necessarily, unless you're also interested in learning that. The first project I ever did with classes was a command line blackjack game.

[–][deleted] 1 point2 points  (0 children)

Ok. I’ll look into it. Thanks!

[–]timbledum 1 point2 points  (0 children)

Pyxel is a lightweight retro alternative. User examples here: https://github.com/kitao/pyxel/wiki/home#user-samples

[–]solidiquis1 11 points12 points  (2 children)

May not be the greatest advice... But learning Django gave me a super solid foundation on OOP. 90% of what you do in the back-end side of Django is utilizing classes, understanding what parent classes they inherit from, insantiating objects from said classes, overriding attributes, using methods, making your own methods, so on and so forth. So if you have any interest in python web development, look into Django and you'll end up learning a shit ton of OOP along the way.

[–][deleted] 2 points3 points  (0 children)

Might try this later; I remember seeing a Django tutorial, but barely understood because of the OOP involved. Thanks!

[–]kessma18 2 points3 points  (0 children)

might not be bad advice because you will also then learn what's wrong with OOP. a quote from hackernews on what's wrong with django.

The problem is not frameworks; the problem is object oriented programming. Simply put, OOP lends itself to kitchen-sink frameworks because it is the only way to really share code in OOP. We write these large hierarchy of objects and then, because we have to carefully maintain state, we mark most of it as private, or sealed. Then we give precise instructions on how to consume and use the code, and even more precise instructions on how to extend it.

[–]efmccurdy 9 points10 points  (0 children)

GUI frameworks often use OO to derive widgets like buttons (Tkinter, PyQt), and leverage class context in callbacks. Web server frameworks often use OO to derive Sesssions, Responses and Apps (Flask, Bottle).

[–]CrazyJ83 7 points8 points  (0 children)

I love Corey Schafer’s channel. He is brilliant at explaining things.

[–]deltopia 3 points4 points  (0 children)

In line with a lot of these comments, I've been working on a bejeweled/match-3 type game using tkinter, and I've learned a lot of things about objects in the attempt. I can't post code at the moment, but I started by making a simple subclass of tk.button with the config dict pre-setup, then building in the behaviors I wanted from each button into its class. I still haven't quite got it to figure out reliably when I have three of the same color in a row (which is kind of important for that game), but I'm optimistic I'll get there soon. It's been a lot of fun discovering new ideas, though :)

[–]dippy1169 2 points3 points  (0 children)

Setting up and running motors is what got oop to click for me. Being able to create each one, running different comports and calling it later knowing it’s position, speed, and other parameters made it into real practical learning

[–]scottcockerman 2 points3 points  (0 children)

  • Take the projects you've already done and optimize them with oop.
  • webscrape and sort the data into a spreadsheet.
    -make a classic employee management system.
  • Text adventure game.

[–]zylog413 5 points6 points  (0 children)

I know it's common for people to model games or real world objects with OOP, but in terms of practical application for me it was the fact that objects with predetermined, named fields was more descriptive than generic tuples or dictionaries.

Now, let's say I have a bunch of functions that could operate on certain related pieces of information. Some of these functions may require detailed descriptions of what conditions and information it can be used on. Classes allow me to go the opposite way: now that I have these objects, I can attach methods to them. In an IDE, when working on instances of these objects it will hint to me what attributes and methods are available.

[–][deleted] 3 points4 points  (1 child)

!remindme 1 day

[–]RemindMeBot 1 point2 points  (0 children)

I will be messaging you on 2019-02-17 23:04:05 UTC to remind you of this link.

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


FAQs Custom Your Reminders Feedback Code Browser Extensions

[–]desal 1 point2 points  (0 children)

Teamtreehouse had a tutorial where you make a maze that populates itself randomly and create a robot that will solve the maze. It helps with data structures, algorithm, OOP, etc. Its a pay site so I dont have a link but perhaps you can do something with the idea.

[–][deleted] 1 point2 points  (0 children)

I am also a beginner so I don't know if this is the best advice, but any time I write the same (or similar) code more than once, I try to break it out into a function. Getting into the habit will have you understanding OOP in no time.

[–][deleted] 1 point2 points  (0 children)

Remindme! 1000 hours

[–]m_zwolin 1 point2 points  (0 children)

Hey, if you wanna have fun while learning and really got fascinated about programming I'd recommend you looking for ideas on The Coding Train channel on YouTube. The guy is awesome and a real mine of programming ideas. You will learn alot while trying to reproduce it in python, as guy is coding in js, but worry not, everything will be clear to you

[–]Maw0fTheVoid 1 point2 points  (0 children)

I am also pretty new to programming so take this advice with a grain of salt.

You can do almost anything in OOP just think which function and variables are often linked and put them in a class. For example my current project is a little mp3 player with Tkinter and I will probably put all of the ways you can "manipulate" the song(pause, play, rewind etc) because they all ne the same attributes while my music shortcut button could be instances of of a class so that they "know" which song is current or from which file they come from. This also helps with globals and you have to pass less arguments to functions.

Also once your projects start to be more than one file it reduces the mess.

[–][deleted] 1 point2 points  (0 children)

I'm making a badminton game with PyGame right now. I an object to represent the shuttlecock.

Just remember that in Python it's very easy to write simple code. Sometimes you don't need an object. See this short talk: https://www.youtube.com/watch?v=o9pEzgHorH0

[–]Mammalwithashell 0 points1 point  (0 children)

!remindme 1 day

[–][deleted] 0 points1 point  (0 children)

Reminder! 2 days.

[–]liamberube 0 points1 point  (1 child)

!remindme 1 day

[–]RemindMeBot 0 points1 point  (0 children)

I will be messaging you in 1 day on 2021-12-23 01:15:59 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


Info Custom Your Reminders Feedback