I want to make a Tetris clone for my final project in class. I have a general understanding of what steps need to happen during each loop of each piece, but I'm having a hard time getting started. Should I use a Grid layout manager, would that help me out when figuring out collisions? Any advice is greatly appreciated!
I did a DOS Tetris years ago in Pascal using a grid of colored squares. That meant pieces could only drop in row sized increments, not smooth like a real graphical implementation. I'd be sure to represent the game state in a model separate from my view. Maybe do all the collision detection and row-full detection in a 2 dimensional array and publish events to a view when the model changes. I've never touched 2D graphics. I'm sure the recommendations from graphics experts will be different.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
You guys are still thinking like procedural programmers, shame on you. Why not create an AbstractTetrisShape (which would extend Panel or JPanel) and extend that class for all of your various blocks? Then have a TetrisSceneManager that would keep a Set of the AbstractTetrisShapes and determine collisions there. The code would be a lot cleaner and more manageable and extensible. It would not be any more difficult than having one huge monolithic procedural class. As a matter of fact, I would guess it would be easier in the long run.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Joined: Jan 29, 2003
Good point. I was indeed thinking back to a pre-OO Pascal solution. Follow up a bit on your design ideas ... the shape would know which points or cells it was covering, would have isOverlapping(anotherShape) method?
Joined: Jan 30, 2002
Do you have to use Swing? This sort of thing seems to be easier to pull off with AWT. I have a small framework that demonstrates the basics for this sort of thing. Don't let the size of some of the classes scare you. Just take a look at the approach and see if you can see how to use it for a Tetris hack. SpaceScene.java
Some of the other SpaceObject classes are not here, if you want I'll post everything later. See if you can follow my logic. Basically the SpaceScene is responsible for calling the update() method on all registered SpaceObjects. The Applet or application just starts an animation loop and on each cycle calls update() on the SpaceScene object. A Tetris hack will be much simpler than this since there are only four possible orientations. There is no collision detection in this but it would be simple to add to the SpaceScene implementation since it has knowledge of all the SpaceObjects in the scene.
Joined: Sep 14, 2002
All of this seems like a little much for the scope of this project. Seeing our current work load, I'll probably have about a week and a half to do this. Also, during our presentation he's going to be drilling us on the code, so I have to know it very very well. Anybody have other suggestions for games or cool little apps?
Chris, As I have mentioned before the game doesn't have to be complex because there are plenty of features you can implement. In my first year at university I made a fruit machine, you entered a username, clicked a button and three random fruit images from an array where displayed. These were then compared to see if they were all the same or if maybe 2 matched and points allocated. The points were added up as you went along and displayed on the screen. Don't forget you only have a week and a half this isn't very long so don't go too mad. Its more important to make a good quality game that you understand. Good luck