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

📄 jsficomponent.java

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

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

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class JSFIComponent
    extends JSFBasicComponent {
  private int state=-1;
  private JSFCanvasface jsfCanvasface;

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

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

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

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

  }

  /**
   * 获得该组件的范围
   *
   * @return Shape
   * @todo Implement this com.sunfruit.draw.framework.JSFComponentface method
   */
  public int[][] getRects() {
    return this.drawRect;
  }

  /**
   * getState
   *
   * @return int
   * @todo Implement this com.sunfruit.draw.framework.JSFComponentface method
   */
  public int getState() {
    return this.state;
  }

  /**
   *
   * @todo Implement this com.sunfruit.draw.framework.JSFComponentface method
   */
  public boolean moveBottom() {
    //是否和其他的组件相交
    boolean b=false;
    while(!isIntersectsBottom())
    {
      y=y+1;
      updatePoints();
      b=true;
    }
    return b;
  }

  /**
   *
   * @return boolean
   * @todo Implement this com.sunfruit.draw.framework.JSFComponentface method
   */
  public boolean moveLeft() {
    if(isIntersectsLeft()) return false;

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

  }

  /**
   *
   * @return boolean
   * @todo Implement this com.sunfruit.draw.framework.JSFComponentface method
   */
  public boolean moveRight() {
    if(isIntersectsRight()) return false;

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

  }

  /**
   * 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();

  }

  /**
   * 转动
   *
   * @param state int
   * @todo Implement this com.sunfruit.draw.framework.JSFComponentface method
   */
  public void setState(int state) {
    if(this.state!=state)
    {
      this.state=state;
      updatePoints();
    }

  }

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

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

  }

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

      int[][] state_ = {{x,y},{x,y+1},{x,y+2},{x,y+3}};
      reAccount(state_);
    }
  }

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

}

⌨️ 快捷键说明

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