MarioGameCanvas.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:25k
源码类别:

J2ME

开发平台:

Java

  1. /**
  2.  * <p>Title: Mario</p>
  3.  * <p>Description:
  4.  * You cannot remove this copyright and notice.
  5.  * You cannot use this file any part without the express permission of the author.
  6.  * All Rights Reserved</p>
  7.  * <p>Copyright: lizhenpeng (c) 2004</p>
  8.  * <p>Company: LP&P</p>
  9.  * @author lizhenpeng
  10.  * @version 1.0.0
  11.  */
  12. package mario;
  13. import java.io.*;
  14. import java.util.*;
  15. import javax.microedition.lcdui.*;
  16. import lipeng.*;
  17. public class MarioGameCanvas
  18.   extends Canvas
  19.   implements Runnable,CommandListener,LPIGameStart
  20. {
  21.   // method
  22.   public MarioGameCanvas(MarioMIDlet midlet)
  23.   {
  24.     this.setFullScreenMode(true);
  25.     this.midlet=midlet;
  26.     this.width=this.getWidth();
  27.     this.height=this.getHeight();
  28.     setCommandListener(this);
  29.     this.addCommand(mainMenu);
  30.     dm=new LPDrawManage(width,height);
  31.     if(record.IsEmpty())
  32.     {
  33.       try
  34.       {
  35.         ByteArrayOutputStream baos=new ByteArrayOutputStream();
  36.         DataOutputStream dos=new DataOutputStream(baos);
  37.         dos.writeInt(1);
  38.         this.record.addRecord(baos.toByteArray());
  39.         dos.close();
  40.         baos.close();
  41.       }
  42.       catch(Exception e)
  43.       {
  44.         System.out.println("byte write error");
  45.       }
  46.     }
  47.     loadGameResource(0);
  48.     imMainSmall16=new LPImageManage("small16.png");
  49.     imMainNormal32=new LPImageManage("normal32.png");
  50.     imMainFire32=new LPImageManage("fire32.png");
  51.     imSprite8=new LPImageManage("sprite8.png");
  52.     imSprite16=new LPImageManage("sprite16.png");
  53.     imEnemy24=new LPImageManage("enemy24.png");
  54.     imSprite48=new LPImageManage("sprite48.png");
  55.     gm=new MarioGameManage(this);
  56.     gm.gameState=MarioGameManage.GAMESTATE_MENU;
  57.   }
  58.   private void loadMap(String fileName,char MapArray[][],int width,int height)
  59.   {
  60.     InputStream inStream=getClass().getResourceAsStream("/"+fileName);
  61.     DataInputStream in=new DataInputStream(inStream);
  62.     int i;
  63.     try
  64.     {
  65.       for(i=0;i<height;i++)
  66.       {
  67.         for(int j=0;j<width;j++)
  68.         {
  69.           MapArray[i][j]=in.readChar();
  70.         }
  71.       }
  72.       in.close();
  73.     }
  74.     catch(IOException e)
  75.     {
  76.       System.out.println("read map file"+fileName+" error!");
  77.       System.out.println(e.toString());
  78.     }
  79.   }
  80.   public void loadGameResource(int level)
  81.   {
  82.     int i,j;
  83.     imMap=new LPImageManage("level_2_1.png");
  84.     mapData=this.level_1_map;
  85.     map=new LPMaps(imMap,mapData,32,20,16,"level_2_1");
  86.     map.x=0;
  87.     map.y=0;
  88.     if(gm!=null&&gm.mainSprite!=null)
  89.     {
  90.       gm.mainSprite.judgeMap=map;
  91.     }
  92.   }
  93.   public void commandAction(Command c,Displayable d)
  94.   {
  95.     if(c==mainMenu)
  96.     {
  97.       removeCommand(mainMenu);
  98.       addCommand(back);
  99.       this.saveGameState=gm.gameState;
  100.       gm.gameState=MarioGameManage.GAMESTATE_MENU;
  101.       this.isSaveState=true;
  102.       gm.menu.init();
  103.     }
  104.     if(c==back)
  105.     {
  106.       removeCommand(back);
  107.       addCommand(mainMenu);
  108.       gm.gameState = MarioGameManage.GAMESTATE_GAMELOOP;
  109.     }
  110.   }
  111.   public void run()
  112.   {
  113.     try
  114.     {
  115.       Thread currentThread=Thread.currentThread();
  116.       while(currentThread==gameThread)
  117.       {
  118.         startTime=System.currentTimeMillis();
  119.         switch(gm.gameState)
  120.         {
  121.           case MarioGameManage.GAMESTATE_MENU:
  122.             gm.menu.action();
  123.             break;
  124.           case MarioGameManage.GAMESTATE_GAMELOOP:
  125.             gm.action();
  126.             break;
  127.           case MarioGameManage.GAMESTATE_PAUSE:
  128.             break;
  129.           case MarioGameManage.GAMESTATE_REINIT:
  130.             gm.reInit();
  131.             break;
  132.         }
  133.         repaint(0,0,width,height);
  134.         serviceRepaints();
  135.         endTime=System.currentTimeMillis();
  136.         if((endTime-startTime)<FRAME_TIME)
  137.         {
  138.           Thread.sleep(FRAME_TIME-(endTime-startTime));
  139.         }
  140.       }
  141.     }
  142.     catch(InterruptedException ie)
  143.     {
  144.       System.out.println(ie.toString());
  145.     }
  146.   }
  147.   public void paint(Graphics g)
  148.   {
  149.     switch(gm.gameState)
  150.     {
  151.       case MarioGameManage.GAMESTATE_MENU:
  152.         switch(gm.menu.menuState)
  153.         {
  154.           case LPMenu.MENU_STATE_MAIN:
  155.             drawMainMenuScreen(g);
  156.             break;
  157.         }
  158.         break;
  159.       case MarioGameManage.GAMESTATE_GAMELOOP:
  160.         drawGameLoopScreen(g);
  161.         break;
  162.       case MarioGameManage.GAMESTATE_PAUSE:
  163.         drawPauseScreen(g);
  164.         break;
  165.       case MarioGameManage.GAMESTATE_REINIT:
  166.         drawTryAgainScreen(g);
  167.         break;
  168.     }
  169.   }
  170.   private void drawTryAgainScreen(Graphics g)
  171.   {
  172.     int offset=(height-font.getHeight()*2)/2;
  173.     g.setColor(0,0,0);
  174.     g.fillRect(0,0,width,height);
  175.     g.setFont(font);
  176.     g.setColor(255,0,0);
  177.     g.drawString("准备好!",(width-font.stringWidth("准备好!"))/2,
  178.                  offset+font.getHeight()*0,g.LEFT|g.TOP);
  179.     g.drawString("再来一次",(width-font.stringWidth("准备好!"))/2,
  180.                  offset+font.getHeight()*1,g.LEFT|g.TOP);
  181.   }
  182.   public void loadSaveState()
  183.   {
  184.     try
  185.     {
  186.       int i,j;
  187.       byte[] rec=record.getRecord(1);
  188.       ByteArrayInputStream bais=new ByteArrayInputStream(rec);
  189.       DataInputStream dis=new DataInputStream(bais);
  190.       gm.initGameState();
  191.       gm.goldNum=dis.readInt();
  192.       loadGameResource(1);
  193.       gm.mainSprite.judgeMap.x=dis.readInt();
  194.       gm.mainSprite.judgeMap.y=dis.readInt();
  195.       for(i=gm.mainSprite.judgeMap.mapArray.length-1;i>=0;--i)
  196.       {
  197.         for(j=gm.mainSprite.judgeMap.mapArray[i].length-1;j>=0;--j)
  198.         {
  199.           gm.mainSprite.judgeMap.mapArray[i][j]=dis.readChar();
  200.         }
  201.       }
  202.       gm.initLevel_1_1();
  203.       for(i=dis.readInt()-1;i>=0;--i)
  204.       {
  205.         gm.brick[i].readData(dis);
  206.       }
  207.       for(i=dis.readInt()-1;i>=0;--i)
  208.       {
  209.         gm.brokenBrick[i].readData(dis);
  210.       }
  211.       for(i=dis.readInt()-1;i>=0;--i)
  212.       {
  213.         gm.bullet[i].readData(dis);
  214.       }
  215.       for(i=dis.readInt()-1;i>=0;--i)
  216.       {
  217.         gm.enemy[i].readData(dis);
  218.       }
  219.       for(i=dis.readInt()-1;i>=0;--i)
  220.       {
  221.         gm.tortoise[i].readData(dis);
  222.       }
  223.       for(i=dis.readInt()-1;i>=0;--i)
  224.       {
  225.         gm.bridge[i].readData(dis);
  226.       }
  227.       for(i=dis.readInt()-1;i>=0;--i)
  228.       {
  229.         gm.gold[i].readData(dis);
  230.       }
  231.       for(i=dis.readInt()-1;i>=0;--i)
  232.       {
  233.         gm.mashRooms[i].readData(dis);
  234.       }
  235.       for(i=dis.readInt()-1;i>=0;--i)
  236.       {
  237.         gm.flowers[i].readData(dis);
  238.       }
  239.       for(i=dis.readInt()-1;i>=0;--i)
  240.       {
  241.         gm.stick[i].readData(dis);
  242.       }
  243.       for(i=dis.readInt()-1;i>=0;--i)
  244.       {
  245.         gm.staticGold[i].readData(dis);
  246.       }
  247.       for(i=dis.readInt()-1;i>=0;--i)
  248.       {
  249.         gm.ugGold[i].readData(dis);
  250.       }
  251.       for(i=dis.readInt()-1;i>=0;--i)
  252.       {
  253.         gm.ugBrick[i].readData(dis);
  254.       }
  255.       gm.mainSprite.readData(dis);
  256.       dis.close();
  257.       bais.close();
  258.     }
  259.     catch(Exception e)
  260.     {
  261.       System.out.println("read state error");
  262.     }
  263.   }
  264.   private void drawGameLoopScreen(Graphics g)
  265.   {
  266.     int i;
  267.     g.setClip(0,0,gm.canvas.width,gm.canvas.height);
  268.     dm.drawMaps(g,gm.mainSprite.judgeMap);
  269.     dm.drawSprite(g,imSprite8,gm.brokenBrick);
  270.     dm.drawSprite(g,imSprite16,gm.brick);
  271.     dm.drawSprite(g,imSprite16,gm.gold);
  272.     for(i=gm.mashRooms.length-1;i>=0;--i)
  273.     {
  274.       gm.mashRooms[i].draw(g,imSprite16);
  275.     }
  276.     for(i=gm.flowers.length-1;i>=0;--i)
  277.     {
  278.       gm.flowers[i].draw(g,imSprite16);
  279.     }
  280.     dm.drawSprite(g,imEnemy24,gm.tortoise);
  281.     dm.drawSprite(g,imSprite16,gm.staticGold);
  282.     dm.drawSprite(g,imSprite48,gm.stick);
  283.     dm.drawSprite(g,imSprite8,gm.bullet);
  284.     dm.drawSprite(g,imSprite16,gm.bridge);
  285.     switch(gm.mainSprite.mainSpriteState)
  286.     {
  287.       case MarioMainSprite.SMALL_SPRITE:
  288.       case MarioMainSprite.DEAD_SPRITE:
  289.         dm.drawSprite(g,imMainSmall16,gm.mainSprite);
  290.         break;
  291.       case MarioMainSprite.NORMAL_SPRITE:
  292.         dm.drawSprite(g,imMainNormal32,gm.mainSprite);
  293.         break;
  294.       case MarioMainSprite.FIRE_SPRITE:
  295.         dm.drawSprite(g,imMainFire32,gm.mainSprite);
  296.         break;
  297.       case MarioMainSprite.GROW_SPRITE:
  298.         if(gm.mainSprite.growCnt%2==0)
  299.         {
  300.           dm.drawSprite(g,imMainSmall16,gm.mainSprite);
  301.         }
  302.         else
  303.         {
  304.           dm.drawSprite(g,imMainNormal32,gm.mainSprite);
  305.         }
  306.         break;
  307.       case MarioMainSprite.BECOME_SMALL:
  308.         if(gm.mainSprite.becomeCnt%2==0)
  309.         {
  310.           dm.drawSprite(g,imMainNormal32,gm.mainSprite);
  311.         }
  312.         else
  313.         {
  314.           dm.drawSprite(g,imMainSmall16,gm.mainSprite);
  315.         }
  316.         break;
  317.       case MarioMainSprite.BECOME_FIRE:
  318.         if(gm.mainSprite.becomeCnt%2==0)
  319.         {
  320.           dm.drawSprite(g,imMainNormal32,gm.mainSprite);
  321.         }
  322.         else
  323.         {
  324.           dm.drawSprite(g,imMainFire32,gm.mainSprite);
  325.         }
  326.         break;
  327.     }
  328.     g.setClip(0,0,gm.canvas.width,gm.canvas.height);
  329.   }
  330.   private void drawMainMenuScreen(Graphics g)
  331.   {
  332.     int menuOffset=(height-font.getHeight()*4)/2;
  333.     int tmpY=0;
  334.     g.setFont(font);
  335.     g.setClip(0,0,width,height);
  336.     dm.drawMaps(g,map);
  337.     g.setClip(0,0,width,height);
  338.     switch(gm.menu.whichActive)
  339.     {
  340.       case LPMenu.MENU_NEW_GAME:
  341.         g.setColor(255,0,0);
  342.         g.drawString("新游戏",(width-font.stringWidth("新游戏"))/2,
  343.                      menuOffset+font.getHeight()*0,g.LEFT|g.TOP);
  344.         g.setColor(255,255,255);
  345.         g.drawString("载入进度",(width-font.stringWidth("载入进度"))/2,
  346.                      menuOffset+font.getHeight()*1,g.LEFT|g.TOP);
  347.         g.setColor(255,255,255);
  348.         if(gm.menu.isVolOn)
  349.         {
  350.           g.drawString("声音开",(width-font.stringWidth("声音开"))/2,
  351.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  352.         }
  353.         else
  354.         {
  355.           g.drawString("声音关",(width-font.stringWidth("声音关"))/2,
  356.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  357.         }
  358.         g.setColor(255,255,255);
  359.         g.drawString("退出",(width-font.stringWidth("退出"))/2,
  360.                      menuOffset+font.getHeight()*3,g.LEFT|g.TOP);
  361.         g.setColor(255,255,255);
  362.         g.drawString("关于",(width-font.stringWidth("关于"))/2,
  363.                      menuOffset+font.getHeight()*4,g.LEFT|g.TOP);
  364.         break;
  365.       case LPMenu.MENU_LOAD_GAME:
  366.         g.setColor(255,255,255);
  367.         g.drawString("新游戏",(width-font.stringWidth("新游戏"))/2,
  368.                      menuOffset+font.getHeight()*0,g.LEFT|g.TOP);
  369.         g.setColor(255,0,0);
  370.         g.drawString("载入进度",(width-font.stringWidth("载入进度"))/2,
  371.                      menuOffset+font.getHeight()*1,g.LEFT|g.TOP);
  372.         g.setColor(255,255,255);
  373.         if(gm.menu.isVolOn)
  374.         {
  375.           g.drawString("声音开",(width-font.stringWidth("声音开"))/2,
  376.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  377.         }
  378.         else
  379.         {
  380.           g.drawString("声音关",(width-font.stringWidth("声音关"))/2,
  381.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  382.         }
  383.         g.setColor(255,255,255);
  384.         g.drawString("退出",(width-font.stringWidth("退出"))/2,
  385.                      menuOffset+font.getHeight()*3,g.LEFT|g.TOP);
  386.         g.setColor(255,255,255);
  387.         g.drawString("关于",(width-font.stringWidth("关于"))/2,
  388.                      menuOffset+font.getHeight()*4,g.LEFT|g.TOP);
  389.         break;
  390.       case LPMenu.MENU_VOL:
  391.         g.setColor(255,255,255);
  392.         g.drawString("新游戏",(width-font.stringWidth("新游戏"))/2,
  393.                      menuOffset+font.getHeight()*0,g.LEFT|g.TOP);
  394.         g.setColor(255,255,255);
  395.         g.drawString("载入进度",(width-font.stringWidth("载入进度"))/2,
  396.                      menuOffset+font.getHeight()*1,g.LEFT|g.TOP);
  397.         g.setColor(255,0,0);
  398.         if(gm.menu.isVolOn)
  399.         {
  400.           g.drawString("声音开",(width-font.stringWidth("声音开"))/2,
  401.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  402.         }
  403.         else
  404.         {
  405.           g.drawString("声音关",(width-font.stringWidth("声音关"))/2,
  406.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  407.         }
  408.         g.setColor(255,255,255);
  409.         g.drawString("退出",(width-font.stringWidth("退出"))/2,
  410.                      menuOffset+font.getHeight()*3,g.LEFT|g.TOP);
  411.         g.setColor(255,255,255);
  412.         g.drawString("关于",(width-font.stringWidth("关于"))/2,
  413.                      menuOffset+font.getHeight()*4,g.LEFT|g.TOP);
  414.         break;
  415.       case LPMenu.MENU_EXIT:
  416.         g.setColor(255,255,255);
  417.         g.drawString("新游戏",(width-font.stringWidth("新游戏"))/2,
  418.                      menuOffset+font.getHeight()*0,g.LEFT|g.TOP);
  419.         g.setColor(255,255,255);
  420.         g.drawString("载入进度",(width-font.stringWidth("载入进度"))/2,
  421.                      menuOffset+font.getHeight()*1,g.LEFT|g.TOP);
  422.         g.setColor(255,255,255);
  423.         if(gm.menu.isVolOn)
  424.         {
  425.           g.drawString("声音开",(width-font.stringWidth("声音开"))/2,
  426.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  427.         }
  428.         else
  429.         {
  430.           g.drawString("声音关",(width-font.stringWidth("声音关"))/2,
  431.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  432.         }
  433.         g.setColor(255,0,0);
  434.         g.drawString("退出",(width-font.stringWidth("退出"))/2,
  435.                      menuOffset+font.getHeight()*3,g.LEFT|g.TOP);
  436.         g.setColor(255,255,255);
  437.         g.drawString("关于",(width-font.stringWidth("关于"))/2,
  438.                      menuOffset+font.getHeight()*4,g.LEFT|g.TOP);
  439.         break;
  440.       case LPMenu.MENU_ABOUT:
  441.         g.setColor(255,255,255);
  442.         g.drawString("新游戏",(width-font.stringWidth("新游戏"))/2,
  443.                      menuOffset+font.getHeight()*0,g.LEFT|g.TOP);
  444.         g.setColor(255,255,255);
  445.         g.drawString("载入进度",(width-font.stringWidth("载入进度"))/2,
  446.                      menuOffset+font.getHeight()*1,g.LEFT|g.TOP);
  447.         g.setColor(255,255,255);
  448.         if(gm.menu.isVolOn)
  449.         {
  450.           g.drawString("声音开",(width-font.stringWidth("声音开"))/2,
  451.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  452.         }
  453.         else
  454.         {
  455.           g.drawString("声音关",(width-font.stringWidth("声音关"))/2,
  456.                        menuOffset+font.getHeight()*2,g.LEFT|g.TOP);
  457.         }
  458.         g.setColor(255,255,255);
  459.         g.drawString("退出",(width-font.stringWidth("退出"))/2,
  460.                      menuOffset+font.getHeight()*3,g.LEFT|g.TOP);
  461.         g.setColor(255,0,0);
  462.         g.drawString("关于",(width-font.stringWidth("关于"))/2,
  463.                      menuOffset+font.getHeight()*4,g.LEFT|g.TOP);
  464.         break;
  465.     }
  466.   }
  467.   private void drawPauseScreen(Graphics g)
  468.   {
  469.     g.setFont(font);
  470.     g.setClip(0,0,width,height);
  471.     g.setColor(0,0,0);
  472.     g.fillRect(0,0,width,height);
  473.     g.setColor(255,0,0);
  474.     g.drawString("暂停中……",(width-font.stringWidth("暂停中……"))/2,
  475.                  height/2,g.LEFT|g.TOP);
  476.   }
  477.   private void drawGameOverScreen(Graphics g)
  478.   {
  479.     dm.drawMaps(g,this.map);
  480.     g.setClip(0,0,width,height);
  481.     g.setFont(font);
  482.     g.setColor(255,0,0);
  483.     g.drawString("游戏结束",(width-font.stringWidth("游戏结束"))/2,
  484.                  height/2,g.LEFT|g.TOP);
  485.   }
  486.   public void stop()
  487.   {
  488.     gameThread=null;
  489.   }
  490.   public void start()
  491.   {
  492.     gm.menu.allAction=0;
  493.     switch(gm.gameState)
  494.     {
  495.       case MarioGameManage.GAMESTATE_MENU:
  496.         if(gm.menu.isVolOn)
  497.         {
  498.           gm.bgPlayer.play();
  499.         }
  500.         break;
  501.       case MarioGameManage.GAMESTATE_GAMELOOP:
  502.       case MarioGameManage.GAMESTATE_PAUSE:
  503.       case MarioGameManage.GAMESTATE_REINIT:
  504.         break;
  505.     }
  506.     gameThread=new Thread(this);
  507.     gameThread.start();
  508.   }
  509.   public boolean isPressStar = false;
  510.   protected void keyPressed(int keyCode)
  511.   {
  512.     if(gm.gameState==MarioGameManage.GAMESTATE_GAMELOOP)
  513.     {
  514.       if(keyCode==Canvas.KEY_STAR)
  515.       {
  516.         if(!isPressStar)
  517.         {
  518.           isPressStar = true;
  519.         }
  520.       }
  521.     }
  522.     gm.judgeKeyCode(keyCode,getGameAction(keyCode));
  523.   }
  524.   protected void keyReleased(int keyCode)
  525.   {
  526.     gm.freeKey(keyCode,getGameAction(keyCode));
  527.   }
  528.   public void saveCurrentState()
  529.   {
  530.     try
  531.     {
  532.       ByteArrayOutputStream baos=new ByteArrayOutputStream();
  533.       DataOutputStream dos=new DataOutputStream(baos);
  534.       int i,j;
  535.       dos.writeInt(gm.goldNum);
  536.       dos.writeInt(gm.mainSprite.judgeMap.x);
  537.       dos.writeInt(gm.mainSprite.judgeMap.y);
  538.       for(i=gm.mainSprite.judgeMap.mapArray.length-1;i>=0;--i)
  539.       {
  540.         for(j=gm.mainSprite.judgeMap.mapArray[i].length-1;j>=0;--j)
  541.         {
  542.           dos.writeChar(gm.mainSprite.judgeMap.mapArray[i][j]);
  543.         }
  544.       }
  545.       dos.writeInt(gm.brick.length);
  546.       for(i=gm.brick.length-1;i>=0;--i)
  547.       {
  548.         gm.brick[i].writeData(dos);
  549.       }
  550.       dos.writeInt(gm.brokenBrick.length);
  551.       for(i=gm.brokenBrick.length-1;i>=0;--i)
  552.       {
  553.         gm.brokenBrick[i].writeData(dos);
  554.       }
  555.       dos.writeInt(gm.bullet.length);
  556.       for(i=gm.bullet.length-1;i>=0;--i)
  557.       {
  558.         gm.bullet[i].writeData(dos);
  559.       }
  560.       dos.writeInt(gm.enemy.length);
  561.       for(i=gm.enemy.length-1;i>=0;--i)
  562.       {
  563.         gm.enemy[i].writeData(dos);
  564.       }
  565.       dos.writeInt(gm.tortoise.length);
  566.       for(i=gm.tortoise.length-1;i>=0;--i)
  567.       {
  568.         gm.tortoise[i].writeData(dos);
  569.       }
  570.       dos.writeInt(gm.bridge.length);
  571.       for(i=gm.bridge.length-1;i>=0;--i)
  572.       {
  573.         gm.bridge[i].writeData(dos);
  574.       }
  575.       dos.writeInt(gm.gold.length);
  576.       for(i=gm.gold.length-1;i>=0;--i)
  577.       {
  578.         gm.gold[i].writeData(dos);
  579.       }
  580.       dos.writeInt(gm.mashRooms.length);
  581.       for(i=gm.mashRooms.length-1;i>=0;--i)
  582.       {
  583.         gm.mashRooms[i].writeData(dos);
  584.       }
  585.       dos.writeInt(gm.flowers.length);
  586.       for(i=gm.flowers.length-1;i>=0;--i)
  587.       {
  588.         gm.flowers[i].writeData(dos);
  589.       }
  590.       dos.writeInt(gm.stick.length);
  591.       for(i=gm.stick.length-1;i>=0;--i)
  592.       {
  593.         gm.stick[i].writeData(dos);
  594.       }
  595.       dos.writeInt(gm.staticGold.length);
  596.       for(i=gm.staticGold.length-1;i>=0;--i)
  597.       {
  598.         gm.staticGold[i].writeData(dos);
  599.       }
  600.       dos.writeInt(gm.ugGold.length);
  601.       for(i=gm.ugGold.length-1;i>=0;--i)
  602.       {
  603.         gm.ugGold[i].writeData(dos);
  604.       }
  605.       dos.writeInt(gm.ugBrick.length);
  606.       for(i=gm.ugBrick.length-1;i>=0;--i)
  607.       {
  608.         gm.ugBrick[i].writeData(dos);
  609.       }
  610.       gm.mainSprite.writeData(dos);
  611.       this.record.SetRecord(1,baos.toByteArray());
  612.       dos.close();
  613.       baos.close();
  614.     }
  615.     catch(Exception e)
  616.     {
  617.       System.out.println("Save Data error");
  618.     }
  619.   }
  620.   public MarioMIDlet midlet;
  621.   public static int width;
  622.   public static int height;
  623.   public static Random rand=new Random(System.currentTimeMillis());
  624.   public LPSaveRecord record=new LPSaveRecord("lipeng_Mario");
  625.   public Command mainMenu=new Command("菜单",Command.OK,1);
  626.   public Command back=new Command("返回",Command.BACK,2);
  627.   public boolean isSaveState;
  628.   public int saveGameState;
  629.   public MarioGameManage gm;
  630.   public LPMaps map;
  631.   public char mapData[][]=null;
  632.   //private
  633.   private volatile Thread gameThread=null;
  634.   private long startTime;
  635.   private long endTime;
  636.   private LPDrawManage dm;
  637.   private Font font=Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD,
  638.                                  Font.SIZE_LARGE);
  639. // image resource
  640.   private LPImageManage imMap;
  641.   private LPImageManage imMainSmall16;
  642.   private LPImageManage imMainNormal32;
  643.   private LPImageManage imMainFire32;
  644.   private LPImageManage imSprite8;
  645.   private LPImageManage imSprite16;
  646.   private LPImageManage imEnemy24;
  647.   private LPImageManage imSprite48;
  648.   //final
  649.   private static final int FRAME_TIME=80;
  650.   static final char[][]  level_1_map=
  651.     {
  652.     {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  653.     {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  654.     {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  655.     {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0011,0x0013,0x0015,0x0017,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  656.     {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0012,0x0014,0x0016,0x0018,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  657.     {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0f26,0x0f26,0x0f26,0x0000,0x0000,0x0000,0x0000,},
  658.     {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  659.     {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0011,0x0013,0x0017,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  660.     {0x0019,0x0019,0x0019,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0012,0x0014,0x0018,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  661.     {0x001a,0x001a,0x001a,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0f26,0x0f26,0x0f26,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  662.     {0x001a,0x001f,0x001a,0x0000,0x0011,0x0013,0x0015,0x0015,0x0017,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0702,0x0702,0x0702,0x0702,0x0702,0x0702,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  663.     {0x001c,0x001c,0x001c,0x0019,0x0012,0x0014,0x0016,0x0016,0x0018,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  664.     {0x001a,0x001a,0x001a,0x001a,0x001a,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  665.     {0x001a,0x001a,0x001a,0x001f,0x001a,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  666.     {0x001c,0x001c,0x001c,0x001c,0x001c,0x0019,0x0019,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0f26,0x0f26,0x0f26,0x0f26,0x0f26,},
  667.     {0x001d,0x001a,0x001a,0x001a,0x001a,0x001a,0x001a,0x0000,0x0000,0x0000,0x0f26,0x0f26,0x0f26,0x0f26,0x0000,0x0000,0x0000,0x0000,0x0000,0x0f26,0x0f26,0x0000,0x0000,0x0000,0x0f26,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  668.     {0x001e,0x001a,0x001a,0x001a,0x001a,0x001a,0x001a,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x002b,0x0000,0x0703,0x0705,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  669.     {0x001e,0x001a,0x001a,0x001a,0x001d,0x001a,0x001a,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x002c,0x0000,0x0704,0x0706,0x0000,0x0029,0x0029,0x0029,0x0029,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,},
  670.     {0x001e,0x001a,0x001a,0x001a,0x001e,0x001a,0x001a,0x0000,0x0000,0x000d,0x000e,0x000f,0x0010,0x0000,0x002a,0x0000,0x0704,0x0706,0x0000,0x0029,0x0029,0x0029,0x0029,0x0000,0x0000,0x0000,0x0000,0x0027,0x0027,0x0027,0x0027,0x0027,},
  671.     {0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0701,0x0228,0x0228,0x0228,0x0228,0x0228,},
  672.     };
  673. }