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

📄 state.java

📁 The game tetris on java with using concurrent lib
💻 JAVA
字号:
package homeTask_14_tetris;


import java.awt.Point;


public class State implements Cloneable{
	
	
	static final int  WIDTH = 10;
	static final int  HEIGHT = 25;
	

    static  final  int L_CORNER   = 11;
    static  final  int R_CORNER   = 12;
    static  final  int LOG        = 13;
    static  final  int L_ZIGZAG   = 14;
    static  final  int R_ZIGZAG   = 15;
    static  final  int SQUARE     = 16;
    static  final  int AWNING     = 17;
   
    private  int     figureType;
    private  int     level ; 
    private  int     countFigureRotate;
    private  int     Points;
    private  int     StateOfGame;
    // END =1; Start=0;
    private  int WholeRemoveRows;
	private int[][] field = new int[WIDTH][HEIGHT];


    private   Point[] figure_parts = new Point[4];
	private  Point CentrefigurePosition = new Point(WIDTH / 2, 0);

	public int[][] getField() {
		return field;
	}

	public   Point[] getFigure() {
		return figure_parts;
	}

	public void setField(int[][] field) {
		this.field = field;
	}

	public void setFigure(Point[] figure) {
		this.figure_parts = figure;
	}

	public void setFigurePosition(Point figurePosition) {
		this.CentrefigurePosition = figurePosition;
	}

	public  Point getFigurePosition() {
		return CentrefigurePosition;
	}


	
	public  void setFigureType(int figureTyp) {
		figureType = figureTyp;
		initFigure();
	}


	public int getFigureType() {
		return figureType;
	}

	public  void setcountFigureRotate(int countfigureRot) {
		countFigureRotate = countfigureRot;
	}

	public int getcountFigureRotate() {
		return countFigureRotate;
	}
	
	public void setLevel(int level) {
		this.level = level;
		
	}

	public int getLevel() {
		return level;
	}
	
	public void setPoints(int points) {
		Points = points;
	}
	
	public int getPoints() {
		return Points;
	}
	
	public void setStateOfGame(int stateOfGame) {
		StateOfGame = stateOfGame;
	}

	public int getStateOfGame() {
		return StateOfGame;
	} 
	
	public void setWholeRemoveRows(int wholeRemoveRows) {
		WholeRemoveRows = wholeRemoveRows;
	}

	public int getWholeRemoveRows() {
		return WholeRemoveRows;
	}
	
	private   void initFigure() {
		 switch (figureType) 
	    	{
	    	   
	    	    
                case L_CORNER : figure_parts[0] = new Point(0, 0);
	                            figure_parts[1] = new Point(-1, 0);
	                            figure_parts[2] = new Point(-1, 1);
	                            figure_parts[3] = new Point(1, 0);
	             		        setcountFigureRotate(4);
	             		       break;
	             		       
	    	    case LOG :     figure_parts[0] = new Point(0, 0);
                               figure_parts[1] = new Point(-1, 0);
                               figure_parts[2] = new Point(1, 0);
                               figure_parts[3] = new Point(2, 0);
                               setcountFigureRotate(2);
                               break;
	        
	    	    case R_CORNER : figure_parts[0] = new Point(0, 0);
	                            figure_parts[1] = new Point(-1, 0);
	                            figure_parts[2] = new Point(1, 0);
	                            figure_parts[3] = new Point(1, 1);
	                           setcountFigureRotate(4);
	               		       break;
	        
	    	    case L_ZIGZAG : figure_parts[0] = new Point(0, 0);
	                            figure_parts[1] = new Point(-1, 0);
	                            figure_parts[2] = new Point(0, 1);
	                            figure_parts[3] = new Point(1, 1);
	                            setcountFigureRotate(2);
	            		       break;
	    	    
	    	    case R_ZIGZAG : figure_parts[0] = new Point(0, 0);
	                            figure_parts[1] = new Point(1, 0);
	                            figure_parts[2] = new Point(0, 1);
	                            figure_parts[3] = new Point(-1, 1);
	                           setcountFigureRotate(2);
	            		       break;
	    
	    	    
	    	    
	    	    case AWNING :   figure_parts[0] = new Point(0, 0);
	                            figure_parts[1] = new Point(-1, 0);
	                            figure_parts[2] = new Point(1, 0);
	                            figure_parts[3] = new Point(0, 1);
	                           setcountFigureRotate(4);
	        		           break;
	    	   
	    	    case SQUARE : figure_parts[0] = new Point(0, 0);
                              figure_parts[1] = new Point(0, 1);
                              figure_parts[2] = new Point(-1, 0);
                              figure_parts[3] = new Point(-1, 1);
                              setcountFigureRotate(1);
		                       break;
	    	}
		
	}
	
	
 public Object clone(){
		State copyState = null;
		try {
			copyState = (State)super.clone();
		} catch (CloneNotSupportedException e) {
			System.err.println("Object cant to be clone");
		}
      copyState.figure_parts=(Point[]) copyState.figure_parts.clone();
      
      for (int i = 0; i < figure_parts.length; i++) {
    	  copyState.figure_parts[i]=(Point) copyState.figure_parts[i].clone();
	       }
	  
      copyState.field  =   (int[][]) copyState.field.clone();
		
		for (int i = 0; i < field.length; i++) {
			copyState.field[i]=copyState.field[i].clone();
		}
		
		copyState.CentrefigurePosition = (Point) copyState.CentrefigurePosition.clone();
		
		return copyState;
	}





	

}

⌨️ 快捷键说明

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