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

📄 line.java

📁 我自己写的一个java tetrix。是上学期的作业
💻 JAVA
字号:
import java.util.*;
import java.io.*;

/** the Line class. include its generate method. rotate methods and the check methods. */
public class line extends block
{
/** generate new block using the row[4],col[4] to store the location of the new block. */
      public line()
      {
		  tile[0][3]='*';
		  tile[0][4]='*';
		  tile[0][5]='*';
		  tile[0][6]='*';

		  row[0]=0; col[0]=3;
		  row[1]=0; col[1]=4;
		  row[2]=0; col[2]=5;
		  row[3]=0; col[3]=6;
          left = true;
          right = true;
          down = true;

	  }

/** unlike the Move_Downward,Left,Right methods. Check and Rotation is different depend on the shape and position of the block. */
	public void rotate()
	{
       if(row[0]==row[1])
       {
		  if((row[1]>0)&&(row[1]<bheight-2)&&(tile[row[1]+1][col[1]]!='*')&&(tile[row[1]+2][col[1]]!='*'))
		  {
			/**row1,col1 is the center which does not move when rotating */
            tile[row[0]][col[0]]=' ';
            tile[row[2]][col[2]]=' ';
            tile[row[3]][col[3]]=' ';
            tile[row[1]-1][col[1]]='*';
            tile[row[1]+1][col[1]]='*';
            tile[row[1]+2][col[1]]='*';
            row[0]=row[1]-1; col[0]=col[1];
            row[2]=row[1]+1; col[2]=col[1];
            row[3]=row[1]+2; col[3]=col[1];
             left=true;  right=true; down =true;

		  }
		  else System.out.println("can not rotate now.");
	   }
	   else if(col[0]==col[1])
	   {
		   if((col[1]>1)&&(col[1]<bwidth-1))
		   {
            tile[row[0]][col[0]]=' ';/**row1,col1 is the center which does not move when rotating */
            tile[row[2]][col[2]]=' ';
            tile[row[3]][col[3]]=' ';

            tile[row[1]][col[1]+1]='*';
            tile[row[1]][col[1]-1]='*';
            tile[row[1]][col[1]-2]='*';

            row[0]=row[1]; col[0]=col[1]-2;
            row[3]=row[1]; col[3]=col[1]+1;
            row[2]=row[1]; col[2]=col[1];
            col[1]=col[1]-1;

            if(col[0]==0)
            left=false;
            else if(col[3]==bwidth-1)
            right=false;

            down =true;

		   }
	   }
	}

/** unlike the Move_Downward,Left,Right methods,Check and Rotation is different depend on the shape and position of the block. */
	  public void check()
    {
		  if(row[0]==row[1])
		  {

				  if(col[0]==0)
				  left = false;
				  else if(tile[row[0]][col[0]-1]!=' ')
				  left = false;

 				/** touch the bouder? */
				  if(col[3]==bwidth-1)
				  right = false;
				  else if(tile[row[0]][col[3]+1]!=' ')
				  right = false;

                 if(row[0]==bheight-1)
                 down = false;
                 else if((tile[row[0]+1][col[0]]!=' ')||(tile[row[0]+1][col[1]]!=' ')||(tile[row[0]+1][col[2]]!=' ')||(tile[row[0]+1][col[3]]!=' '))
                 down = false;

		  }
		  else if(col[0]==col[1])
		  {
				  if(col[0]==0)
				  left = false;
				  else if((tile[row[0]][col[0]-1]!=' ')||(tile[row[1]][col[0]-1]!=' ')||(tile[row[2]][col[0]-1]!=' ')||(tile[row[3]][col[0]-1]!=' ')) /** there is * besides */
				  left = false;

				  if(col[0]==bwidth-1)
				  right = false;
				  else if((tile[row[0]][col[0]+1]!=' ')||(tile[row[1]][col[0]+1]!=' ')||(tile[row[2]][col[0]+1]!=' ')||(tile[row[3]][col[0]+1]!=' ')) /** there is * besides */
				  right = false;

                 if(row[3]==bheight-1)
                 down = false;
                 else if(tile[row[3]+1][col[0]]=='*')
                 down = false;
		  }
	  }

}

⌨️ 快捷键说明

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