📄 dicesselectturnanim.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 show one black and one white dice, used
* at start of a game for selecting who should start.
*
* @author Peter Andersson
*/
public class DicesSelectTurnAnim extends AbstractDicesAnim
{
protected static final char[] TXT_BLACK_STARTS =
Resources.getChars(Resources.TXT_A_BLACK_STARTS);
protected static final char[] TXT_WHITE_STARTS =
Resources.getChars(Resources.TXT_A_WHITE_STARTS);
protected boolean m_white;
protected boolean m_showTurnText = false;
protected long m_showTurnTextCue;
protected int m_width, m_height;
protected char[] m_text;
protected static final Font FONT = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_LARGE);
/**
* Initiates this animation.
* @param whiteDice White dice value, 1 to 6.
* @param blackDice Black dice value, 1 to 6.
* @param width Board width.
* @param height Board height.
*/
public DicesSelectTurnAnim(int whiteDice, int blackDice, int width, int height)
{
super(true, false, whiteDice, blackDice);
m_width = width;
m_height = height;
m_white = whiteDice > blackDice;
m_text = m_white ? TXT_WHITE_STARTS : TXT_BLACK_STARTS;
}
/**
* Prevent interaction and update gui.
*/
public void onStart()
{
super.onStart();
BoardCanvas.getInstance().allowInteraction(false);
BoardCanvas.getInstance().setDrawDiceValues(false);
BoardCanvas.getInstance().updateCursor();
BoardCanvas.getInstance().updateUndoCommand();
}
public void paint(Graphics g)
{
if (!m_showTurnText)
{
super.paint(g); // draw dices
}
else
{
g.setFont(FONT);
int x = m_width / 2;
int y = m_height / 2 - FONT.getHeight() / 2;
g.setColor(m_white ? 0x000000 : 0xffffff);
g.drawChars(m_text, 0, m_text.length, x-1, y , Graphics.HCENTER | Graphics.TOP);
g.drawChars(m_text, 0, m_text.length, x+1, y , Graphics.HCENTER | Graphics.TOP);
g.drawChars(m_text, 0, m_text.length, x , y-1, Graphics.HCENTER | Graphics.TOP);
g.drawChars(m_text, 0, m_text.length, x , y+1, Graphics.HCENTER | Graphics.TOP);
g.setColor(m_white ? 0xffffff : 0x000000);
g.drawChars(m_text, 0, m_text.length, x , y , Graphics.HCENTER | Graphics.TOP);
}
}
public boolean isFinished()
{
if (super.isFinished())
{
if (!m_showTurnText)
{
m_showTurnText = true;
m_showTurnTextCue = System.currentTimeMillis();
}
return System.currentTimeMillis() > m_showTurnTextCue + 2000;
}
else
{
return false;
}
}
/**
* Start a new turn for the winning color.
*/
public void onExit()
{
super.onExit();
BoardMediator.newTurn(m_dice1 > m_dice2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -