Examples

This is an extremely dumb question and I apologize in advance…But where can I find examples of games and source code? Back in the day, when I was playing around with Visual Basic and some of the older languages, I could always go on planetsourcecode.com and see examples of how people have done things and I learned pretty quickly…I’ve found a few examples on the wiki but only a few games and nothing that even pertained to what i’m doing.

I’m having trouble figuring out how to organize my classes, what to make each class do, etc. For instance, for my 2d tiled game, I have a Map class which loads and renders the map…Sometimes I look at the code and think it may need to be split up, but am not really sure. Sometimes I have trouble making the classes work together. I hope I explained this correctly as i’m having trouble finding the words to explain what i’m asking lol. I’m new to Java, but I have read through a java book and I feel pretty comfortable with the code itself…It’s just placement and putting it into action.

So basically, is there anything like planetsourcecode for us that I can see projects and see how they did things?

Look for tutorials on youtube done by the newboston, MrJavaHelp and Vanzeebans. I recomend THECHERNOPROJECT

I’ve watched a few of those already. They’re good tutorials and all, I would just rather play around with the code. I get bored with the videos too quickly. I watched dermetfans. Those were my favorite so far.

Don’t watch newboston. He teaches you bad coding practices.

theNewBoston is actually pretty good for learning about something specific, don’t discount him just because of some of his coding styles. theChernoProject is essentially a huge copy cat, taking his code from a famous person notch, and even admits it. Sure, the code is good. But the fact that he copies just ruins the entire experience. Vanzeebans is also… ok, but his coding style is bad.

Yeah, I just criticised every YouTuber you named…

java4k don’t have source code?
If not, you could check some simple games made for java4k contest and try to make one rip-off.
You will learn a lot.

Java4k isn’t exactly for people who want to learn “regular” game programming. Its more for learning how to minimize your game, but still have the maximum amount of fun and “coolness”.

A little bit off topic, but if you haven’t checked out Derek Banas yet, you should definitely do it, like right now. He’s got an enormous library of high quality videos, and he teaches really well.

Okay. First of all, ignore all the previous advice.

  • Java4K code is heavily obfuscated. Reading the code will teach you how to do everything the wrong way. It is wrote in an anti object orientated manner using an object orientated language. Learning the coding practices used in Java4K is the most idiotic thing you could do.
  • Youtubers seem to have little understanding of good coding practices. Most of them teach as they learn and they litter their videos with mistakes and bad practices.

Don’t look at other peoples code. Honestly, it’s not what you should do. Instead, don’t worry too much about whether you’re code is written badly. The first step is to learn how to write code - the second step is to learn how to write it well. You’ll get better by just practising; only when you’re confident that you’ve got a good understanding of the language should you review your code and try to improve it. When you’re at the stage of trying to improve your code, remember to ask yourself these questions:

  • Is it written in an object orientated manner?
  • Is it easy to debug?
  • Can you read it?

If the answer to those three questions is yes, then you’re doing well. However, here’s a few things to look out for:

  • Type safety; type safe code is well written code. Never forget that.
  • Code reuse; try to maximise code reuse, though don’t overdo it. If you overdo it then code can become hard to read.
  • Composition over inheritance; only use polymorphism where necessary. Abusing inheritance can make code messy.

A couple of points to note:

  • Enums are type-safe. Prefer them over constants when there is a certain range of possible values.
  • Don’t focus on using certain design patterns. Instead, think about how you should structure your code and structure it how you want to do so.

TLDL: Start by learning how to write code, then learn how to write it well. Learn by practising, not by reading.

@Troubleshoots I’ll have to partly disagree with you here. While I also think copy & paste learning is bad, it doesn’t mean that these “youtubers” forces you to do it or that all of them have bad practices. All my programming knowledge comes from people like Derek, who describe what things are and do. I then, after the video/article, go through and see what I learned. Thereafter I play with the code to understand even more.

Reading and getting a grasp of information is always (in my terms) the first step to learn something new. The next step, as you say, is practicing and using that knowledge.

Looking at others’ code is actually a nice way to learn, I don’t know what you’re talking about. Copying and pasting isn’t good, but looking and learning is always a good way to see how things work. By your logic, we shouldn’t look at tutorials that have code in them. How are people supposed to learn then? Don’t copy and paste and you’ll be fine. Implement it in your code in your own way, and you’ll learn a lot about code design and how code works together.

You have to read sometimes, just writing code won’t get you anywhere. This is why we have huge books that fill hundreds of pages with documentation. Are you going to discount all those books that successful developers use everyday?

Of course, everyone has their own way of learning. I like an even balance of coding and reading documentation. You have to realize some people learn differently, and what works for you will not necessarily work for everyone else.

Also, don’t tell the OP to ignore our advice please. Many of us have been programming for longer than you, and we know more about what works and what doesn’t and how to advise newbies. It’s offensive when someone discounts this.