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

📄 jsftcomponent.java

📁 这是一个俄罗斯方块的JAVA实现
💻 JAVA
字号:
package com.sunfruit.draw.swing;

import com.sunfruit.draw.basic.*;
import java.awt.Color;
import com.sunfruit.draw.framework.JSFCanvasface;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class JSFTComponent
    extends JSFBasicComponent {

  private int state=-1;

  private JSFCanvasface jsfCanvasface;

  public JSFTComponent(JSFCanvasface jsfCanvasface) {
    super(jsfCanvasface);
    x=3;
    y=0;
    this.drawRect=new int[4][2];
    this.jsfCanvasface=jsfCanvasface;
    initStyle();
    setState(0);
  }

  private void initStyle()
  {
    this.setFillColor(Color.blue);
    this.setFrameColor(Color.black);
  }


  /**
   *
   * @todo Implement this com.sunfruit.draw.framework.JSFComponentface method
   */
  public boolean falling() {
    //是否和其他的组件相交
    if(isIntersectsBottom()) return false;

    y=y+1;
    updatePoints();
    return true;
  }

  public boolean uping() {
    //是否和其他的组件相交
    if(isIntersectsTop()) return false;

    y=y-1;
    updatePoints();
    return true;
  }


  public boolean moveLeft()
  {
    if(isIntersectsLeft()) return false;

    x=x-1;
    updatePoints();
    return true;
  }

  public boolean moveRight()
  {
    if(isIntersectsRight()) return false;

    x=x+1;
    updatePoints();
    return true;
  }

  public boolean moveBottom()
  {
    boolean b=false;
    //是否和其他的组件相交
    while(!isIntersectsBottom())
    {
      b=true;
      y=y+1;
      updatePoints();
    }
    return b;
  }

  public void setState(int state)
  {
    if(this.state!=state)
    {
      this.state=state;
      updatePoints();
    }
  }

  public int getState()
  {
    return this.state;
  }
  /**
   * setPoint
   *
   * @param x int
   * @param y int
   * @todo Implement this com.sunfruit.draw.framework.JSFComponentface method
   */
  public void setPoint(int x, int y) {
    this.x=x;
    this.y=y;
    updatePoints();
  }

  private void updatePoints()
  {
    //T
    if(state==0)
    {
      int[][] state_ = {{x,y},{x+1,y},{x+2,y},{x+1,y+1}};
      reAccount(state_);
    }
    //|-
    if(state==1)
    {
      int[][] state_ = {{x,y},{x,y+1},{x,y+2},{x+1,y+1}};
      reAccount(state_);
    }
    //_|_
    if(state==2)
    {
      if(x==(jsfCanvasface.getReseau()[0].length-2)) x--;
      int[][] state_ = {{x,y+1},{x+1,y+1},{x+2,y+1},{x+1,y}};
      reAccount(state_);
    }
    //-|
    if(state==3)
    {
      int[][] state_ = {{x,y+1},{x+1,y},{x+1,y+1},{x+1,y+2}};
      reAccount(state_);
    }

  }

  private void reAccount(int[][] state_)
  {
    this.drawRect=state_;
  }



  public int[][] getRects() {
    return this.drawRect;
  }

}

⌨️ 快捷键说明

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