Console Programming - Tetris

Started by
31 comments, last by Android_s 20 years, 8 months ago
Right! Due to my lack of knowledge I have been forced to take a step back to try to make a console Tetris instead of the Win32/OGL one i was trying earlier. Things now seem to proceed fast but i still have a couple of questions about this. First one is about movement. In my Win32/OGL project i was using bool keys[VK_LEFT/VK_RIGHT] for the horizontal movement, all acording to NeHe standards . But now when I try it in console nothing happens. My question is then, Dosn''t VK_LEFT/VK_RIGHT work in console? My second, that is some sort of a thought. I have seen people here suggest the 4x4-array method for making the shapes of the four blocks. I read somewhere that it is a way to dynamically link the blocks together instead. Is there anyone that have made this and if so, can you perhaps post some info about this method? Thanks in advance! ----------------------------------------------------------- ----------------------------------------------------------- "Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr. http://www.gametutorials.com
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.
Advertisement
#1 - VK_LEFT/VK_RIGHT are win32 only. They are used in the windows message procedure but, dos does not have one. You would have to implement some form of input. ( Such as getch() or getchar() )

#2 - 1 way to dynamicaly link blocks is with linked lists. Read up on how linked lists work and that should do the trick.
The bool keys thing is a concoction of Jeff''s that has nothing to do with console mode. That array gets updated in the generic WinProc code whenever an appropriate message is received (you can look through the source if you don''t believe me). Anyways, you''ll probably want to look into the getch() family of functions for your input. Just remember that this won''t be event driven, but procedural (is that the right terminology?) in nature.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
About the VK_LEFT/RIGHT I suspected something like that. I will try an old code I remember from one of the GameTutorial lessions, and if that dosn''t do the trick i will look into getch().

And about the other question, I have always wondered what linked lists are for. Perhaps now I find the answear to that

Thanks!
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.
Heres most of the input function in my ASCII tetris, hopefully this will help you a little ...
void UserInput(void) {   input = false;   if(_kbhit())   {	   bInput = true;	   int key = _getch();	    if(toupper(key) == 'Q')		{			//blah blah		}	    else if(toupper(key) == 'P')		{		                  //blah blah                }			QueryPerformanceCounter(&previousTicks);    // reset the time		}		else if(key == 32)	// pressed the spacebar		{                  //blah blah		}		else if(key == 224)	// it's a cursor key!		{			switch(_getch())			{				case 75:					bLeft = true;					//left					break;				case 77:					bRight = true;					//right					break;				case 72:					bRotCounterClock = true;					//up					break;				case 80:					bRotClock = true;					//down					break;			}		}   }		}


An ASCII tetris clone... | AsciiRis

[edited by - Tiffany Smith on August 6, 2003 12:11:28 PM]
An ASCII tetris clone... | AsciiRis
I will start on a Win32/OpenGL/DirectX one soon. But not today. Maybe tomorrow. I will give out the source when I am done.

Scott Simontis
Big Joke: C#
Scott SimontisMy political blog
quote:Original post by Android_s
And about the other question, I have always wondered what linked lists are for. Perhaps now I find the answear to that


A linked list is where one object contains a pointer to the next object. It is great if you''re going to insert or remove lots of objects in the list, but you can''t jump to any object you want, you always have to go through them in order.

I doubt you''ll need a linked list for tetris, though.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
As for "dynamically linking blocks together", I don''t see what you mean. If, however, you mean to reserve memory only for the needed blocks (as oposed to a 4x4 array, where you allocate four times as much memory as is really needed), you could simply solve it by placing all the currently falling blocks in a CGroup class or something like that.

If you need some other help about the game logics, you can check out the full source of my Tetris game here. It uses Win32 for input and stuff, and OpenGL for the graphics, but the logics are the same wether you use OpenGL or ASCII graphics. The code is heavily commented, at least if you compare it to what my code usually looks like.

"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately."
Thanks for all the help!

I havn''t had mutch time to try all the methods that have been suggested here, but I hope I can sit down and try some tonight.

I still have one question for Tiffany Smith about her Tetris clone. Why is it that you write for example _getch() and _kbhit()? Is it the same as to write getch() and kbhit()?
Hmm, is it possible I can see the code to that Tetris you made? I would like to see how you did that drop-funktion.

And for Valderman. I ain''t sure exactly WHAT i meant by linking them together dynamically, it was just something I read a while ago. The thought is that when you want a speciffic shape, for example one of those straight lines, you could group 4 blocks together in a line. I don''t know if it''s possible without too mutch code, but it would be fun to see how it''s done.
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.
quote:The thought is that when you want a speciffic shape, for example one of those straight lines, you could group 4 blocks together in a line. I don't know if it's possible without too mutch code, but it would be fun to see how it's done.
Check out the CGroup and CBlock classes in the link I posted before, that's one way to do it. Although it's most likely not the best way, it works fine for me.

Oh, here's the link again: Clicky

Oh yeah, the code for rotating the blocks is pretty ugly, if I remember correctly.

"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately ."

[edited by - Valderman on August 7, 2003 1:02:23 PM]

This topic is closed to new replies.

Advertisement