I'm creating a tetris console-ish game, and I'm having difficulties as in how to stack the blocks on top of each other. Does anyone have, or know of where some source code.
BTW, I'm using ASCII char(219) blocks.
I'm creating a tetris console-ish game, and I'm having difficulties as in how to stack the blocks on top of each other. Does anyone have, or know of where some source code.
BTW, I'm using ASCII char(219) blocks.
Stan The Man. Beatles fan
When I was a child,
I spoke as a child,
I thought as a child,
I reasoned as a child.
When I became a man,
I put childish ways behind me"
(the holy bible, Paul, in his first letter to the Cor. 13:11)
Without seeing some code, that is all I can help with...Code:#define BLOCK 219 if(Block[X][Y + 1] == BLOCK) StopBlockFromFalling();
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Basicly a good idea would be to have the board as a 2 dimensional array, and have a class for each shape, and a class to handle(group) those shapes.
Each (shape) class would have its main member variable be a 2 dimensinal array that describes the shape. Also it would have a few functions like rotate, and move, and check for collision. IE:
Code:class block4 { ... // con-de-structors Rotate(); Move(); CheckCollide(); int shape[4][4]; // lots of seemingly extra indexs for a strait bar. }; // rotate function block4::Rotate{ // progmaticaly change indices of shape array /* [1][0][0][0] [1][0][0][0] [1][0][0][0] [1][0][0][0] to-> [1][1][1][1] [0][0][0][0] [0][0][0][0] [0][0][0][0] etc. */ } block4::CheckCollide{ /* cycle through the shape array (backwards) to see if corresponding board position is filled, if it is, then block needs to remain there. After youve decided that piece is in its final position, set the shape (indecies with values of 1) in the board array. and destroy the block4 object. */ } /* Now you'll need a function for the board array that checks rows of the array to see if the values are all one (filled). and if sow, sets them to zero, and cycles the board array, moving everything down one. */
Basic ideas to help.
c++->visualc++->directx->opengl->c++;
(it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)
You can read my old source code to get an idea on how to go about it. I did it almost exactly the way goten described it.
http://cboard.cprogramming.com/showt...hlight=textris
Alright, now I've moved onto CHAR_INFO's instead of blocks, so there is easier movement & stuff. I have it to where you see the blocks dropping, but near the end, I get an error saying some type of fault. Here's the code:
Code:#include <windows.h> #include <iostream> #include <conio.h> class CBlock { public: int x; int y; WORD Color; bool Done; void BlockFall(int x,int y,WORD Color); }; SMALL_RECT Rect= {26 , 0 , 53 , 24}; COORD Size={27,25}; COORD ZeroZero={0,0}; int RandDice(int low, int high); void gotoxy(int x, int y); void SetUp(); CBlock Block[50]; CHAR_INFO Buffer[675]; //27*25 HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE); int main() { srand(GetTickCount()); for (int c=0; c<50; c++) { Block[c].x=RandDice(28,52); Block[c].y=1; Block[c].Done=false; int Color=RandDice(0,4); switch(Color) { case 0: Block[c].Color=9; //blue break; case 1: Block[c].Color=12; //red break; case 2: Block[c].Color=10; //green break; case 3: Block[c].Color=11; //aqua break; case 4: Block[c].Color=14; break; default: return 0; } } SetUp(); int i=0; while(i!=51) { Block[i].BlockFall(Block[i].x,Block[i].y,Block[i].Color); i++; } Sleep(10000); return 0; } int RandDice(int low, int high) { return low+rand()%(high-low+1); } void gotoxy(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(hOutput, coord); } void SetUp() { for (int e=0; e<25; e++) { Buffer[26+(27*e)].Char.AsciiChar='#'; Buffer[26+(27*e)].Attributes=15; } for (int f=0; f<25; f++) { Buffer[0+(27*f)].Char.AsciiChar='#'; Buffer[0+(27*f)].Attributes=15; } for (int g=0; g<27; g++) { Buffer[((24*27)+g)].Char.AsciiChar='#'; Buffer[((24*27)+g)].Attributes=15; } gotoxy(5,4); cout << "Tetron 2.0 \nCreated By: Stan Schwertly \n(AKA Stan100)."; cout << char(1); gotoxy(54,5); cout << "Controls: "; gotoxy(54,6); cout << "Left: Moves box left "; gotoxy(54,7); cout << "Right:Moves box right "; gotoxy(54,8); cout << "Esc: Exit\n"; } void CBlock::BlockFall(int x,int y, WORD Color) { while(y!=23) { Buffer[x+(y-1)*27].Char.AsciiChar=219; //This one Buffer[x+(y-1)*27].Attributes=0; Buffer[x+y*27].Char.AsciiChar=219; Buffer[x+y*27].Attributes=Color; WriteConsoleOutput(hOutput,Buffer,Size,ZeroZero,&Rect); if (Buffer[x+(y+1)*27].Attributes!=Color) { if(Buffer[x+(y+1)*27].Attributes==0) {} else { break; } } if(Buffer[x+(y+1)*27].Attributes==Color) { break;} y++; Sleep(35); } }
Stan The Man. Beatles fan
When I was a child,
I spoke as a child,
I thought as a child,
I reasoned as a child.
When I became a man,
I put childish ways behind me"
(the holy bible, Paul, in his first letter to the Cor. 13:11)
I'm still working on this and I keep getting a thread access violation near the end. I think I made too many Char_Info's, but I'm not sure. Help?
Thx
Stan The Man. Beatles fan
When I was a child,
I spoke as a child,
I thought as a child,
I reasoned as a child.
When I became a man,
I put childish ways behind me"
(the holy bible, Paul, in his first letter to the Cor. 13:11)