📄 myshape.java
字号:
package com.ywb.model;
public class MyShape {
private int type=0;//0 方块、1 长条、2 z、3 反z、4 L、5 反L、6 T
private int shape=0;
public MyShape(){
int[] temp=getRandomType();
type=temp[1];
shape=temp[0];
}
public static int[] getRandomType(){
int temp[]=new int[2];
temp[0]=(int)(Math.random()*7);
temp[1]=(int)(Math.random()*4);
return temp;
}
public int[] getShape(int shape,int type){
int[] tempshape=null;
//方块形状的色块分布
if(shape==0){
tempshape=new int[]{0,0,0,1,1,0,1,1};
}
//长条形状的色块分布
if(shape==1){
if(type==0||type==2){
tempshape=new int[]{0,0,0,1,0,2,0,3};
}else{
tempshape=new int[]{0,0,1,0,2,0,3,0};
}
}
//z形状的色块分布
if(shape==2){
if(type==0||type==2){
tempshape=new int[]{0,1,1,0,1,1,2,0};
}else{
tempshape=new int[]{0,0,0,1,1,1,1,2};
}
}
//反z形状的色块分布
if(shape==3){
if(type==0||type==2){
tempshape=new int[]{0,1,0,2,1,0,1,1};
}else{
tempshape=new int[]{0,0,1,0,1,1,2,1};
}
}
//L形状的色块分布
if(shape==4){
if(type==0){//L
tempshape=new int[]{0,0,1,0,2,0,2,1};
}else if(type==1){//|-
tempshape=new int[]{0,0,0,1,0,2,1,0};
}else if(type==2){//7
tempshape=new int[]{0,0,0,1,1,1,2,1};
}else{//_|
tempshape=new int[]{0,2,1,0,1,1,1,2};
}
}
//反L形状的色块分布
if(shape==5){
if(type==0){//_|
tempshape=new int[]{0,1,1,1,2,0,2,1};
}else if(type==1){//|_
tempshape=new int[]{0,0,1,0,1,1,1,2};
}else if(type==2){//|-
tempshape=new int[]{0,0,0,1,1,0,2,0};
}else{//7
tempshape=new int[]{0,0,0,1,0,2,1,2};
}
}
//T形状的色块分布
if(shape==6){
if(type==0){//T
tempshape=new int[]{0,0,0,1,0,2,1,1};
}else if(type==1){//-|
tempshape=new int[]{0,1,1,0,1,1,2,1};
}else if(type==2){//上
tempshape=new int[]{0,1,1,0,1,1,1,2};
}else{//|-
tempshape=new int[]{0,0,1,0,1,1,2,0};
}
}
return tempshape;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getShape() {
return shape;
}
public void setShape(int shape) {
this.shape = shape;
}
public void reShape(){
int tnum=this.getType()+1;
if(tnum>=4){
tnum=0;
}
this.setType(tnum);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -