zoukankan      html  css  js  c++  java
  • 3D效果的底面和围墙

    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();
            }
        }
    }
  • 相关阅读:
    转:【实用教程】阿里云服务器的配置和使用
    C# 定制错误页面
    C# Session进程外存储
    NOIP200101数的计算
    周末舞会
    queue 队列
    信息学作文
    求三个数的平均数
    Hello world
    Django-Form组件-forms.Form
  • 原文地址:https://www.cnblogs.com/tt-t/p/5757548.html
Copyright © 2011-2022 走看看