Code:
import javax.microedition.lcdui.*;
public class BattlingLordGame extends Canvas implements Runnable
{
private MidletMenu menu;
private Image map,mapcontd,greenmap,bluemap,redmap,flashmap;
public int first,kingchance=1;
public boolean msgprint=false,conquer=false;
public boolean chance=false,repeatchance=false,chanceover=true;
private Thread thread;
private final static int DELAY = 10*1000;
public BattlingLordGame(MidletMenu menu)
{
this.menu=menu;
first=0;
//Constantdeclaration.done=false;
try
{
map=Image.createImage("/mappart2.png");
mapcontd=Image.createImage("/mappartcontd.png");
greenmap=Image.createImage("/greenmap.png");
redmap=Image.createImage("/redmap.png");
bluemap=Image.createImage("/bluemap.png");
flashmap=Image.createImage("/flashmap.png");
thread = new Thread(this);
thread.start();
}
catch(Exception error)
{
Alert alert=new Alert("Err...","Cannot Open Image",null,AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
MidletMenu.display.setCurrent(alert);
}
}
protected void paint(Graphics g)
{
g.setColor(255,255,255);
g.fillRect(0, 0, getWidth(), getHeight());
/*Method1 for Midlet2 and Later*/
g.drawRegion(map, 0, 0, 42, 60, 0, 5, 40, Graphics.TOP|Graphics.LEFT); //1st Row 1st Col
g.drawRegion(greenmap, 55, 0, 120, 52, 0, 32, 06, Graphics.TOP|Graphics.LEFT);// 1st Row 2nd Col
g.drawRegion(map, 180, 0, 60, 60, 0, 130, 06, Graphics.TOP|Graphics.LEFT);//1st Row 3rd Col
g.drawRegion(redmap, 0, 65, 72,85, 0, 4,79, Graphics.TOP|Graphics.LEFT);//2nd Row 1st Col
g.drawRegion(map, 70, 65, 100, 60, 0, 40, 54, Graphics.TOP|Graphics.LEFT);//2nd Row 2nd Col
g.drawRegion(map, 170, 55, 70, 80, 0, 121, 35, Graphics.TOP|Graphics.LEFT);//2nd Row 3rd Col
g.drawRegion(map, 0, 153, 60,70, 0, 24,141 , Graphics.TOP|Graphics.LEFT);//3rd Row 1st Col
g.drawRegion(map, 55, 153, 120,70, 0, 40,99 , Graphics.TOP|Graphics.LEFT);//3rd Row 2nd Col
g.drawRegion(bluemap, 185, 153, 60,70, 0, 129,74 , Graphics.TOP|Graphics.LEFT);//3rd Row 3rd Col
g.drawRegion(map, 0, 230, 65, 90, 0, 62, 182, Graphics.TOP|Graphics.LEFT);//4th Row 1st Col
g.drawRegion(map, 55, 240, 100, 60, 0, 64, 154, Graphics.TOP|Graphics.LEFT);//4th Row 2nd Col
g.drawRegion(map, 170, 230, 100, 60, 0, 157, 105, Graphics.TOP|Graphics.LEFT);//4th Row 3rd Col
g.drawRegion(mapcontd, 0, 0, 120, 50, 0, 105, 179, Graphics.TOP|Graphics.LEFT);//1st Row 1st Col
g.drawRegion(mapcontd, 120, 0, 80, 40, 0, 170, 158, Graphics.TOP|Graphics.LEFT);//1st Row 2nd Col
g.drawRegion(mapcontd, 0, 60, 90, 90, 0, 92, 218, Graphics.TOP|Graphics.LEFT);//2nd Row 1st Col
g.drawRegion(mapcontd, 110, 60, 120, 90, 0, 156, 194, Graphics.TOP|Graphics.LEFT);//2nd Row 2nd Col
g.drawRegion(mapcontd,20,140,70,100,0,40,209,Graphics.TOP|Graphics.LEFT);//3rd Row 1st Col
g.drawRegion(mapcontd,108,140,120,100,0,132,230,Graphics.TOP|Graphics.LEFT);//3rd Row 2nd Col
g.setColor(0);
g.drawString("Pause",0,getHeight(),Graphics.LEFT|Graphics.BOTTOM);
//syntax
//g.drawRegion(image,ix(topleftcorner of image),iy(topleft corner of image),
//width,height,Sprite.TRANS_NONE,sx(screen position)
//,sy(screen poistion),Graphics.TOP|Graphics.LEFT);
if(msgprint==false)
{
g.setColor(0,0,0);
g.setFont(Constantdeclaration.largefont);
g.drawString("Your Turn", getWidth()/2, getHeight()/2, Graphics.TOP|Graphics.HCENTER);
}
g.drawString("Pause",0,getHeight(),Graphics.LEFT|Graphics.BOTTOM);
if(first==1)
{
if(conquer==true && chance==true)
g.drawRegion(greenmap, 0, 0, 42, 60, 0, 5, 40, Graphics.TOP|Graphics.LEFT); //1st Row 1st Col
else
g.drawRegion(flashmap, 0, 0, 42, 60, 0, 5, 40, Graphics.TOP|Graphics.LEFT); //1st Row 1st Col
chance=false;
}
if(first==2)
{
if(conquer==true && chance==true)
g.drawRegion(greenmap, 70, 65, 100, 60, 0, 40, 54, Graphics.TOP|Graphics.LEFT);//2nd Row 2nd Col
else
g.drawRegion(flashmap, 70, 65, 100, 60, 0, 40, 54, Graphics.TOP|Graphics.LEFT);//2nd Row 2nd Col
chance=false;
}
if(first==3)
{
if(conquer==true && chance==true)
g.drawRegion(greenmap, 180, 0, 60, 60, 0, 130, 06, Graphics.TOP|Graphics.LEFT);//1st Row 3rd Col
else
g.drawRegion(flashmap, 180, 0, 60, 60, 0, 130, 06, Graphics.TOP|Graphics.LEFT);//1st Row 3rd Col
chance=false;
}
if(chanceover==false)
{
g.drawRegion(redmap, 0, 153, 60,70, 0, 24,141 , Graphics.TOP|Graphics.LEFT);//3rd Row 1st Col
//thread.sleep(DELAY);
g.drawRegion(bluemap, 0, 230, 65, 90, 0, 62, 182, Graphics.TOP|Graphics.LEFT);//4th Row 1st Col
}
/* Method2 for Midlet1*/
//g.setClip(30, 40, 40, 60);
//g.drawImage(map, 30-0, 40-0, Graphics.TOP|Graphics.LEFT);
//syntax
//sy,sx=screen position where images is pasted
//ix,iy=image clipping i.e topleft corner
//g.setClip(sx, sy, width, height);
//g.drawImage(img, sx - ix, sy - iy, Graphics.TOP | Grapics.LEFT);
}
protected void keyPressed(int key)
{
msgprint=true;
switch(key)
{
case KEY_NUM4:
if(repeatchance==false)
first=1;
break;
case KEY_NUM8:
if(repeatchance==false)
first=2;
break;
case KEY_NUM6:
if(repeatchance==false)
first=3;
break;
case KEY_NUM5:
conquer=true;
chance=true;
repeatchance=true;
break;
case -21:
Constantdeclaration.PAUSE=true;
MainMenu displaymain=new MainMenu(menu);
MidletMenu.display.setCurrent(displaymain);
}
repaint();
}
public void run()
{
long endTime = System.currentTimeMillis() + DELAY;
while (System.currentTimeMillis() < endTime)
{
try
{
Thread.sleep(DELAY);
}
catch (Exception error)
{
// ignore
}
}
gotoChance();
}
private void gotoChance()
{
if(chance==false)
{
chanceover=false;
}
repaint();
}
}
Now after running this code i m able to draw the greenmap properly and after some time i wanna draw the remap and after the redmap is drawn after some time the bluemap should be drawn. Now as i have written the same condition for both the region i want to introduce some delay between the redmap and bluemap region so that after redmap is drawn the bluemap should be drawn after some time.