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

📄 tblock.java

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

/** the T-block class. include its generate method. rotate methods and the check methods. */
public class tblock extends block
{
/** using 'count'to store the rotation times of the block and to note the status(position) of the block. */
      private int count=0;
/** generate new block using the row[4],col[4] to store the location of the new block. */
      public tblock()
      {
		  tile[0][3]='*';
		  tile[0][4]='*';
		  tile[1][4]='*';
		  tile[0][5]='*';

		  row[0]=0; col[0]=3;
		  row[1]=0; col[1]=4;
		  row[2]=1; col[2]=4;
		  row[3]=0; col[3]=5;
          left = true;
          right = true;
          down = true;
          this.count = 0;
	  }
/** unlike the Move_Downward,Left,Right methods. Check and Rotation is different depend on the shape and position of the block. */
	 public void rotate()
	 {

      switch(count%4)
      {
		  case 0: if(row[0]!=0)
		          {

					  tile[row[3]][col[3]]=' ';

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

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

					  if(right==false) right = true;
					  count++;
					  break;

				   }
				  else System.out.println("Can not rotate!");break;

		  case 1: if((col[1]!=(bwidth-1))&&(tile[row[2]][col[2]+1]!='*'))
		          {

					  tile[row[3]][col[3]]=' ';

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

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

                      if(right==false) right = true;
					  count++;
					  break;

				   }
				  else System.out.println("Can not rotate!");break;

		  case 2: if((row[0]!=(bheight-1))&&(tile[row[2]+1][col[2]]!='*'))
		          {

					  tile[row[0]][col[0]]=' ';

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

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

					  if(left == false) left = true;
					  count++;
					  break;

				   }
				  else System.out.println("Can not rotate!");break;

		  case 3: if((col[0]!=0)&&(tile[row[1]][col[1]-1]!='*'))
		          {

					  tile[row[0]][col[0]]=' ';

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

                      row[0]=row[1]; col[0]=col[1]-1;

                      if(col[1]==1) left = false;
					  count++;
					  break;

				   }
				  else System.out.println("Can not rotate!");break;

	   }

	  }

/** 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(count%4==0)
		{
          if(col[0]==0)
          left = false;
          else if((tile[row[0]][col[0]-1]=='*')||(tile[row[2]][col[2]-1]=='*'))
          left = false;

          if(col[3]==bwidth-1)
          right = false;
          else if((tile[row[3]][col[3]+1]=='*')||(tile[row[2]][col[2]+1]=='*'))
          right = false;

          if(row[2]==bheight-1)
          down =false;
          else if((tile[row[2]+1][col[2]]=='*')||(tile[row[3]+1][col[3]]=='*')||(tile[row[0]+1][col[0]]=='*'))
          down = false;
		}
		else if(count%4==1)
		{
          if(col[0]==0)
          left = false;
          else if(tile[row[0]][col[0]-1]=='*'||(tile[row[1]][col[1]-1]=='*')||(tile[row[3]][col[3]-1]=='*'))
          left = false;

          if(col[3]==bwidth-1)
          right = false;
          else if((tile[row[3]][col[3]+1]=='*')||(tile[row[2]][col[2]+1]=='*')||(tile[row[1]][col[1]+1]=='*'))
          right = false;

          if(row[3]==bheight-1)
          down =false;
          else if((tile[row[3]+1][col[3]]=='*')||(tile[row[0]+1][col[0]]=='*'))
          down = false;
		}
		else if(count%4==2)
		{
          if(col[0]==0)
          left = false;
          else if((tile[row[0]][col[0]-1]=='*')||(tile[row[1]][col[1]-1]=='*'))
          left = false;

          if(col[3]==bwidth-1)
          right = false;
          else if((tile[row[3]][col[3]+1]=='*')||(tile[row[1]][col[1]+1]=='*'))
          right = false;

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

		else if(count%4==3)
		{
          if(col[0]==0)
          left = false;
          else if(tile[row[0]][col[0]-1]=='*'||(tile[row[1]][col[1]-1]=='*')||(tile[row[2]][col[2]-1]=='*'))
          left = false;

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

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

	}
}























⌨️ 快捷键说明

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