Archived

This topic is now archived and is closed to further replies.

neXt

How long would it take to make Tetris?

Recommended Posts

neXt    122
OK, I haven''t finished learning C++ just yet, but I am going along slowly. I was just wondering how long ruffly it might take someone who only just learnt the basics of C++ to code a functioning game of Tetris?

Share this post


Link to post
Share on other sites
caffeineaddict    633
It really depends on how well you know C++ and how much time you have to work on the game. It took me about 5 months to get it working a little bit, i just wasnt interested in tetris and school was killing me anyway if you have a good grasp on most of the concepts and have time to learn some more, (you never finish learning programming stuff) you may be able to finish in a couple of months if its your very first game. Make sure you learn a decent graphics api too, gdi may be ok for a first game but make sure its the last time you use it you''ll understand what i mean if you do use gdi. you should then learn directx or opengl if your going to pursue game programming, hope i''ve answered your question. Excuse the rambling, its late and i tend to do that the later it gets and the more caffeine i drink.

Share this post


Link to post
Share on other sites
Ronin_54    122
A graphics

I was talking about a text-based tetris

-Maarten Leeuwrik
"Some people when faced with the end of a journey simply decide to begin anew I guess."

Share this post


Link to post
Share on other sites
rk    122
Ronin_54, I believe he asked how long it would take from someone who only just learned the basics of c++ . Of course it depends on how one defines "basics", but your time seems utopistic to me in any case. Programming a tetris involves quite a lot of things, like visually representing the game field, getting the user input, inverting arrays and all that jazz. Much of it goes beyond my definition of "basic level". Plus there's the factor that the programmer would be probably doing his first game, unsure of what to do and how to do. So I would say it is very likely that it will take a lot more time than two and a half hours. So stop depressing the beginners with such approximations!

[EDIT] I was a little slow. Well, anyhow.. This goes for a text-based tetris as well. [/EDIT]


rk

Edited by - rk on January 1, 2002 5:39:00 AM

Share this post


Link to post
Share on other sites
Ronin_54    122
Well, I got this really neat book called "Learn C++ in 21 days". Read it in a week. Started coding. Just plotting spaces at first, found some dos commando to change the background color. Jippie, I could create blocks.

Made a single class about blocks, a simple 2d array to store the game, and a function to get input (getch) and to check the keyboard (kbhit). Well, those are the main components

-Maarten Leeuwrik
"Some people when faced with the end of a journey simply decide to begin anew I guess."

Share this post


Link to post
Share on other sites
THE Omega    122
I think alot of it depends on your level of logic.

Have you been thinking about what goes on when you play tetris? Do you understand how the field is represented? Do you know a logical way to get rid of lines and shift the rest of the field down?

When I made my tetris clone in OpenGL, I was amazed at how little OpenGL I actually used. Of course, I used a 2D view and didn''t really have any special effects or anything, but still, I''d say 75% of my time went into thinking about the logic of moving pieces, determining when the player has lost, etc, and 25% went into actually programming.

So, if you know the inner workings of Tetris extremely well, I guess you could do it in 2.5 hours. It took me about a month (on and off. School took most of my time. I could only work on tetris for a few hours a night)

Good luck

Share this post


Link to post
Share on other sites
23yrold3yrold    941
I got bored of my current project one day and tried a Tetris clone. Did it in about a day. No frills, but it had proper rotation (pushes away from other blocks and walls when turning), which the SNES version doesn''t even have (really; go check!) and worked great. I wouldn''t say it was "basic" though; I had a Tetrad base class which the other 7 inherited, and used polymorphism, calling member functions of the block to rotate, drop, etc. A bit complex for Tetris, but if you know that stuff, it makes it easy

Chris Barry

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Well, I think a very basic tetris (without any fancy effects) and no speed optimization could be easily done in 2.5 hours, even less. Not for a newbie, though.

Think about it, it''s really simple: grid is a 2d array, scroll down is easy, just data copy. Collision detection is brute force around the falling block. Check for filled lines is also a brute force approach. Test for gameover is simple.
I''d say around 20-30 min for the main game logic. 5-10 min for user input. 30 min or less for OpenGL graphics output. max 15 min. for everything else around it. Very basic, but it works.

I think I could do it in less than 1 hour, using a finished OGL framework (not typing all this WinAPI stuff, this takes time). We should try a competition some day

Share this post


Link to post
Share on other sites
kmsixpence    134
Anon, you''ve got to be one heck of a programmer to do it in an hour. It''s not as simple as people say it is. First how would you store where the current block is? Would you store it in your array or would you keep it seperate and add it to the array when it hits a block. Rotations, how would you do that. A lookup table? Pre-figured rotations? Collision detection: You''d have to test each current block for the block beneath it. Rotations again. You couldn''t allow a rotation that wasn''t possible meaning you have to do harder collision detection when it rotates. Showing the next block. When do you want to figure out what it will be. When the user fills a row? How will you do that. Will you store each type of block as a const int and randomize an integer number?

That''s just some of the logic. Now for drawing. Would you keep the blocks that are already there in an array? Would you keep the current block seperate from the array or would you keep it in the array also. When you draw the blocks, would you draw the blocks already still as a background and then the current block as a foreground. How would you store the block images in data. Would you store them as a single block and mix four of them to make a complete block? Or would you have the actual block pictures to draw on the screen.

Maybe I''m just rambling on but I''d be in awe if you could do it in under an hour

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
OK, let''s see

quote:

First how would you store where the current block is? Would you store it in your array or would you keep it seperate and add it to the array when it hits a block.


No, I would simply keep it in the array. As I said, 2d grid, each grid position represents a block. Different values for different colours, but no meaning in the game. Only one block can be at a grid position at a time. I would keep a pointer to the shape of the current block (predefined small arrays of shape masks), it''s rotation (4 possibilities) and position within the game grid (x, y).

quote:

Rotations, how would you do that. A lookup table? Pre-figured rotations?


No, depending on the current rotation flag, invert or transpose the x/y axis.

quote:

Collision detection: You''d have to test each current block for the block beneath it. Rotations again. You couldn''t allow a rotation that wasn''t possible meaning you have to do harder collision detection when it rotates.


No, not harder. Before performing a block operation (rotation, movement, falldown), make a brute force search at the desired new block position. Simple AND between the grid (at current position x,y) and the current block shape mask (pointer, see above). Don''t forget axis inversion/transpose for rotations. If there is a collision (grid & mask == 1), simply forbid the operation. If the forbidden operation was a fall-down, then the block settles, check for lines to remove and/or game-over, on to next block.

quote:

Showing the next block. When do you want to figure out what it will be.


See above.

quote:

When the user fills a row? How will you do that. Will you store each type of block as a const int and randomize an integer number?


Kind of. See my shape mask pointers above. Filled row check: simply check all rows that are affected by the settled block, if they are filled -> delete them and scroll down the array.

quote:

That''s just some of the logic. Now for drawing. Would you keep the blocks that are already there in an array?


No, they are the values in the grid.

quote:

Would you keep the current block seperate from the array or would you keep it in the array also.


In the grid.

quote:

When you draw the blocks, would you draw the blocks already still as a background and then the current block as a foreground. How would you store the block images in data. Would you store them as a single block and mix four of them to make a complete block? Or would you have the actual block pictures to draw on the screen.


No, I iterate through the 2D array, get the value (= colour), and draw a coloured rectangle at that position on the screen.

quote:

Maybe I''m just rambling on but I''d be in awe if you could do it in under an hour


I''m almost sure I can. Hey, I think I''ll just try it, if I''ve some time, just to prove myself, that I can Just don''t bet on the readability of the source

Share this post


Link to post
Share on other sites
Crash    122
Id say it should take a month if you already know DirectX quite well or 2months if you dont. Thats including school and a demanding social life though.

Anyway thats how long it took me, so you should be able to cope with that.

Crash,



"We Must Move Forwards NOT Backwards, Sideways NOT Forwards And Always Twirling Twirling Towards Success." - 2000

"If You Keep Looking Forward Your Gonna End Up Looking Backwards At Yourself Running Sideways!" - 2001

Share this post


Link to post
Share on other sites
da_cobra    122
and now to answer the question that neXt asked

I was a total newbie to c++ & directx and It did me 1 month to learn the basics of c++, 2 months to create my first window and initialize DirectX, and now I''m about 3 months busy with my first game : a tetris :D

after 2 months and a half I had the complete game logic and a simple menu (new game, credits, exit) now I''m trying to include sound and improve my graphics a bit

so let''s say 5 months for a newbie to understand the tetris logic and to create one

Share this post


Link to post
Share on other sites
TheTramp    122
It took me a few days to make a quite advaned tetris clone - after learning DirectDraw and DirectInput (took a week or 2) - although this was following the tutorial in the hands-on game development forum - which although is not object oriented was one of the most helpful tutorials I ever read - It covers all sorts of very helpful topics.

Edited by - TheTramp on January 2, 2002 6:48:07 AM

Share this post


Link to post
Share on other sites
BeerNutts    4400
AP, I guarantee you cannot make a decent Tetris game from scratch in 1 hour. Everyone seems to forget one thing when talking about time estimartes: TESTING! Somewhere in the code, you''re going to do something stupid (ex, if (PosX = 0)), and you''ll spend 10-15 minutes on those problems (everyone does stupid things...it happens). Besides that, writing the code will take long enough. 2.5 hours, yeah, that''s possible, but 1 hour for Tetris, "Inconceivable!"

Share this post


Link to post
Share on other sites
Ronin_54    122
Eight a4-sized pages. That''s my code

-Maarten Leeuwrik
"Some people when faced with the end of a journey simply decide to begin anew I guess."

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
OK, I did it. Took me 52 minutes, 17 seconds, timed. (phew, close I had to speed up to the end, so I couldn''t include some more fancy stuff, but well, in the end I still had 8 minutes left).

This is not counting the OpenGL framework (it was already done on my HD), and the by-hand drawing of the shape blocks. I didn''t play Tetris for quite some time, so I had to remember the shape of all those blocks, by playing a bit Tetris first.
It''s a very primitive Tetris, but it works. It''s OpenGL with a little graphical effect (coloured blocks with gradients). It''s configurable through #define''s in the source.

I''ll add some comments and clear up the source (because it''s *really* chaotic right know). I''d like to upload the source somewhere, someone got some webspace for me ? I don''t want to create a GeoCities account for a small .C file...

It is possible under an hour ! I knew it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Hmm... I thought I would make a tetris like 5 days ago. I thought it would be a good challenge. And it wasn''t that hard. I used allegro, which made me not have to worry about gfx. And it took me like 5 hours and then I hade a "working" tetris, with a random block, falling down, and destorying lines. Then it took like 10 mins to add score. But now I''ve started to make it OOP, which have made me write it again from scratch.

Share this post


Link to post
Share on other sites