• Advertisement
Sign in to follow this  

2nd game idea - tetris. Coments about initial thoughts

This topic is 4728 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

Thanks for all the input about my 1st game I personally thought about randomising the AI a little, well for the demo at least. At the moment the computers always follow the same path so radomising it may produce different results. Am thinking about starting to do a text based tetris next. Was thinking about doing a graphical version of TTT straight away but might be an idea to consolidate a bit of knowledge and try something new. Have broken the game down into some constituent parts 1 being the game area, the area that shows the score, next piece, in play instructions and another being the play area, the area in which the blocks are moved. I'm thinking the play area shold be a 1-D array of strings or a 2-D array of char(s). What does anyone else think? Don't worry I have also thought that I'll need playing pieces. a square a Block (made up of 4 squares) and a blocktype (derived from a block class I think???) I think I'll try to add a high score table as well which will mean using file I/O (which will be new for me in C++) What do poeople think about the basic HLD for this tetris game. Does anyone have suggestions, either about the design and/or features that should be incorporated?

Share this post


Link to post
Share on other sites
Advertisement
Just had a thought about a text based tetris game and that is keyboard input.

Initially I thought that I would just use cin to capture whatever the player pressed but that isn't feasible due to the fact that using cin >> variable waits for input.

I'd actually have to catch a keyboard event and then process it. Does C++ allow for this without using any 3rd party api's.

What would a simple way of capturing keyboard input in a way that didn't hold up game play?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Gary,

I would suggest the 2D array of chars would give you an easy way to access the columns and rows.

To pass on some wisdom, make the 2D array 2 chars wider and 1 char taller than you need and fill the sides with a character that basically says, hey you cannot go any further in this direction. You can use basicly use the same collision detection routines if it is an empty bucket of filled with tetris pieces.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by garyfletcher
What would a simple way of capturing keyboard input in a way that didn't hold up game play?


It has been a while but this is very close to something that you are looking for.

char ch;
while (true){
if (!kbhit()){ // detects if there is input on coming from the keyboard.
ch = getch();
//process ch
}

}

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by garyfletcher
What would a simple way of capturing keyboard input in a way that didn't hold up game play?


It has been a while but this is very close to something that you are looking for.

char ch;
while (true){
if (!kbhit()){ // detects if there is input on coming from the keyboard.
ch = getch();
//process ch
}

}


Make sure to include conio.h if you use this.

Share this post


Link to post
Share on other sites
Thanks for the input advise...thought I'd be scuppered before I'd started.

So if I wanted a play area of say 40 rows and 20 columns I'd actaully declare an array like:

char playArea[41][22]

So that I'd have extra empty "tiles" surronding the play area (except the top that is).

Edit: Is kbhit() a built in function or one for me to write? Can't find any mention of it in the C++ programming Language so am guessing I'd write it?

Edit: Had another thought. if I define a Tile class then I could use that to say if it was currently empty:


class Tile
{
public:
Tile();
~Tile();
bool isEmpty(){return isempty;}
void setChr(char aChr){chr = aChr;}
char getChr(){return chr;}

private:
bool isempty;
char chr;
};






Then I could have a 2-D array of Tiles:

Tile *playArea[41][22];

Does that sound feasible or overkill?

[Edited by - garyfletcher on March 16, 2005 2:43:30 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
kbhit is defined in conio.h like Stompy9999 mentioned.

Your tile class looks good, but the
bool isEmpty() method could be written as bool isEmpty(){return chr==' ';} and you will not have a need for the "empty" boolean variable. However, you are the engineer and it is all a matter of style and preference.

The other way could be just make it char Grid[41][22] and reference the data directly;

Share this post


Link to post
Share on other sites
I have defined two types of tile classes a base class


Class Tile
{
public:
Tile(char blockStyle = EMPTY, tileType thisTile = BASIC);
virtual Tile();
void setStyle (char aStyle){style=aStyle}
char getValue(){return value;}
bool isEmpty{return style == EMPTY;}

protected:
char style;
};

For normal tiles and a derived class

Class PlayingTile : public Tile
{
public:
PlayingTile(int row = 0, col = 0);
~PlayingTile();
void setRow (int aRow){currRow=aRow;}
int getRow(){return currRow;}
void setCol (int aCol){currCol=aCol;}
int getCol(){return currCol;}
private:
int currRow;
int currCol;
};



for tiles that are populated with playing pieces and that store their current locations within the playing area releative to a pivot tile.

I am hoping that using this method I can move/rotate the blocks quite easily. I am not too sure if I'm over complicating matters though.

What do you think?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement