25 Replies - 18536 Views - Last Post: 18 August 2010 - 07:24 PM

Week #24: Game Programming

Posted 28 June 2010 - 06:47 AM

GAME PROGRAMMING

CHALLENGE: Try writing a computer game!

A fascinating aspect of programming is game program. Game programming has come a long way from where it began. Games can take many forms. From simple text based games to large 3D worlds for the player to explore. The good thing about game programming is you are not tied to one language. You can write games in any programming language! If you understand a programming language, you can write some sort of game. A basic number guessing game or a top down 2D space shooter are in the realm of possibilites. You aren't even limited to desktop games, you can create browser based games as well.

Ideas:

Number guessing game

Rock, Paper, Scissors

Tic-Tac-Toe (human versus human or for a harder challenge against an intelligent computer opponent)

Tetris style game

Board game

Interactive fiction

Card games

Getting Started:
Getting started depends on your language of choice and the game you are going to try and make. For a console game, ie text based, all you need is a compiler or interpreter for your language of choice. For a graphical game you would be best to use an API, SDK, or framework.

Re: Week #24: Game Programming

Posted 28 June 2010 - 10:55 AM

There is a Tic Tac Toe GUI application that I've written in managed C++, using Windows Forms. It may not be the best, but I did it in no time. The GUI elements are pretty basic. This is how it looks like (yes, my GUI skills are bad):
So, as you can see, it also includes a Hard mode button, that enables better computer AI.

The source is included in TicTacSrc.zip. It has about 600 lines, so I couldn't post it directly, since the page load would be slow. In order to build the application using that source code that I've provided, you have to create a CLI Windows Form, and add nine buttons and one checkbox. It could take some time, and not everyone knows how to do that, so I've decided to post the executable too. You need to have .NET Framework 3.5 installed in order to run it. There is the virus scan of the executable:

Re: Week #24: Game Programming

Posted 28 June 2010 - 07:18 PM

Here's something I whipped up. It's an evolution of the traditional game, Pong.

You are the entity at the top, and you are trying to bounce the ball into one of the two goals at the bottom corners. At the same time, your opponent is trying to get the ball in the top two corners. You move by clicking or holding the mouse on your desired location.

The game goes until 10 points are scored.

Requires Python 2.x and the corresponding version of PyGame. If you are installing python for the first time, get the 32-bit version of 2.6 or lower, as that is all PyGame supports!

Re: Week #24: Game Programming

Posted 29 June 2010 - 07:49 AM

OoH! Well, I have a simple game of Pong written in the form of a Java Applet. I don't have a web page up, but I do have a zip for everyone. Basically, you just try to last until the computer scores 10 points, then it shows you your time that you lasted. Open the html doc to play. One thing I'm gonna get to eventually is make the ball bounce at different angles than 45 degrees, I just haven't gotten to it yet

Re: Week #24: Game Programming

Thanks, I was only posting on resource I knew about. I've yet to start programming with Java other than some simple text programs. I do believe, SDL will work with Java.

I didn't know about that. I'll have to see. The cool thing about Java is that it has a massive built in standard Graphics library. java.awt.Graphics and java.awt.Graphics2D allow for 2D games. For 3D games, one can look at the other library Graphics3D and potentially at JOGL (Java OpenGL) once it matures a bit more.

Re: Week #24: Game Programming

Here is a little command line number guessing game that I wrote. Note that very nearly 1/3 of the code lines are devoted to just making sure the user didn't input something stupid.

So obviously I would prefer you to try the program before reading this

Spoiler

Actually it's not a number guessing game at all. The program never even thinks of the number you are supposedly guessing.

What it actually does is just store up all the sequences of digits the user inputs, never converting them to binary values. If the user is tenacious enough to try 42 guesses then it selects your 42nd guess as the "correct answer". Otherwise if the user gives up it uses normal rules of addition to add up all the guesses and adds 1 to create the number it had "thought of".

Most of the time it will tell you that the number it is thinking of is higher than the guess but if the user happens to input exactly 903 digits in total then it will tell them that the number it is thinking of is lower.

It counts the number of non-digit characters in the string token using the standard function template<typename _CharT> bool std::isdigit(_CharT, const locale&); and the algorith std::count_if.

However std::count_if expects a unary predicate but std::isdigit is just a function that takes 2 parameters and returns true if the character is a digit. It uses std::ptr_fun to convert the function to a binary predicate, then uses std:bind2nd to convert the binary predicate to a unary predicate by binding a value to the second parameter and finally uses std::not1 to invert the sense of the test to count not digit istead of is digit.

Re: Week #24: Game Programming

Posted 03 July 2010 - 11:30 AM

I also made a version of Pong, though in XNA. I did it for a tutorial to explain the basic idea behind bounding box collision detection in 2D. It is part of series of collision detection tutorials that I'm planning on writing. XNA Pong

Re: Week #24: Game Programming

Posted 04 July 2010 - 02:20 AM

I'd post what I have so far of a card game I started in XNA not too long ago but, considering its something I'm doing anyway and I'm not really doing anything new, think it kind of defeates the point of the challenge. Going to check out OpenGL tomorrow (err.. well, its 5am so technically today) and see if I can't knock off both that and the C++ challenge as well.