tetris game

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

tetris game

Postby deepak_evil » Thu Sep 27, 2007 5:35 am

Code: Select all
import javax.microedition.lcdui.*;
import java.util.Random;
import javax.microedition.lcdui.game.*;
public class game2 extends GameCanvas implements Runnable {
private boolean isPlay; // Game Loop runs when isPlay is true
private long delay; // To give thread consistency
private Image  i1,i2,i3,i4,i5,i6;
private int ran,lop,a;
// Sprites to be used
private Sprite[] sprite;
// Layer Manager
private int index;
private Random random;
private LayerManager layerManager;
// Constructor and initialization
public game2() throws Exception {
super(true);
delay = 20;
lop=1;


// Load Images to Sprites
i1=Image.createImage("/pink.png");
i2=Image.createImage("/green.png");
i3=Image.createImage("/red.png");
i4=Image.createImage("/blue.png");
i5=Image.createImage("/cursor.png");
i6=Image.createImage("/yellow.png");
sprite=new Sprite[6];
sprite[0]=new Sprite(i1);
sprite[1]=new Sprite(i2);
sprite[2]=new Sprite(i3);
sprite[3]=new Sprite(i4);
sprite[4]=new Sprite(i5);
sprite[5]=new Sprite(i6);
layerManager = new LayerManager();
}
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() { isPlay = false; }
// Main Game Loop
public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
drawScreen(g);
player();
pos();
ran();
}

try { Thread.sleep(delay); }
catch (InterruptedException ie) {}
}
// Method to Handle User Inputs


// Method to Display Graphics
private void drawScreen(Graphics g) {
    g.setColor(255,255,255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0,0,0);
g.fillRect(0,getHeight()-10,getWidth(),20);
layerManager.paint(g,0,0);
flushGraphics();
}
public void player()
{
 
   // if(p1.getY()==getHeight()-p1.getHeight())
{
     
}
//else
{
   //p1.setPosition(0,i++);
}   


}
        private void input() {
int keyStates = getKeyStates();
{
    if ((keyStates & RIGHT_PRESSED) !=0 )
    {
     //   p5.move(2,0);
    }
    if ((keyStates & LEFT_PRESSED) !=0 )
    {
       // p5.move(-2,0);
    }
    if ((keyStates & UP_PRESSED) !=0 )
    {
    //    p5.move(0,-2);
    }
    if ((keyStates & DOWN_PRESSED) !=0 )
    {
      //  p5.move(0,2);       
         
    }
}

}
        public int ran()
        {
             random = new Random();
a = Math.abs(random.nextInt() % 6);   
return a;
        }
       
public void pos()
{
   
if(a==1)
{
//if(System.currentTimeMillis() -10 > 300) {
    layerManager.append(sprite[1]);     
    sprite[1].move(0,lop++);
}
else if(a==3)
{
//if(System.currentTimeMillis() -10 > 300) {
    layerManager.append(sprite[3]); 
    sprite[3].move(0,lop++);
}
else if(a==4)
{
//if(System.currentTimeMillis() -10 > 300) {
    layerManager.append(sprite[4]);     
    sprite[4].move(0,lop++);
}
}}
     //   }
       
//}

Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

midlet

Postby rahul7star » Tue Oct 23, 2007 4:36 pm

could u tell me wer is d code of ur midlet
rahul7star
Regular User
 
Posts: 84
Joined: Fri Aug 17, 2007 11:22 am


Return to J2ME Games

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron