make tetris using java by bearzx. what is tetris a simple but interesting game

Post on 11-Jan-2016

220 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Make Tetris Using Java

By bearzx

What is TetrisA simple but interesting game

Java Graphic Programming

Just using Graphics ClassDraw 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

Controller

Shape

Ground

GamePanel

• Int [][] body• Shape Driver• drawMe()• moveDown()• moveLeft()• rotate• …

• int [][] obstacles• isMoveable• accept()• drawMe()• deleteLines()

• newGame()• keyPressed()• pause()• stop()• …

Is This Hard ?

Nope, it just have lots of detailsall you need to do is

install your Java Virtual Machine set up your Java IDE

then start codingIf you need to view the complete code, welcome to fork it on GitHubhttps://github.com/bearzx/MyTetris

top related