-1

I am working out a concept for a Tetris style game with a twist. I have worked through a few tutorials for the basic logic but with the way we are wanting to do this, I am not sure if the logic is even possible in our time frame.

Basically, we are using custom images for the Tetris pieces. We have three different colors for each and a different image for each possible rotation. On top of that, our game will be trying to pair letters together so we have images with each possible rotation with each possible letter placement. For example, for the "T" shape, we have right now 92 images of each possible rotation for just ONE of the three color's we want to use with the four letters we are using. After thinking about it for the past few days, there is going to be hundreds (maybe even over a thousand) images.

However, that's not the issue. The only way I can think of checking is using a TON (like well over a thousand) IF statements. For example, if piece 1 which is a "T" shape with an "A" on the right side, we need to check if "B" is next to any of the other possible positions the piece can ever be in. If a piece with an "A" on it is next to (either above, below, or on either side) a piece with a "B" on it, a good match with be registered. If at any point two letters that are the same land next to each other, the whole row of pieces that the are a bad match will disappear causing any pieces above it to fall down. Once these pieces land again, every single piece needs to be checked again to see if its new position is a part of any possible letter pair. The checking will always need to be happening for every single piece that is spawned onto the game board so the more pieces there are, the more checking that needs to always be happening.

So, is this something that will simply take way to long (we have just over a month) or is there something else that can be done besides a TON of IF statements? Is something like this even possible? After all we are talking most likely 1000 images and every single image needs to always be getting checked if it:

  1. Has hit another image and needs to stop

  2. Check if where the player placed it is next to another letter and if it is a good letter match or not (this is the big issue)

  3. Once a whole piece disappears, the pieces need to shift down again and get all the checking needs to happen once again.

The plan is to do this in java since its the only language I have a good understanding of but I am open to any and all suggestions. If its a lost cause, please let me know. Would like to come up with another concept before I invest a lot of time into this if it is a lost cause.

EDIT:

Here is a very quickly tossed together image that gives you an idea of what it looks like:

http://imageshack.us/a/img560/1814/dg80.png

Looking at this image, you see 4 pieces already in place at the bottom of the board and the player is guiding the straight piece down. The player wants to match the "A" at the bottom of the line with the "A" that is in the right "square" of the "T" shape. Once the piece has landed next to the "T", the code needs to say "Oh hey, another "A" just landed next to me so I am a good match and we both need to disappear". Once that has happened, the other pieces will shift down and the checking needs to happen again. Since there are SO many combinations of pieces and with players having free reign to put pieces in crazy spots, the checking needs to be insane. Every single piece needs to check with all the other pieces to ensure a valid combo is never missed.

Here is an example of what a piece looks like:

http://imageshack.us/a/img23/6632/1g3q.png

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Badge
  • 61
  • 5
  • 1
    I think it would be easier to achieve a Tetris board using colored `Shape` instances, than using images. Java-2D has built-in methods for rotating either images or shapes, but a shape also provides methods to detect collision with other shapes (which is handy when it comes to pieces that are not rectangular). See [this answer](http://stackoverflow.com/a/14575043/418556) for an example. – Andrew Thompson Oct 02 '13 at 15:24
  • That's something we are thinking about, however that still doesn't solve our biggest issue which is the letter combos. With so many different possible combination of letters taking up a single "square" in the Tetris piece, there are hundreds of possible pair combinations that can be valid. We don't plan on having every single piece that comes out have a letter on it, but when one does, it needs to not only check collision, but it needs to detect if it has stopped moving with a part of the shape (one of four Tetris squares) landing next to another shape with a letter that it a valid pair. – Badge Oct 02 '13 at 15:31
  • OK I don't get it (now I've read more). These 'letters' is what I don't understand. By 'letters' DYM that a 'T shape' is one letter? So the other shapes would be an 'L shape', an 'I shape' and ..what? No.. wait, that does not seem to be it, you are mentioning 'A's and 'B's. Can you post a screenshot of how a partially completed game would look? – Andrew Thompson Oct 02 '13 at 15:35
  • Check out the edit at the top with two images. – Badge Oct 02 '13 at 15:55
  • *"(I don't have access to include it right in the post)"* I do. It is done! – Andrew Thompson Oct 02 '13 at 16:00
  • Why not have the letters alone as transparent images and compose the letters onto the pieces? And rotate the (possibly composed) pieces as @AndrewThompson suggests. PS: The images are gone... – Harald K Oct 03 '13 at 07:38

1 Answers1

0

What you will probably want to do is think of your Gamefield as a 2 dimensional array with a set of cells. Each row is N cells wide and there are M rows. Now whenever a piece gets dropped anywhere you register the letters in the piece in the gamefield array.

Lets assume your pieces look like this:

public class GamePience {
  public Character letter;
  public Color color;
}

This gives you

GamePience[][] gamefield = new GamePience [M][N]; // null is empty, otherwise gilled

When a piece is dropped you copy it's letters to the array (for simplicity I'm assuming pieces are also 2 dimensional arrays because that works well)

gamefield[0][2] = piece[0][0];

Now after a letter is placed and copied to the field you can simply check the over the field

boolean destroyedLine = false;
do {
 for (int x = 0; x < gamefield.length; x++) {
  for (int y = 0; y < gamefield[x].length; y++) {
     GamePiece cur = gamefield[x][y];
     if (cur != null && x < MAX_FIELD_WIDTH && gamefield[x+1][y] != null) {
        // there are gamepieces in both!
        GamePiece neighbour = gamefield[x+1][y];
        if (cur.letter == neighbour.letter) {
           destroyLine(x); // this method should null out the line and shift everything down, you'll probably want to loop trough the whole line first and check if there are pieces in every cell
           destroyedLine = true;
           break;
        }
     }
  }
 }
} while(destroyedLine);

You can also easily check against the gamefield while dropping down pieces to check if the cells are already filled. Now, all you need to do is fill out that logic and write some code to draw the gamefield and you are set ;) (you might want to think about using an LinkedList for the gamefield because that makes deleting rows trivial)

Patrick Huy
  • 975
  • 1
  • 8
  • 19