Make Tetris Using Java By bearzx
What is Tetris A simple but interesting game
Java Graphic Programming Just using Graphics Class Draw anything you want in a Java GUI Gomponent(Jpanel, Jframe, etc)
Key Points Of Tetris Game How to store a shape ? How to generate a shape ? What happens after a shape is generated ? How to describe a ground ? How to accept a shape, and DELETE full lines ? Let’ s fix them one by one
How to store a shape ? Just using an array with 3 dimensions
How to generate a shape ? When we need a new shape, we “new” a instance of Shape Class
What happens after a shape is generated ? Make it falls down, using Java multithreading feature. Define a class which implements Runnable interface
How to describe a ground ? Like a shape, use a 2 dimensions array for a ground, it is just bigger When you need to draw the ground, just have a look at the obstacles.
How to accept a shape, and DELETE full lines ? First you need to decide whether or not the shape can move down
How to accept a shape, and DELETE full lines ? If the shape can’ t move down, accept it. And don’ t remember to delete the full lines, if you can
Let’ s Link Them Up Int [][] body Shape Driver drawMe() Shape moveDown() moveLeft() rotate … Shape GamePanel Controller int [][] obstacles isMoveable accept() drawMe() deleteLines() newGame() keyPressed() pause() stop() … Ground
Nope, it just have lots of details Is This Hard ? Nope, it just have lots of details all you need to do is install your Java Virtual Machine set up your Java IDE then start coding If you need to view the complete code, welcome to fork it on GitHub https://github.com/bearzx/MyTetris