码迷,mamicode.com
首页 > 其他好文 > 详细

3D效果的底面和围墙

时间:2016-08-10 17:38:16      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

public class SnakePanel extends JPanel{
    private static final long serialVersionUID = 1L;
    int x_width = 40;
    int y_height = 30;
    boolean[][]map = new boolean[y_height][x_width];
    
    void initMap(){
        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[i].length; j++) {
                if(i==0 || i==map.length-1 || j==0 || j==map[i].length-1)
                    map[i][j] = true;
                //else
                //    map[i][j] = false;默认为false
            }
        }
    }
    
    int cell_width = 20;
    int cell_height = 20;
    @Override
    public void paint(Graphics g) {    
        super.paint(g);
        //外层循环控制的是行数即当前坐标的纵坐标y
        for (int i = 0; i < map.length; i++) {
            //内层循环控制的是列数即当前坐标的横坐标x
            for (int j = 0; j < map[i].length; j++) {
                  if(map[i][j])    
                       g.setColor(Color.DARK_GRAY);
                  else
                      g.setColor(Color.WHITE);
                  g.fill3DRect(j*cell_width, i*cell_height, cell_width, cell_height, true);
            }
        }
        
        
    }
    
    public static void main(String[] args) {
        SnakePanel sp = new SnakePanel();
        for (int i = 0; i < sp.map.length; i++) {
            for (int j = 0; j < sp.map[i].length; j++) {
                System.out.print(sp.map[i][j]);
            }
            System.out.println();
        }
    }
}

 

3D效果的底面和围墙

标签:

原文地址:http://www.cnblogs.com/tt-t/p/5757548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!