Sign in to follow this  
DZee

Wrote First Game[SDL/C++] - Feedback

Recommended Posts

Hey guys, some colleague of mine asked me to learn SDL. So yesterday I went and skimmed the API along with one or two tutorials. I figured I'd start slow so I wrote this Tic Tac Toe game.

I wouldn't mind any kind of feedback either on the code or the game, anything is appreciated. It's written in C++. I was cut short because of a work project(Income!!!) so I didn't implement any proper AI unfortunately. Took around 8 hours, I had forgotten a lot of things about C++ since most of my experience comes from Java Swing(Eww). Everything is from my mind, my pencil and a blank sheet of paper. Didn't want to inspire myself from any of the popular methods for finding the winner, I will take a peek into the AI algorithm just for my personal culture though.


Expect to see more interesting games coming along with each step I take. I'm probably going to make a <game of life> type just because I'm curious and then probably a poker game(I wrote an engine in Java a year ago), then probably step away from turned based games and go on to make the best game in the world[img]http://public.gamedev.net//public/style_emoticons/default/ph34r.png[/img] .


Worst case scenario this might help someone or inspire people.


Have fun.

---
Oh I forgot, my laptop is in repair so I had to use the dreaded Visual Studio so I can't offer any makefiles for Unix

-----
Oh yeah and, I haven't tried multiple grid sizes. There's no loop to construct the frame initially so that would have to be done manually... my fault [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by DZee

Share this post


Link to post
Share on other sites
The dreaded Visual Studio? Visual Studio is dreaded? Why? (Well, okay, I guess the C++11 support is somewhat lacking...)

After spending a couple minutes looking, I found a couple of odd things:
1) People still use RAR files?
2) Of the files Visual Studio generates, the only files vital to building the project are the .sln and .vcproj. The rest -- .sdf, the intellisense database; .suo, the solution options (??); the .vcxproj.user -- aren't needed, should be deleted.
3) Do not distribute the Debug versions of your executable. The debug versions of the C runtime library are intended for development only, not for deployment.
4) Multiple copies of the res directory?
5) (Nitpick) Your vcproj assumes I have SDL installed in C:\SDL-1.2.5 -- I actually have it installed in C:\bin\sdk\SDL\1.2.5. It doesn't really matter as long as your project links to an SDL.lib, and I have properly set up the appropriate directory.

I'll take a much thorough look inside your project later...

Share this post


Link to post
Share on other sites
IMO, I would replace
[source lang="cpp"] buttons[0] = new Button(0, 0, 200, 200, tileClips[Empty]);
buttons[1] = new Button(200, 0, 200, 200, tileClips[Empty]);
buttons[2] = new Button(400, 0, 200, 200, tileClips[Empty]);
buttons[3] = new Button(0, 200, 200, 200, tileClips[Empty]);
buttons[4] = new Button(200, 200, 200, 200, tileClips[Empty]);
buttons[5] = new Button(400, 200, 200, 200, tileClips[Empty]);
buttons[6] = new Button(0, 400, 200, 200, tileClips[Empty]);
buttons[7] = new Button(200, 400, 200, 200, tileClips[Empty]);
buttons[8] = new Button(400, 400, 200, 200, tileClips[Empty]);[/source]
with something along the lines of
[source lang="cpp"] const int BOARD_W = 3; // in tiles
const int BOARD_H = 3;
const int BUTTON_W = 200; // in pixels
const int BUTTON_H = 200;

int i = 0;
int j = 0;

for(i = 0 ; i < BOARD_H ; i++)
{
for(j = 0 ; j < BOARD_W ; j++)
{
buttons[i*BOARD_H + j] = new Button(i*BUTTON_H, j*BUTTON_W, BUTTON_H, BUTTON_W);
}
}[/source]

because this avoids some repetition and also allows you to change the board size easily, if you wanted to add an option for a 4x4 game, or if you want to change the tile size easily for changing screen resolution, using different graphics etc. Edited by arrrgh

Share this post


Link to post
Share on other sites
[quote name='fastcall22' timestamp='1341376826' post='4955515']
People still use RAR files?
[/quote]
I do.. what's wrong with rar files? =P Rather use that than zip.. JAR, now that's a legacy format. Haven't seen that in years and years
Moving on..

[quote name='fastcall22' timestamp='1341376826' post='4955515']
Your vcproj assumes I have SDL installed in C:\SDL-1.2.5 -- I actually have it installed in C:\bin\sdk\SDL\1.2.5. It doesn't really matter as long as your project links to an SDL.lib, and I have properly set up the appropriate directory.
[/quote]
How [i]do[/i] you set up the appropriate directory? I've never found a good standard way for looking up libraries depending on the user. I always get frustrated with msdn. It's worked for me so far, because I mostly handle my development alone.

Share this post


Link to post
Share on other sites
[quote name='Zoomulator' timestamp='1341393598' post='4955573']what's wrong with rar files? =P Rather use that than zip..[/quote]
WinRAR is what's wrong with RAR files. I find [url=http://7-zip.org]7-zip[/url] as a much superior (and free) alternative.

[quote name='Zoomulator' timestamp='1341393598' post='4955573']How [i]do[/i] you set up the appropriate directory?[/quote]
You can only setup the appropriate directory for your own machine. Anywhere else and you'll need to either trust the user has the appropriate directory setup or distribute the libraries with your project and use those.

Visual Studio's property sheets are a step forward, in my opinion. These allow you to change your project properties in layers. If you were to create and include in your project two property sheets, "SDL_1.2.5-debug" and "SDL_1.2.5-release", that add your SDL's include/library directories, and then distribute your project without those property sheets (remember, they reference directories in your harddrive), then the developer (once presented with an error message or reading your readme.txt) on the other side will substitute his own versions of those property sheets so that your project will point to his SDL directory.

Share this post


Link to post
Share on other sites
[quote name='fastcall22' timestamp='1341376826' post='4955515']
The dreaded Visual Studio? Visual Studio is dreaded? Why? (Well, okay, I guess the C++11 support is somewhat lacking...)

After spending a couple minutes looking, I found a couple of odd things:
1) People still use RAR files?
2) Of the files Visual Studio generates, the only files vital to building the project are the .sln and .vcproj. The rest -- .sdf, the intellisense database; .suo, the solution options (??); the .vcxproj.user -- aren't needed, should be deleted.
3) Do not distribute the Debug versions of your executable. The debug versions of the C runtime library are intended for development only, not for deployment.
4) Multiple copies of the res directory?
5) (Nitpick) Your vcproj assumes I have SDL installed in C:\SDL-1.2.5 -- I actually have it installed in C:\bin\sdk\SDL\1.2.5. It doesn't really matter as long as your project links to an SDL.lib, and I have properly set up the appropriate directory.

I'll take a much thorough look inside your project later...
[/quote]

Dreaded because I do not like how VS handles properties for different projects. Give me makefiles any time of the day. Perhaps I am just used to the Unix way of dealing with these. I do use VS at most places I work though.

1)
Well yes it's true that I did some tests at some point in time and Zip files were superior in pretty much every category against rar files. I guess I'm used to WinRar. I would have tarred it if I was on Unix.

2),3)
You are right, sorry about that I was lazy.

4)
Essentially the res directory was unique, but I copied it in the .exe for a quick run for anyone who was interesting in trying it out. I think I left the .bmp too for no reason. Packaging again, my fault [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

5)
I normally use environment variables(Such as creating SDL_DIR="path"), It would have fixed your problem per se, but it would have facilitated the integration.



@arrgh, yes indeed, I mentioned the loop earlier my fault, thanks for pointing out it's importance.

---
Thanks for the input. Edited by DZee

Share this post


Link to post
Share on other sites
[quote name='fastcall22' timestamp='1341376826' post='4955515']
The dreaded Visual Studio? Visual Studio is dreaded? Why? (Well, okay, I guess the C++11 support is somewhat lacking...)

After spending a couple minutes looking, I found a couple of odd things:
1) People still use RAR files?
2) Of the files Visual Studio generates, the only files vital to building the project are the .sln and .vcproj. The rest -- .sdf, the intellisense database; .suo, the solution options (??); the .vcxproj.user -- aren't needed, should be deleted.
3) Do not distribute the Debug versions of your executable. The debug versions of the C runtime library are intended for development only, not for deployment.
4) Multiple copies of the res directory?
5) (Nitpick) Your vcproj assumes I have SDL installed in C:\SDL-1.2.5 -- I actually have it installed in C:\bin\sdk\SDL\1.2.5. It doesn't really matter as long as your project links to an SDL.lib, and I have properly set up the appropriate directory.

I'll take a much thorough look inside your project later...
[/quote]

All of your arguments are nitpicks. Seriously, your 1st criticism's is he used rar for compression.

There are some valid criticism's, but your's, especially about how he distributed the code, are unwarranted.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this