• Advertisement

# My First Time

This topic is 2770 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I just finished my first complete project with C++ and even though it seems a bit unrealistic to expect anyone to take the time to look through the source critically...I would greatly appreciate anyone if they did.

I've also included an executable.
This is, as you can see, a Tetris clone as per the main site's suggestion, and my code was heavily influenced by this example. I'm using SDL for input/output.

Download link

You use the up arrow to spin, other arrows for movement, P key to pause, escape key to exit, and the spacebar to drop pieces immediately.

Any feedback, constructive or otherwise is welcome, and I think that I will try to make something more interesting now.

Suggestions for drawing text would be especially welcome.

Thank you for your time.

EDIT: Also it has just occured to me that I forgot to add a restarting feature near the end...

#### Share this post

##### Share on other sites
Advertisement
I tried running the app, but got 'This application has failed to start because MSVCR100.dll was not found'. (This is on Windows XP.)

It would take me a while to really go through the code thoroughly, but from a quick once-over, it looks quite good. Here are some random observations:

- You seem to be going for an object-oriented, C++-style approach in general. In keeping with that, I'd suggest replacing your various #define's with named constants or enums.

- Don't write empty non-virtual destructors (the compiler-generated destructor will suffice).

- It looks like all the member data in c_control is public (not sure if that was intentional).

- If s_screen is the SDL_Surface for the window itself, I don't think you need to free it at shutdown (you might check the SDL docs to make sure).

Again, this was only a very cursory once-over; I didn't really get into the program logic or overall design. What I saw looked nice and clean though.

As for rendering text, you might look into the SDL_ttf library (or whatever it's called).

#### Share this post

##### Share on other sites
Thank you for taking the time to reply, I suppose it would be nice if you were able to actually run it, but I'm not skilled enough toa dd anything you wouldn't see in any other Tetris clone.

I'm assuming that I downloaded whatever DLL that is at some point and have forgotten, hm...

So enumerations are better then? I will look into changing that...

About the public members...I realy have some issues with the whole public/private bit...and Visual Studio isn't helping by automatically making things public lol.

I will definately look into "SDL_ttf"...now, thank you for the suggestion.

#### Share this post

##### Share on other sites
Quote:
 Original post by wioneoI will definately look into "SDL_ttf"...now, thank you for the suggestion.
Lazy Foo's tutorial 7 describes how to use SDL_ttf (and install it by refering to another tutorial for installing libraries).

#### Share this post

##### Share on other sites
I just want to say nice work! While I'm sure you weren't focusing on this, I do suggest that you pick nicer colors in the future. For the MSVCR100.dll, you'll probably need to look into the Visual C++ 2010 redistributables.

#### Share this post

##### Share on other sites
Quote:
 Original post by EzbezI just want to say nice work! While I'm sure you weren't focusing on this, I do suggest that you pick nicer colors in the future. For the MSVCR100.dll, you'll probably need to look into the Visual C++ 2010 redistributables.

Thank you, and about the colors, is there a better way than searching for/copying hex colors to define colors? If not, what variable type should I use to stor '0xFFFFFFff' and the like to pass? I tried character constant but that did not work.

EDIT: Thank you for suggesting that tutorial site, I'm going through 3 or 4 tutorial lists at the moment lol so I will definately need to move that set up.

#### Share this post

##### Share on other sites
Quote:
 Original post by wioneoThank you, and about the colors, is there a better way than searching for/copying hex colors to define colors? If not, what variable type should I use to stor '0xFFFFFFff' and the like to pass? I tried character constant but that did not work.
What functions are you using to create surfaces? In any case, you have some options here that might be better than using a 32-bit hex value. For example, SDL_MapRGB may enable you to more easily specify colors based on their red, green, and blue components. Or maybe you can switch and load images for your surfaces using SDL_LoadBMP you can just make some bitmaps that are colors the way you want them.

But to answer your specific question, most compilers will use an unsigned int to store a hex value like 0xFFFFFFFF. Actually, most compilers will include typedefs that allow you to specify the number of bits you want in your type. The C++ standard header for this is cstdint and you would use a uint32_t in this case.

#### Share this post

##### Share on other sites
The only surface that I used in that case was the screen surface, and I used...
s_screen=SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
I used boxColor from the gfx library for alll of the drawing, but I will try to lear about the 'SDL_image' that was mentioned...

THANK YOU for telling me about the User defined types, I've beenw ondering what all the Uint's in the libraries were, that makes sense. I think that I will finish those tutorials before I try another project.

Do you know how to create c++ project templates in VS10 via the custom wizard by chance? My recent files are a bit confusing because every solution is called 'sdl_base.'

EDIT: I think that I'm misreading the 'Microsoft Visual C++ 2010 Redistributable Package' description, does installing that change how executables are created? or does it allow the person installing to run exe's that I created?

EDIT:: Completely random, but do 'object_names' listed after a class declarations closing bracket but before the semi-colon count as a global declaration for an identifier for the class? Also, does it actually create the object or just declare it?

EDIT::: I was messing around with global variabels to just test some things and returned...
1>blabla\c_piece.cpp(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int1>blabla\c_piece.cpp(10): error C2086: 'int iii' : redefinition

Don't those two errors directly contradict each other? If it is missing a type specifier, than when was it originally defined to be illegally defiend here?

[Edited by - wioneo on July 18, 2010 9:44:07 PM]

#### Share this post

##### Share on other sites
Quote:
 Original post by EzbezI just want to say nice work! While I'm sure you weren't focusing on this, I do suggest that you pick nicer colors in the future. For the MSVCR100.dll, you'll probably need to look into the Visual C++ 2010 redistributables.

Thanks you for the post.

__________________
Watch Ramona And Beezus Online Free

#### Share this post

##### Share on other sites
Well done in completing your first game in C++. I know the first one is hard because I'm still trying to my first game in C++.

I've never actually used SDL before but I have heard of it how much different is it to using the Win32 API?

#### Share this post

##### Share on other sites
Quote:
 Original post by wioneoDo you know how to create c++ project templates in VS10 via the custom wizard by chance? My recent files are a bit confusing because every solution is called 'sdl_base.'
No. Sorry!

Quote:
 EDIT: I think that I'm misreading the 'Microsoft Visual C++ 2010 Redistributable Package' description, does installing that change how executables are created? or does it allow the person installing to run exe's that I created?
The redistributable is something that users of your program must install before they can use your program. Much of the functionality of C++ requires a layer between the program and the operating system. This layer can be added to the exe or it can be 'linked' in external dll files. By default Visual C++ puts this layer in external dll files. In the past you could change this, but I literally don't know if you can do that with VS10. In your case I suggest zipping the game exe, data files, and the redistributable along with a readme telling people to install the redistributable before running your game. Eventually you'll want to make an installer. The installer would run the sub-installers for stuff like the redistributable and DirectX for the user. Also, don't forget that other users need to run a 'release' build of your program and not a 'debug' build.

Quote:
 EDIT:: Completely random, but do 'object_names' listed after a class declarations closing bracket but before the semi-colon count as a global declaration for an identifier for the class? Also, does it actually create the object or just declare it?
First, I think I found the tutorial you must have been reading. I don't think 'object_names' is how the standard refers to that concept. Second, I personally never use this feature and I know I'm not alone in that regard.

That said, I think that this specific syntax does create global variables. While you can test this pretty easily, I suggest just never doing it regardless of what it actually means.

Quote:
 EDIT::: I was messing around with global variabels to just test some things and returned...1>blabla\c_piece.cpp(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int1>blabla\c_piece.cpp(10): error C2086: 'int iii' : redefinitionDon't those two errors directly contradict each other? If it is missing a type specifier, than when was it originally defined to be illegally defiend here?
Hard to say for sure without seeing what you actually wrote.

edit: I should say, I don't think that those errors necessarily contradict each other. The first error means that in order to continue compiling the type will be assumed to be int. After making that assumption the compiler determined that you defined iii somewhere else. If you don't define iii somewhere else then I am confused over that error.

#### Share this post

##### Share on other sites
Thank you everyone for your answers. Main thing that I think I need to work on for now is private vs. public members.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### Popular Tags

• Advertisement
• ### Popular Now

• 12
• 10
• 10
• 11
• 18
• Advertisement