Hey, my names saline and I'm here to cause problems. Well kind of. This is a new section where each week I'm going to provide a programming problem and then new coders (codenewbies if you will) can get some practice thinking like computer scientists. Then people can ask each other questions and share code snippets and learn how to solve programming problems on their own. It’ll be a big party, a big coding party, trust me they‘re fun.
The problems will probably be limited to the following languages: C++, JavaScript, Perl, Visual Basic and Python because for now, that's all I know. Then through the week people can work on it and ask me and each other questions and who knows where it will all end up?
Anyway, for the first week we're going to draw from the forums for inspiration. Specifically this thread:
http://codenewbie.com/forum/showthre...=&threadid=708
Here's the quick story, toAst, is a newbie but he wants to get going doing something. He wants to make a game, something simple like Pong. That's the first part of our problem of the week. If you think you're up to it, make Pong. Maybe make it like the classic Atari game which you can read all about here
http://www.pong-story.com/ or something updated with fancy futuristic things like, um, color.
OK, so I responded in the forums because I've seen the pitfalls (bad old game pun) of people saying pong was simple. It's simplistic and simple compared to now adays, or really anything, however, it's not easy.
Things to consider about pong
1) How are you going to do the graphics? If you don't know how to do graphics in your language(s) it might make things too hard. I've seen pong done as ASCII art but that's something I would consider a rare skill.
2) How are you going to control the computer opponent (if there is one). Are you going to be able to make it good but not too good so that it doesn't always win? If there is no computer opponent you need to set up dual controls somehow.
3) At the very basic level, can you make the "ball" bounce correctly and detect when a point is scored?
If one of these questions gives you pause you might still try and be successful however if more than one seems puzzling you might want to consider the second or third problem and working your way up.
If you choose to do this problem I would recommend C++, Java (or so I'm told in the forum), Python (with pygame), Visual Basic and maybe JavaScript if you like a real challenge. Other languages will work but I can't gauge how difficult it would be as I haven't done graphics in them.
The second part incorporates graphics but they don't move so it avoids a number of the difficulties of Pong.
The "match game" also known as "memory" or "where the hell is it?!" is a classic intro programming game. If you have a Nokia cell phone you can play the match game right now, they call it pairs.
The rules are simple there are cards which are face down. Every card has a picture on it's face down side and there are two of every card picture type. You click on one and get to see its picture. The goal is to find the match for each pair with as few guesses as possible.
Here is an example where you play alone:
http://www.funbrain.com/match/
(I'd like to say that the way they implemented this is kind of ridiculous and I would not recommend it, there are easier ways which look better than this. It's just an example of how the game works.)
And here's a cool variation where you play against the computer:
http://jimworld.com/memory/memory.html
Anyway you get the idea, here are things to consider about doing the match game:
1) Again, can you do graphics, and do you know how to change those graphics from one picture (the back) to another (the front) when the user chooses them?
2) Can you make sure the user doesn't choose the same pair twice, once it's found it should go away somehow?
3) How will you keep score, and how will the user interact with the game board?
If these give you pause you might want to consider the final problem for this week which is geared toward the newest of the coders the few the proud the n00b!
The guessing game.
The guessing game is one of the first things people learn it's got a lot of absolutely fundamental concepts within it. It's a challenge but they're surmountable. It doesn't require graphics so this is a big drop in the difficulty.
It's just a simple guessing game, the computer chooses a number (or a letter but that's a tad more difficult) and the user guesses. Generally the number should be constrained within some reasonable range like 0-20 or something. If you want to get all fancy like you can tell the user whether their guess was too high or too low. Then when they get it just tell them so. Maybe you can keep track of a score or number of guesses versus number of correct answers, kind of like a hit ratio (like counterstrike, only less violent and a guessing game).
This is a basic problem and so you should know or research the following things
1) Getting text input from the user and printing information back to them.
2) "If" statements and the comparison operators (==, >, >=, <, <=).
3) Loops and looping.
4) Generating random numbers.
If you don't think you can do those things you'll probably be able to research them or ask questions about them and still have enough time to get it done. These concepts are the absolute basis of all programming in all languages so even if you don't think you can finish the problem you should try it to get the experience.
So, that's it for this week, good luck to everyone who tries and feel free to ask each other and me questions within the forum. As a final note remember to drink your vegetables, eat all your milk, drugs know best and don't do moms. Or something.