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

📄 commitmoveanim.java

📁 有兴趣的朋友可以看看,蓝牙应用的,很不錯的哦!!!!
💻 JAVA
字号:
// Copyright (c) 2005 Sony Ericsson Mobile Communications AB
//
// This software is provided "AS IS," without a warranty of any kind. 
// ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, 
// INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A 
// PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. 
//
// THIS SOFTWARE IS COMPLEMENTARY OF JAYWAY AB (www.jayway.se)

package bluegammon.gui.animation;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

import bluegammon.Resources;
import bluegammon.gui.BoardCanvas;
import bluegammon.logic.BoardMediator;

/**
 * Animation showing the user that he or she should commit his or her moves.
 * 
 * @author Peter Andersson
 */
public class CommitMoveAnim extends Animation
{
  protected static final Font FONT =
    Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_LARGE);
  protected static final char[] MESS =
    Resources.getChars(Resources.TXT_A_QUERY_COMMIT);
  protected static final int MESSW =
    FONT.charsWidth(MESS, 0, MESS.length);
  protected static final int MESSH =
    FONT.getHeight();
  protected boolean m_white;
  protected int m_step = 0;
  protected int m_x, m_y, m_minX, m_dx;
  protected static final int DT = 8;

  /**
   * Creates an animation indicating that user should commit his/her moves.
   * 
   * @param white  True for white player, false for black player.
   */
  public CommitMoveAnim(boolean white)
  {
    m_white = !white;
    m_x = (BoardCanvas.getInstance().getWidth() - MESSW) / 2;
    m_y = (BoardCanvas.getInstance().getBoardHeight() - MESSH) / 2;
    m_minX = -MESSW - 16;
    m_dx = (m_x - m_minX) / DT;
  }

  public void paint(Graphics g)
  {
    int x = 0;
    if (m_step >= 0 && m_step < DT)
    {
      x = m_minX + m_dx * m_step;
    }
    else if (m_step < DT * 5)
    {
      x = m_x;
    }
    else if (m_step < DT * 6)
    {
      x = m_x + m_dx * (m_step - DT * 5);
    }
    else if (m_step <= DT * 10)
    {
      return;
    }
    else if (m_step > DT * 10)
    {
      m_step = 0;
      return;
    }

    g.setFont(FONT);
    g.setColor(m_white ? 0x000000 : 0xffffff);
    g.drawChars(MESS, 0, MESS.length, x - 1, m_y, Graphics.LEFT | Graphics.TOP);
    g.drawChars(MESS, 0, MESS.length, x + 1, m_y, Graphics.LEFT | Graphics.TOP);
    g.drawChars(MESS, 0, MESS.length, x, m_y - 1, Graphics.LEFT | Graphics.TOP);
    g.drawChars(MESS, 0, MESS.length, x, m_y + 1, Graphics.LEFT | Graphics.TOP);
    g.setColor(m_white ? 0xffffff : 0x000000);
    g.drawChars(MESS, 0, MESS.length, x, m_y, Graphics.LEFT | Graphics.TOP);
  }

  public void next()
  {
    m_step++;
    BoardCanvas.getInstance().requestRepaint();
  }

  public boolean isFinished()
  {
    return !BoardCanvas.getInstance().waitingForCommit()
        || BoardMediator.isGameFinished();
  }

  /**
   * Called when animation is finished, repaints the 
   * whole canvas.
   */
  public void onExit()
  {
    BoardCanvas.getInstance().requestRepaint();
  }

  public long getInterval()
  {
    return 40;
  }
}

⌨️ 快捷键说明

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