| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1631 人关注过本帖
标题:简单的推箱子
只看楼主 加入收藏
立志学编程
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-1-8
收藏
 问题点数:0 回复次数:2 
简单的推箱子
//import
//
//import javax.microedition.midlet.MIDlet;
//import javax.microedition.lcdui.Canvas;
//import javax.microedition.lcdui.Graphics;
//import javax.microedition.lcdui.Display;
//import javax.microedition.lcdui.Image;
//public class Test extends MIDlet
//{
//    private Display dis = null;
//    private Gam ga = new Gam();
//    public Test()
//    {
//        dis = Display.getDisplay(this);
//    }
//    protected void startApp()
//    {
//        dis.setCurrent(ga);
//    }
//    protected void pauseApp()
//    {
//
//    }
//    protected void destroyApp(boolean arg0)
//    {
//
//    }
//}
//class Gam extends Canvas
//{
//    public final int LCD_WIDTH;
//    public final int LCD_HEIGHT;
//    public final int LCD_CENTERX;
//    public final int LCD_CENTERY;
//    public static final int KEY_UP = -1;
//    public static final int KEY_DOWN = -2;
//    public static final int KEY_LEFT = -3;
//    public static final int KEY_RIGHT = -4;
//
//    private int[][][] i_map =
//    {
//        {
//            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
//            {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
//            {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
//            {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
//            {0, 1, 0, 0, 0, 1, 0, 2, 0, 0, 1, 1, 0},
//            {0, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 1, 0},
//            {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0},
//            {0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
//            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
//        },
//        {
//            
//            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
//            {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
//            {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
//            {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
//            {0, 1, 0, 0, 0, 1, 0, 2, 0, 0, 1, 1, 0},
//            {0, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 1, 0},
//            {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0},
//            {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
//            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
//        },
//        {
//            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
//            {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
//            {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
//            {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
//            {0, 1, 0, 0, 0, 1, 0, 2, 0, 0, 1, 1, 0},
//            {0, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 1, 0},
//            {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
//            {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0},
//            {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
//            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
//        }
//    };
//    
//    
//    Gam()
//    {
//        LCD_WIDTH = getWidth();
//        LCD_HEIGHT = getHeight();
//        LCD_CENTERY = LCD_HEIGHT>>1;
//        LCD_CENTERX  =LCD_WIDTH>>1;
//    }
//    private int iZz=0;
//    private int i_menuNum = 0;
//    private int i_XiaBiaox = 5, i_XiaBiaoy = 3;
//    private int[][] weizhi = {{5, 6},{3, 4}};
//    public void paint(Graphics g)
//    {
//        
//        int i = 0, j = 0;
//        g.setColor(-1);
//        g.fillRect(0, 0, LCD_WIDTH, LCD_HEIGHT);
//
//        for(i = 0; i < 13; i++)
//        {
//            for(j = 0; j < 13; j++)
//            {
//                if(i_map[iZz][i][j] == 1)
//                {
//                    g.setColor(0);
//                }
//                else if(i_map[iZz][i][j] == 2)
//                {
//                    g.setColor(0xFF0000);    
//                }
//                else
//                {
//                    g.setColor(-1);
//                }
//                g.fillRect(j * 20, i * 20, 20, 20);    
//            }
//        }
//        boolean isG = true;
//        for(i = 0; i < weizhi.length; i++)
//        {
//            if(i_map[iZz][weizhi[i][1]][weizhi[i][0]] != 2)
//            {
//                g.setColor(0xFFFF);
//                g.fillRect(weizhi[i][0] * 20, weizhi[i][1] * 20, 20, 20);
//                isG =false;    
//            }
//        }
//        if(isG)
//        {
//            iZz++;
//            repaint();
//        }
//        
//        g.setColor(0xFF);
//        g.fillArc(i_XiaBiaox * 20, i_XiaBiaoy * 20, 20, 20, 0, 360);
//    }
//
//    protected void keyPressed(int keyCode)
//    {
//        
//        
//        switch(keyCode)
//        {
//            case -1:
//                if(i_map[iZz][i_XiaBiaoy - 1][i_XiaBiaox] == 0)
//                {
//                    --i_XiaBiaoy;
//                }
//                else if(i_map[iZz][i_XiaBiaoy - 1][i_XiaBiaox] == 2
//                        && i_map[iZz][i_XiaBiaoy - 2][i_XiaBiaox] == 0)
//                {
//                    i_map[iZz][i_XiaBiaoy - 2][i_XiaBiaox] = 2;
//                    i_map[iZz][i_XiaBiaoy - 1][i_XiaBiaox] = 0;
//                    --i_XiaBiaoy;
//                }
//                break;
//            case -2:
//                if(i_map[iZz][i_XiaBiaoy + 1][i_XiaBiaox] == 0)
//                {
//                    ++i_XiaBiaoy;
//                }
//                else if(i_map[iZz][i_XiaBiaoy + 1][i_XiaBiaox] == 2
//                        && i_map[iZz][i_XiaBiaoy + 2][i_XiaBiaox] == 0)
//                {
//                    i_map[iZz][i_XiaBiaoy + 2][i_XiaBiaox] = 2;
//                    i_map[iZz][i_XiaBiaoy + 1][i_XiaBiaox] = 0;
//                    ++i_XiaBiaoy;
//                }
//                break;
//            case -3:
//                if(i_map[iZz][i_XiaBiaoy][i_XiaBiaox - 1] == 0)
//                {
//                    --i_XiaBiaox;
//                }
//                else if(i_map[iZz][i_XiaBiaoy][i_XiaBiaox - 1] == 2
//                        && i_map[iZz][i_XiaBiaoy][i_XiaBiaox - 2] == 0)
//                {
//                    i_map[iZz][i_XiaBiaoy][i_XiaBiaox - 2] = 2;
//                    i_map[iZz][i_XiaBiaoy][i_XiaBiaox - 1] = 0;
//                    --i_XiaBiaox;
//                }
//                break;
//            case -4:
//                if(i_map[iZz][i_XiaBiaoy][i_XiaBiaox + 1] == 0)
//                {
//                    ++i_XiaBiaox;
//                }
//                else if(i_map[iZz][i_XiaBiaoy][i_XiaBiaox + 1] == 2
//                        && i_map[iZz][i_XiaBiaoy][i_XiaBiaox + 2] == 0)
//                {
//                    i_map[iZz][i_XiaBiaoy][i_XiaBiaox + 2] = 2;
//                    i_map[iZz][i_XiaBiaoy][i_XiaBiaox + 1] = 0;
//                    ++i_XiaBiaox;
//                }
//                break;
//        }
//        repaint();
//    }
//}
搜索更多相关主题的帖子: 箱子 
2008-01-08 01:56
linsua
Rank: 1
等 级:新手上路
帖 子:275
专家分:0
注 册:2008-1-2
收藏
得分:0 
怎么都是注释了

如果你对我的话感到再明白不过 那恐怕你是误解了我的意思
2008-01-09 04:15
天涯海角
Rank: 2
等 级:新手上路
威 望:3
帖 子:507
专家分:0
注 册:2005-10-21
收藏
得分:0 
学习了,谢谢。

我的未来不是梦!
2008-03-09 13:07
快速回复:简单的推箱子
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021240 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved