block.java
来自「我自己写的一个java tetrix。是上学期的作业」· Java 代码 · 共 130 行
JAVA
130 行
import java.util.*;
import java.io.*;
public abstract class block
{
public final static int bwidth = 10;
public final static int bheight = 18;
/** repensent the status of the 6*8 board. */
protected static char tile[][]= new char[bheight][bwidth];
/** to store the location of the new block */
protected static int row[]=new int[4];
/** to store the location of the new block */
protected static int col[]=new int[4];
/** set the variable to check whether the intial right side of the block is free */
protected static boolean right = true;
/** set the variable to check whether the intial left side of the block is free */
protected static boolean left = true;
/** set the variable to check whether the intial down side of the block is free */
protected static boolean down = true;
protected static int score =0;
/** the constructor */
public block()
{
}
/** unlike the Move_Downward,Left,Right methods,Check and Rotation is different depend on the shape and position of the block. */
public abstract void check();
/** unlike the Move_Downward,Left,Right methods,Check and Rotation is different depend on the shape and position of the block. */
public abstract void rotate();
/** Move the block to the left */
protected void Move_Left()
{
for (int i=0,j=0; i<4; i++,j++)
{
tile[row[i]][col[j]]=' ';
}
for (int i=0,j=0; i<4; i++,j++)
{
tile[row[i]][col[j]-1]='*';
}
for (int j=0; j<4; j++)
{
col[j]-=1;
}
}
/** Move the block to the right */
protected void Move_Right()
{
for (int i=0,j=0; i<4; i++,j++)
{
tile[row[i]][col[j]]=' ';
}
for (int i=0,j=0; i<4; i++,j++)
{
tile[row[i]][col[j]+1]='*';
}
for (int j=0; j<4; j++)
{
col[j]+=1;
}
}
/** Move the block to the downward */
protected void Move_Downward()
{
for (int i=0,j=0; i<4; i++,j++)
{
tile[row[i]][col[j]]=' ';
}
for (int i=0,j=0; i<4; i++,j++)
{
tile[row[i]+1][col[j]]='*';
}
for (int i=0; i<4; i++)
{
row[i]+=1;
}
}
/** check every line in the board whether it is assembled. If there is a Assembled Line, then eliminate it and get every line down one step and show the score you get. */
public void erase_lines()
{
for(int i=bheight-1;i>=0;i--)
{
for(int j=bheight-1;j>0;j--)
{
if((tile[i][0]=='*')&&(tile[i][1]=='*')&&(tile[i][2]=='*')&&(tile[i][3]=='*')&&(tile[i][4]=='*')&&(tile[i][5]=='*')&&(tile[i][6]=='*')&&(tile[i][7]=='*')&&(tile[i][8]=='*')&&(tile[i][9]=='*'))
{
/** move the upper tile downwards */
for(int m=i; m>0; m--)
{
for(int n=0; n<bwidth; n++)
{
tile[m][n] = tile[m-1][n];
}
}
for(int k=0;k<bwidth; k++)
{
tile[0][k]=' ';
}
score++;
}
}
}
// System.out.println("You got "+score+" score!");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?