Jump to content

  • Log In with Google      Sign In   
  • Create Account

Tetris clone in an hour with C++.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
149 replies to this topic

#21 Evil_Greven   Members   -  Reputation: 410

Like
Likes
Like

Posted 25 November 2003 - 01:58 PM

Dko,
You need to make the bitmap that it uses for yourself. Read the bottom part of the tutorial, it''s easy Name it "blocks.bmp", also. You don''t have the graphics, you''re not going to see anything. I suspect that there may be a problem in your MessageHandler() or further down in your WinMain() code when it''s exiting, you might want to doublecheck those two.

glassJAw,
In a simple program such as this, risks are quite minimal. What would you have done for something such as a ''score'' variable? That''d basically have to be global. You''d be passing it constantly. Sure, it''s good programming to pass stuff, but newbies aren''t always familiar with the different forms of passing, so I try to keep their use minimal.

Also, I don''t use exact Hungarian notation (bleh, n for ints, I prefer i), I use my own variant.

Lastly, I would have to change the code significantly in order to set piece types as enum/constants. The program doesn''t really care what *kind* of piece it is, it just moves it around how it needs to. Like I said, this is a very simple program.

To all beginning game programmers reading this, I wish you luck on your journey; either professional or hobbyist. You''ll need it, with all the frustrations that come up. I won''t say this is the best tutorial in the world, just one of the shorter ones .

-Greven

Sponsor:

#22 valderman   Members   -  Reputation: 512

Like
Likes
Like

Posted 26 November 2003 - 05:18 AM

quote:
Original post by The Alchemist
In my humble opinion

pouya''s tetris article was better


~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Any programmer can make snake.
The difference is that real game programmers would never think about using a linked list


[edited by - THe Alchemist on November 24, 2003 10:30:37 PM]
I concur.


[My Image Gallery (WIP)][Greatest Tetris clone evar!][Return your stolen MP3s]

#23 wild_pointer   Members   -  Reputation: 230

Like
Likes
Like

Posted 26 November 2003 - 07:31 AM

This was quite nice of you. Much appreciated.



[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people

#24 PlayGGY   Members   -  Reputation: 122

Like
Likes
Like

Posted 26 November 2003 - 12:45 PM

Congratulations! You got yourself a sticky!

#25 QzarBaron   Members   -  Reputation: 370

Like
Likes
Like

Posted 26 November 2003 - 03:32 PM

I sat thruogh the entire tutorial and finished the code then at the end i get this(BTW i named the project SimpleTris):

SimpleTris error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
SimpleTris fatal error LNK1120: 1 unresolved externals

i really dont know whats wrong is it my fault or the code.


#26 Captain Logic   Members   -  Reputation: 121

Like
Likes
Like

Posted 26 November 2003 - 03:40 PM

quote:
Original post by QzarBaron
I sat thruogh the entire tutorial and finished the code then at the end i get this(BTW i named the project SimpleTris):

SimpleTris error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
SimpleTris fatal error LNK1120: 1 unresolved externals

i really dont know whats wrong is it my fault or the code.



You need to compile to a Win32 executable, not a console. This is a compiler setting.



#27 WiseElben   Members   -  Reputation: 250

Like
Likes
Like

Posted 26 November 2003 - 04:38 PM

Uh, it''s a sticky now! Well, I''m gonna bookmark this page. I''ll read it when I have time!



Quick Clickys: [ WiseElben.com | My Journal | nMagic | My Profile ]
"Give a man a fish and he will eat for a day. Teach a man how to fish and he will eat for a life time."
-Chinese Proverb


#28 glassJAw   Members   -  Reputation: 128

Like
Likes
Like

Posted 26 November 2003 - 06:02 PM

quote:
Original post by Evil_Greven
glassJAw,
In a simple program such as this, risks are quite minimal. What would you have done for something such as a ''score'' variable? That''d basically have to be global. You''d be passing it constantly. Sure, it''s good programming to pass stuff, but newbies aren''t always familiar with the different forms of passing, so I try to keep their use minimal.

Then I recommend using accessor functions so you have some level of protection. You''re right the risks are minimal in a program of this scope, but it''s a bad habit to be teaching new programmers (I can attest to that, it was one of my bad habits).

quote:
Also, I don''t use exact Hungarian notation (bleh, n for ints, I prefer i), I use my own variant.

Using i for ints is, in fact, a very popular variant, and it completely misses the point of Hungarian notation. As I said earlier, if you prefix a variable, the prefix should represent the purpose of the variable, not the type. Using i for ints is the worst case of this, as I''ve found variables of type int are the most prone to change. Something like "BYTE iWhatever" just looks dumb, but the only alternative would be to rename every single instance of "iWhatever" in the code.

quote:
Lastly, I would have to change the code significantly in order to set piece types as enum/constants. The program doesn''t really care what *kind* of piece it is, it just moves it around how it needs to. Like I said, this is a very simple program.


You wouldn''t have to change the code much at all to use constants. It does wonders for readability.

quote:
To all beginning game programmers reading this, I wish you luck on your journey; either professional or hobbyist. You''ll need it, with all the frustrations that come up. I won''t say this is the best tutorial in the world, just one of the shorter ones .

Overall, it''s definitely a good tutorial. I just think there''s a few small problems with it that could be corrected fairly easily, and without making it a whole lot longer.

#29 Skizz   Banned   -  Reputation: 794

Like
Likes
Like

Posted 26 November 2003 - 08:54 PM

It''s OK but...
It''s not really C++, I mean, a single object isn''t very OO. You could have made the map an object, a tile an object and the application itself as an object (a singleton, even) containing your global variables.
It''s not very maintainable or resuable - two important elements when it comes to developing any type of software. The block creation code is duplicated. Also, I prefer to not use prototypes, rather use definition as declaration. In both these cases, any updates require changes to two bits of code (although one may be spotted by the compiler).
It''s not "data driven", another useful tool, especially in games programming.
You should really have put a brief section at the start detailing the design of the game (what you''re setting out to do) and thus the program (how it''s done).
Finally, a section at the end listing a few ideas for further development.

Skizz

#30 KurtCPP   Members   -  Reputation: 130

Like
Likes
Like

Posted 27 November 2003 - 01:11 AM

although that may simply means I''m a cretin, I''ve never thought Tetris was the best for a beginner. This involves no one but me...

Prog, Hex & Rock''n''Roll :
I don''t like the Prog but the Prog likes me.
Some nice poetry to sweeten your spirit and relax a bit before programming

#31 QzarBaron   Members   -  Reputation: 370

Like
Likes
Like

Posted 27 November 2003 - 03:38 AM

well i created an empty project in VS.NET i guess ill try it with Win32 the problem is it creates a bunch of useless stuff that i cant deal with.

#32 hellz   Members   -  Reputation: 356

Like
Likes
Like

Posted 27 November 2003 - 11:09 AM

quote:
Original post by Skizz
It's OK but...
It's not really C++, I mean, a single object isn't very OO. You could have made the map an object, a tile an object and the application itself as an object (a singleton, even) containing your global variables.
It's not very maintainable or resuable - two important elements when it comes to developing any type of software. The block creation code is duplicated. Also, I prefer to not use prototypes, rather use definition as declaration. In both these cases, any updates require changes to two bits of code (although one may be spotted by the compiler).
It's not "data driven", another useful tool, especially in games programming.
You should really have put a brief section at the start detailing the design of the game (what you're setting out to do) and thus the program (how it's done).
Finally, a section at the end listing a few ideas for further development.

Skizz


I think you're slightly missing the point of what's being put across here. Sure, there are improvements that could be made in terms of coding style and re-usability, but let's remember that the point of the tutorial was to get a working Tetris clone, with beginners in mind. If that means over-simplifying parts of the code in order to get the point across, then that's all well and good; it gives people an insight into how things can be accomplished and probably makes reading more specific tutorials, easier to read and grasp.

One last thing. Just because C++ supports object orientation doesn't mean that you have to use it. Yes, admittedly there are a large number of benefits to using it. However, it can be a slightly confusing paradigm to use if you're not familiar with it. Whereas the structured approach tends to be much easier to grasp; it doesn't matter how many tutorials you read about objects in a program working in a fashion like a bicycle with wheels and gears, unless you've put it into practice, it won't change the way you develop your own projects.

To OP: IMHO, great tutorial. I've not read all of it yet, but whilst I feel glassJaw makes some valid points, I do think that you've got the message across to beginners, which is the most important thing. Understanding is the foundation to a successful tutorial. No point writing something that the audience you're aiming at, won't understand; it defeats the point.

Glad it's been turned into a 'Sticky' as well. Certainly should help to answer some of the more frequent questions on this board.

-hellz

[edited by - hellz on November 27, 2003 6:09:31 PM]

#33 Captain Logic   Members   -  Reputation: 121

Like
Likes
Like

Posted 27 November 2003 - 01:04 PM

quote:


One last thing. Just because C++ supports object orientation doesn''t mean that you have to use it


What he said.


#34 boomji   Members   -  Reputation: 138

Like
Likes
Like

Posted 29 November 2003 - 05:16 AM




hi,
thank you so much greven.and a poster was right on the money when he said this tut was aimed at people starting out so all the wise tricks in the world would not mean fart.After i''m done with taking a few steps i''ll look into making all the optimizations...in fact i''ll be in a position to appreciate them more.


class act...without classes ;-p .

b


#35 alnite   Crossbones+   -  Reputation: 2133

Like
Likes
Like

Posted 29 November 2003 - 09:50 AM

quote:
Original post by hellz
One last thing. Just because C++ supports object orientation doesn''t mean that you have to use it.
*static* Roger that! *static*

As I recall, C++ is a multi-paradigmn language. Somebody posted that interview with Bjarne Stroustop. It supports OO, but you don''t have to.



#36 maxd gaming   Banned   -  Reputation: 100

Like
Likes
Like

Posted 29 November 2003 - 11:04 AM

quote:
Original post by Nervo
quote:
Original post by Anonymous Poster
http://www.gamedev.net/ can use you


aren''t you that "maxd gaming" guy?

If so, then why don''t you post in your real name.


No, thats not me. Thats my idiot friend who thinks spamming is the greatest thing

#37 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 30 November 2003 - 09:24 AM

sweet tutorial, i just finished it thanks. i''m adding onto the game now, thinking of changing it into a dr mario clone too

#38 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 01 December 2003 - 09:14 AM

quote:
Original post by maxd gaming
quote:
Original post by Nervo
quote:
Original post by Anonymous Poster
http://www.gamedev.net/ can use you


aren''t you that "maxd gaming" guy?

If so, then why don''t you post in your real name.


No, thats not me. Thats my idiot friend who thinks spamming is the greatest thing


What are you talking about...yes I am Max''d Gaming

Goto www.www.gamedev.net/

#39 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 01 December 2003 - 09:31 AM

www.www.gamedev.net

#40 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 01 December 2003 - 09:32 AM

lol thats funny... www . total noobism . cjb . net/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS