• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Making a Tetris clone

 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

{B]SpaceSceneManager.java[/B]

SpaceObject.java

Ship.java

TestShip.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.
 
Chris Stewart
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checkers, Chess, Monopoly, Tank, Stratego, Risk, Minesweeper, Mini-golf, Pac-Man, Connect Four..
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I'm doing laundry! Look how clean this tiny ad is:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic