Advertisement

Tetris Problem

Started by August 21, 2000 01:15 PM
6 comments, last by Neeko81 24 years, 4 months ago
I am making my first game be my own version of tetris in VC++. Since this is my first full game I am going through the process pretty slow, but I have run into a roadblock, how do you know if there is a tetris? I know the common response is when the line is filled, but how do you code when a line is filled? I know this is a newbie question, but your help would be greatly appreciated.
Do or do not--there is no try- Master Yoda
A way of doing it could be to use an 2D array of values for the puzzle screen and then use a for loop to check a line. for example:


int Display[ysize][xsize]

// Code to check for a line
bool Line;
for (int i = 0; i < ysize; i++)
{
Line = true;
for (int j = 0; j < xsize; j++)
{
if (!Display [j])
Line = false;
// if there is no block here, it is not a line
}
if (Line)
// More code here to tell program you have a line
}

// Code to draw the array
for (int i = 0; i < ysize; i++)
for (int j = 0; j < xsize; j++)
// Drawing code here


Also, you could use an array of integers while drawing cause the aray could store different non-zero numbers for different colored tiles, and a 0 for no tile.

Hope this helps!

Edited by - SteveBrown on August 21, 2000 2:36:18 PM
Advertisement
every time a block drops fully, check all the lines that the block dropped into for whether they are full (the other lines don''t need to be checked, because they aren''t affected)... the way I implemented this was to have a one-byte value for 8 bools, which were set to 1 when a block was filling that place... so I only had to xor the value and check for its truth... but there are easier and slower ways to do it...

11101111 xor 11111111 = 00010000 -> not filled!

11111111 xor 11111111 = 00000000 -> filled, you''ve got a line!

to place a block, just ''or'' that place with 2^(whatever column you''re in)... (1 << col)

well, my aim was to take up as little space as possible, and I used a lot of assembly in there, too... since you''re using VC++ and it''s probably your first game, you don''t have to make it complicated... just have an 8 x ROW_SIZE array storing whether the place is filled yet... and check all of these after each drop...

hope this helped...


"Man is the only animal that laughs and weeps; for he is the only animal that is struck with the difference between what things are and what they ought to be."
        --William Hazlitt
Greenspun's Tenth Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp."

.- Nice game to program... I will re-start mine who knows when...

.- In this game, you need to THINK all before implementing it, because there are many optimizations...

.- You are using a 2d matrix to represent the area where the pieces are, aren´t you. Of course you are... Just loop over the line,check if it´s a piece in each cell ,all filled->Tetris:

//line when you want to check for a tetris
//int matrix[y,x] is the playable area.If 0 there isn´t any piece
// else number is the number of the piece.
//TRICK:Every Tetris piece is made of 4 "boxes". This way you //just need N,N=nº of pieces, color cuadrangles to make any //piece...
BOOL IsLine(int line)
{
int index;
for(index=0,index if(matrix[line,index]==0
return TRUE;
return FALSE;
}

.-You don´t know spanish, don´t you? .I could link you to a page about Teris with many optimizations...

.-If your´re in big trouble continue asking, and I´ll help you, but you SHOULD do it yourself...

.-Last indication, at initializing construct arrays of each piece at each possible look, you´re play and next pieces will be just copies of those...

.-Were you born in 1981 or are you 81 years old?. The latter is what your nick says... I´m from 1980...

Hope to help....


What the hells!
What the hells!
Use a 2D array. After the current brick is done moving, just scan the rows.

Here is a process you can use for a tetris game:
1. drop block
2. scan rows
3. remove rows
4. game over?
5. go to 1 if necessary
Thanks for all the help. I knew I needed a 2D matrix, but didn''t know how to implement. To answer your Q Grugnorr I am from 1981. I will let you all know how it turns out.

Do or do not--
there is no try
- Master Yoda
Do or do not--there is no try- Master Yoda
Advertisement

.-Of course you´re from 1981! I was joking! Or not?...

.-In Internet chats people put NameYears, as Mike23, not Mike 1977->that´s longer...

.-Well there´s also sex chats where people put, ejem, some exagerated measures like Mike25(centimeters..)

.-Good luck ...


What the hells!
What the hells!
LOL
Yeah, I put it as 81 so I don''t have to change it year-to-year.
Anywho---

Do or do not--
there is no try
- Master Yoda
Do or do not--there is no try- Master Yoda

This topic is closed to new replies.

Advertisement