⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridaction.java

📁 用JAVA实现的九方格问题
💻 JAVA
字号:
/*
 * GridAction.java
 *
 * Created on 2006年12月10日, 下午8:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ninegrids;


public class GridAction {
    int ArrayNum=3,i,j,x,y,index,temp;
    int[][] GridArray=new int[3][3];

    public void MoveUp(){
        if(x-1<0){
          //
        }else{
            temp=0;
            temp=GridArray[x-1][y];
            GridArray[x-1][y]=GridArray[x][y];
            GridArray[x][y]=temp;
        }
    }
    public void MoveDown(){
        if(x+1>2){
           //
        }else{
            temp=0;
            temp=GridArray[x+1][y];
            GridArray[x+1][y]=GridArray[x][y];
            GridArray[x][y]=temp;
        }
    }
    public void MoveLeft(){
        if(y-1<0){
            //
        }else{
            temp=0;
            temp=GridArray[x][y-1];
            GridArray[x][y-1]=GridArray[x][y];
            GridArray[x][y]=temp;
        }
    }
    public void MoveRight(){
        if(y+1>2){
            //
        }else{
            temp=0;
            temp=GridArray[x][y+1];
            GridArray[x][y+1]=GridArray[x][y];
            GridArray[x][y]=temp;
        }
    }
 
    /** Creates a new instance of GridAction */
    public GridAction(int[][] Array,int x,int y,int index) {
        
        for(i=0;i<ArrayNum;++i){
             for(j=0;j<ArrayNum;++j){
                 GridArray[i][j]=Array[i][j];
             }
         }
        this.x=x;
        this.y=y;
        this.index=index;
         switch(index){
          case 0: 
                break;
            case 1:
                MoveUp();
                break;
            case 2:
                MoveDown();
                break;
            case 3:
                MoveLeft();
                break;
            case 4:
                MoveRight();
                break;
        }
        
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -