TETRIS In JAVA Mac OS

broken image


The Tetris game

By Tetris Holding One of the largest selling and recognized brands in gaming history is now available for both Windows and Mac OS X. Tetris Zone offers four modes of play, from the simple, yet. To date, Macintosh Repository served 1439197 old Mac files, totaling more than 285652.3GB! Downloads last 24h = 722: 131698MB Last 5000 friend visitors from all around the world come from.

In this chapter, we will create a Tetris game clone in Java Swing. The following example is based on the C++ code example available at doc.trolltech.com. It is modified and simplified.

Tetris

The Tetris game is one of the most popular computer games ever created. The original game was designed and programmed by a russian programmer Alexey Pajitnov in 1985. Since then, Tetris is available on almost every computer platform in lots of variations. Even my mobile phone has a modified version of the Tetris game.
Tetris is called a falling block puzzle game. In this game, we have seven different shapes called tetrominoes. S-shape, Z-shape, T-shape, L-shape, Line-shape, MirroredL-shape and a Square-shape. Each of these shapes is formed with four squares. The shapes are falling down the board. The object of the Tetris game is to move and rotate the shapes, so that they fit as much as possible. If we manage to form a row, the row is destroyed and we score. We play the tetris game until we top out.

The development

We do not have images for our tetris game, we draw the tetrominoes using Swing drawing API. Behind every computer game, there is a mathematical model. So it is in Tetris.
Some ideas behind the game.
  • We use a Timer class to create a game cycle
  • The tetrominoes are drawn
  • The shapes move on a square by square basis (not pixel by pixel)
  • Mathematically a board is a simple list of numbers
I have simplified the game a bit, so that it is easier to understand. The game starts immediately, after it is launched. We can pause the game by pressing the p key. The space key will drop the tetris piece immediately to the bottom. The d key will drop the piece one line down. (It can be used to speed up the falling a bit.) The game goes at constant speed, no acceleration is implemented. The score is the number of lines, that we have removed.
Tetris.java
In the Tetris.java file, we set up the game. We create a board on which we play the game. We create a statusbar.
The start() method starts the Tetris game. Immediately, after the window appears on the screen.
The Shape class provides information about a tetris piece.
The Tetrominoes enum holds all seven tetris shapes. Plus the empty shape called here NoShape.
This is the constructor of the Shape class. The coords array holds the actual coordinates of a tetris piece.
The coordsTable array holds all possible coordinate values of our tetris pieces. This is a template from which all pieces take their coordiate values.
Here we put one row of the coordiate values from the coordsTable to a coordsarray of a tetris piece. Note the use of the ordinal() method. In C++, an enum type is esencially an integer. Unlike in C++, Java enums are full classes. And the ordinal() method returns the current position of the enum type in the enum object.
The following image will help understand the coordinate values a bit more. The coords array saves the coordinates of the tetris piece. For example, numbers { 0, -1 }, { 0, 0 }, { -1, 0 }, { -1, -1 } , represent a rotated S-shape. The following diagram illustrates the shape.
Figure: Tetris
This code rotates the piece to the left. The square does not have to be rotated. That's why we simply return the reference to the current object. Looking at the previous image will help to understand the rotation.
Finally, we have the Board.java file. This is where the game logic is located.
We initialize some important variables. The isFallingFinished variable determines, if the tetris shape has finished falling and we then need to create a new shape. The numLinesRemoved counts the number of lines, we have removed so far. The curX and curY variables determine the actual position of the falling tetris shape.
We must explicitely call the setFocusable() method. From now, the board has the keyboard input.
Timer object fires one or more action events after a specified delay. In our case, the timer calls the actionPerformed() method each 400 ms.
The actionPerformed() method checks if the falling has finished. If so, a new piece is created. If not, the falling tetris piece goes one line down.
Inside the paint() method, we draw the all objects on the board. The painting has two steps.
In the first step we paint all the shapes, or remains of the shapes, that have been dropped to the bottom of the board. All the squares are rememberd in the board array. We access it using the shapeAt() method.
In the second step, we paint the actual falling piece.
If we press the space key, the piece is dropped to the bottom. We simply try to drop the piece one line down until it reaches the bottom or the top of another fallen tetris piece.
The clearBoard() method fills the board with empty NoSpapes. This is later used at collision detection.
The pieceDropped() method puts the falling piece into the board array. Once again, the board holds all the squares of the pieces and remains of the pieces that has finished falling. When the piece has finished falling, it is time to check, if we can remove some lines off the board. This is the job of the removeFullLines() method. Then we create a new piece. More precisely, we try to create a new piece.
The newPiece() method creates a new tetris piece. The piece gets a new random shape. Then we compute the initial curX and curY values. If we cannot move to the initial positions, the game is over. We top out. The timer is stopped. We put game over string on the statusbar.
The tryMove() method tries to move the tetris piece. The method returns false, if it has reached the board boundaries or it is adjacent to the already fallen tetris pieces.
Inside the removeFullLines() method, we check if there is any full row among all rows in the board. If there is at least one full line, it is removed. After finding a full line we increase the counter. We move all the lines above the full row one line down. This way we destroy the full line. Notice, that in our Tetris game, we use so called naive gravity. This means, that the squares may be left floating above empty gaps.
Every Tetris piece has four squares. Each of the squares is drawn with the drawSquare() method. Tetris pieces have different colors.
The left and top sides of a square are drawn with a brighter color. Similarly, the bottom and right sides are drawn with darker colors. This is to simulate a 3D edge.
We control the game with a keyboard. The control mechanism is implemented with a KeyAdapter. This is an inner class that overrides the keyPressed() method.
If we pressed the left arrow key, we try to move the falling piece one square to the left.
TETRIS In JAVA Mac OS
Figure: Tetris

Tetris In Browser

This was a Tetris game.
  • Beginning with MacOSX v.10.2 (Jaguar), Apple has reserved the keyboard shortcut Command+~ (Tilde) to cycle through an applications open document windows. This change conflicts with the behavior of the shortcut in Adobe Photoshop 7.x (selecting the. ..

    • File Name:OS_X_Keyboard_Shortcut_Fix.hqx
    • Author:Adobe Systems, Inc.
    • License:Freeware (Free)
    • File Size:9 Kb
    • Runs on:PPC
  • Brings together enhancements to AOLA?s popular email and instant messaging features, such as a counter on the MacOSX dock that displays the number of new messages, the new AOL Search, the addition of new short-cut keys, as well as several Mac-first. ..

    • File Name:AOL_for_Mac_OS_X.dmg
    • Author:Jeffrey Surry
    • License:Freeware (Free)
    • File Size:18.6 Mb
    • Runs on:Any Platform
  • Plazer for MacOSX 2.0.5 is such a small yet very useful software that can locate you automatically with your PC or Laptop. It integrates into iChat to let other people know where you are. The Software acts as the local part of Plazes, a location. ..

    • File Name:Plazer for Mac OS X
    • Author:plazes AG
    • License:Freeware (Free)
    • File Size:526 Kb
    • Runs on:Mac OS X
  • D2X-XL is an OpenGL port of the classic 3D Shooter game Descent 2 for Win32, Linux and MacOSX, containing many enhancements and bug fixes while preserving full backwards compatibility. FEATURES: · Colored lighting and lightmap support. ·. .. Diplomat (obtuse angels) mac os.

    • File Name:d2x-xl-osx-1.15.270.dmg
    • Author:Dietfrid Mali
    • License:Freeware (Free)
    • File Size:37 Mb
    • Runs on:Mac OS X
  • K-3D is the free-as-in-freedom 3D modeling, animation, and rendering system for MacOSX operating systems. K-3D features a robust, object-oriented plugin architecture, designed to scale to the needs of professional artists, and is designed. ..

    • File Name:k3d-setup-0.8.0.1-i386.dmg
    • Author:Rene Jensen
    • License:Freeware (Free)
    • File Size:29.2 Mb
    • Runs on:Mac OS X
  • Veusz is a GUI scientific plotting and graphing package. It is designed to produce publication-ready Postscript or PDF output. SVG, EMF and bitmap export formats are also supported. The program runs under Unix/Linux, Windows or MacOSX, and binaries. ..

    • File Name:veusz-1.13-AppleOSX.dmg
    • Author:Jeremy Sanders
    • License:Freeware (Free)
    • File Size:10.2 Mb
    • Runs on:Mac OS X
  • HeliosPaint is a feature-rich, easy-to-use and powerful paint program for editing photos, drawings and icons. It runs on Microsoft Windows, Apple MacOSX, Linux and Unix. Tools and features in HeliosPaint currently include: * Pencil for. ..

    • File Name:HeliosPaint.jar
    • Author:D.J.B. Osborne
    • License:Freeware (Free)
    • File Size:1.6 Mb
    • Runs on:Mac OS X
  • Free desktop client for the web-based Wolapp Cloud application, specially developed for MacOSX. Wolapp Cloud - Wheel Of Life Cloud is a web-based application for self-development and personal growth. Wolapp Cloud Client allows using the application. ..

    • File Name:wolapp-cloud.zip
    • Author:Rylstim
    • License:Freeware (Free)
    • File Size:932 Kb
    • Runs on:Mac OS X 10.5
  • Keyparc works on most computers - Windows, Linux and MacOSX. Keyparc enables you to work with your secret files as-if they are in plain. You do not need to change your current workflow nor learn to use it. Access your sensitive files in Keyparc. ..

    • File Name:Keyparc-MacOSX-Setup.dmg
    • Author:Bloombase Technologies
    • License:Freeware (Free)
    • File Size:7.1 Mb
    • Runs on:Mac OS X
  • PCGen is a FREE Open Source RPG character generator and maintenance program (d20 Systems mainly) that works on most personal computers (It's Java-based so: Windows, MacOSX, Linux, Unix are supported). All datafiles are ASCII so they can be modified. ..

    • File Name:pcgen5174_mac_install.dmg
    • Author:PCGen Team
    • License:Freeware (Free)
    • File Size:31.4 Mb
    • Runs on:Mac OS X
  • MAME OSX is a native MacOSX port of MAME, designed to take full advantage of OSX-specific. ..

    • File Name:mameosx-0.135.tgz
    • Author:mameosx
    • License:Freeware (Free)
    • File Size:16.94 Mb
    • Runs on:Mac
  • AquaTerm is a MacOSX grahics renderer. It allows command line applications written in ObjC, C, FORTRAN, Lisp, Perl or Python to display vector graphics, text and images using a simple API. Adapters for gnuplot, PGPLOT, and PLplot exists as. ..

    • File Name:aquaterm_src.1.0.1.tar.gz
    • Author:aquaterm
    • License:Freeware (Free)
    • File Size:299 Kb
    • Runs on:Mac

Related:Mac Os X Tetris - Tetris Mac - Tetris For Mac Os X - Tetris Mac Os X - Tetris Mac Download

Free Tetris App

Pages : 1 | 2 | 3>




broken image