Tetris game java source code download
#1

[attachment=13510]



The main logic behind the game


I faced difficulty in two areas while working this project, the details and logic of which are mentioned below.

• The first problem came while finding out a way to recognize patterns once the elements pair are on the game board.


To solve this problem I designed a 3 dimensional data structure .TetrisDS[15][4][4] i.e basically15 2-dimensional array of 4*4 dimension to store information about 15 tetris shape.
Code:
static int tetrisDS[][][]=
    {
        {                              
            {0,0,0,0},            
            {0,1,2,3}
        },                      
        {                        
            {0,1,2,3},        
            {0,0,0,0}                    
        },                        
        {
            {0,0,1,1},
            {0,1,0,1}
        },
        {
            {0,1,2,2},
            {0,0,0,1}
        },
        {
            {0,1,1,1},
            {0,0,-1,-2}
        },
        {
            {0,0,1,2},
            {0,1,1,1}
        },
        {
            {0,0,0,1},
            {0,1,2,0}
        },
        {
            {0,1,2,2},
            {0,0,0,-1}
        },
        {
            {0,0,0,1},
            {0,1,2,2}
        },
        {
            {0,0,1,2},
            {0,1,0,0}
        },
        {
            {0,1,1,1},
            {0,0,1,2}
        },
        {
            {0,0,1,1},
            {0,1,1,2}
        },
        {
            {0,1,1,2},
            {0,0,-1,-1}
        },
        {
            {0,0,1,1},
            {0,1,-1,0}
        },
        {
            {0,1,1,2},
            {0,0,1,1}
        }
    }
The main procedure to scan :

In the method removeAllTetris we start scanning from the bottom most, leftmost element of the gameboard (game Board is a matrix of 6*14 dimension) i.e from
Field[height][0].
Now for each element we call a method foundTetris(int y ,int x) where y and x are the row index and column index of the field matrix. In foundTetris() method we compare value of the field[y][x] to the element decided by adding the value of TetrisDS[0-15][0][1-3] to y and TetrisDS[0-15][1][1-4]. Now this is done till the next 3 element
i.e total of 4 elements have same value , if this is the case the loop is halted and the tetrisDS index for which 4 elements have the same value is send back.

If this is not the case then the searching is continued.

EXAMPLE:


Suppose we have 4 similar elements lying horizontally starting from the position field[2][2] now to scan we store the value of field[2][2] in a variable color and compare this value with field[2+0][2+1] then with field[2+0][2+2] and then with field[2+0][2+3].
So basically we added 0,0,0 to Y index ie row index and 1,2,3 to column index i.e. x.

Now this is the idea behind the TetrisDS datastructure which I have used


• The second problem was to remove the tetris which has been detected

Now for this too we removed the tetris- element wise where the data structure helped to track down the detected pattern of removal
The removeElement (y,x)method is a recursive method with a simple working






The main class
Tetris.java



This class implements the game play it handles the keyboard events and other the creation of random element pair and their downward movement.

This class also implements the GUI of the game.

TetrisFrame.java class

starting point of the game. Extends JFrame container and adds the Jpanel component of the Tetris class. Initializes the tetris class.
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: source code for quiz game in java, cricket game code in java, tetris game java code, srs on quiz game in java, cricket game code java, bluetooth multiplayer game abstract for java, java game,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  projects in core java project topics 6 16,127 16-01-2018, 11:15 AM
Last Post: dhanabhagya
  Steganography implemented in Java science projects buddy 14 12,170 24-05-2016, 10:15 AM
Last Post: dhanabhagya
  Visual Learner Memory Game seminar presentation 2 1,928 25-03-2016, 12:03 PM
Last Post: dhanabhagya
  STUDENT INFORMATION SYSTEM IN JAVA project topics 14 10,606 19-08-2015, 11:28 PM
Last Post: Guest
  mini projects in java project topics 7 18,788 01-05-2015, 04:18 PM
Last Post: seminar report asees
  Visa Processing System full report and asp source code project topics 2 5,531 19-06-2014, 06:54 PM
Last Post: seminar report asees
  distributed cache updating for the dynamic source routing protocol project report tiger 4 3,000 05-03-2013, 02:22 PM
Last Post: Guest
  application projects in java and vb.net (titles and topics) project topics 1 5,497 28-11-2012, 01:11 PM
Last Post: seminar details
  Energy-Efficient Routing in Mobile Ad Hoc Networks: Mobility-Assisted Case (Java) project topics 1 1,756 12-11-2012, 12:42 PM
Last Post: seminar details
  Net Auction java based project report project topics 2 3,699 01-11-2012, 12:59 PM
Last Post: seminar details

Forum Jump: