?? gamebase.java
字號:
package Darts;
import com.nttdocomo.ui.*;
/** The game of Base. */
/* 僎乕儉偺婎掙僋儔僗 */
public class GameBase extends Canvas {
/* 僎乕儉偵娭偡傞掕媊 */
/* 1儔僂儞僪偺嵟戝搳栴悢 */
public static final int THROWMAX = 3;
/* 儗僀傾僂僩掕媊 */
/* 僨傿僗僾儗僀暆 */
protected int dsW;
protected int dsHW;
/* 僨傿僗僾儗僀崅偝 */
protected int dsH;
protected int dsHH;
/* 暥帤暆(拞) */
protected int strMW;
/* 暥帤崅偝(拞) */
protected int strMH;
/* 暥帤暆(戝) */
protected int strLW;
/* 暥帤崅偝(戝) */
protected int strLH;
/* 儔僂儞僪昞帵埵抲 */
protected int roundPosX;
/* 儔僂儞僪昞帵埵抲 */
protected int roundPosY;
/* 僾儗乕儎乕昞帵埵抲 */
protected int[] playerPos;
/* 僗僐傾昞帵埵抲 */
protected int[] scorePos;
/* 僎乕儉偺忬懺偺掕媊 */
/* 僎乕儉偺忬懺 */
protected int gameStat;
/* 僾儗僀拞 */
protected static int GS_PLAYING = 0;
/* 廔椆 */
protected static int GS_FINISH = 1;
/* 僎乕儉僆乕僶乕 */
protected static int GS_GAMEOVER = 2;
/* 僎乕儉傪娗棟偡傞崁栚偺掕媊 */
protected int playerCnt;
protected int curPlayer;
protected int curRound;
protected int curThrowCnt;
/* 僾儗僀儎乕 */
protected Player[] player;
/* 僗僐傾 */
protected int[] score;
/* 彑幰敾掕 */
protected int winPlayer;
protected int evenPlayerCnt;
protected Darts parent = null;
protected GameMenu gameMenu = null;
Graphics g;
public GameBase(Darts _parent, int _playerCnt) {
this.parent = _parent;
playerCnt = _playerCnt;
dsW = this.getWidth();
dsHW = dsW / 2;
dsH = this.getHeight();
dsHH = dsH / 2;
Font f = Font.getFont( Font.FACE_SYSTEM |
Font.SIZE_MEDIUM |
Font.STYLE_BOLD );
strMW = f.stringWidth( " " );
strMH = f.getHeight();
f = Font.getFont( Font.FACE_SYSTEM |
Font.SIZE_LARGE |
Font.STYLE_BOLD );
strLW = f.stringWidth( " " );
strLH = f.getHeight();
roundPosX = dsHW - ( strMW * 6 );
roundPosY = strMH;
if ( _playerCnt <= 2 ) {
playerPos = new int[2];
scorePos = new int[2];
playerPos[0] = ( dsHW - ( strLW * 4 ) ) / 2;
playerPos[1] = ( dsHW + ( strLW * 2 ) ) + playerPos[0];
scorePos[0] = strLW * 2;
scorePos[1] = dsHW + ( strLW * 2 );
}
else {
playerPos = new int[4];
scorePos = new int[4];
playerPos[0] = 0;
playerPos[1] = ( strLW * 3 ) + playerPos[0];
playerPos[2] = dsW - ( strLW * 5 );
playerPos[3] = dsW - ( strLW * 2 );
scorePos[0] = 0;
scorePos[1] = ( dsW / 4 );
scorePos[2] = ( ( dsW / 4 ) * 2 ) + strMW;
scorePos[3] = ( ( dsW / 4 ) * 3 ) + strMW;
}
g = getGraphics();
setBackground( Color.BLACK );
setSoftLabel( Frame.SOFT_KEY_1, "Prev" );
setSoftLabel( Frame.SOFT_KEY_2, "Menu" );
}
/* 僗僐傾昤夋 */
protected void drawScore() {
String[] strScore = new String[playerCnt];
for ( int i = 0; i < playerCnt; i++ ) {
strScore[i] = "" + score[i];
String tmpStr = "";
for ( int k = 0; k < 4 - strScore[i].length(); k++ ) {
tmpStr = tmpStr + " ";
}
strScore[i] = tmpStr + strScore[i];
}
g.lock();
if ( playerCnt <= 2 ) {
g.setFont( Font.getFont( Font.FACE_SYSTEM |
Font.SIZE_LARGE |
Font.STYLE_BOLD ) );
}
else {
g.setFont( Font.getFont( Font.FACE_SYSTEM |
Font.SIZE_MEDIUM |
Font.STYLE_BOLD ) );
}
/* 僾儗僀儎乕1昤夋 */
g.setColor( Color.BLUE );
g.drawString( strScore[0], scorePos[0], dsH );
/* 僾儗僀儎乕2昤夋 */
if ( playerCnt >= 2 ) {
g.setColor( Color.RED );
g.drawString( strScore[1], scorePos[1], dsH );
}
/* 僾儗僀儎乕3昤夋 */
if ( playerCnt >= 3 ) {
g.setColor( Color.GREEN );
g.drawString( strScore[2], scorePos[2], dsH );
}
/* 僾儗僀儎乕4昤夋 */
if ( playerCnt == 4 ) {
g.setColor( Color.YELLOW );
g.drawString( strScore[3], scorePos[3], dsH );
}
g.unlock(true);
}
/* 廔椆昤夋 */
protected void drawFinish() {
g.lock();
g.setFont(Font.getFont(Font.FACE_SYSTEM |
Font.SIZE_LARGE |
Font.STYLE_BOLD));
g.setColor( Color.GREEN );
g.fillRect( 0, dsHH - 50, dsW, 10);
g.fillRect( 0, dsHH + 20, dsW, 10);
g.drawString( "G a m e" , dsHW - 82, dsHH - 12 );
g.drawString( " O v e r", dsHW - 82, dsHH + 12 );
g.setColor( Color.YELLOW );
g.drawString( "G a m e" , dsHW - 80, dsHH - 10 );
g.drawString( " O v e r", dsHW - 80, dsHH + 14 );
if ( playerCnt > 1 ) {
if ( evenPlayerCnt > 0 ) {
g.drawString( "Tie game...", dsHW - 80, dsHH + 65 );
}
else {
g.drawString( "仚Player" + winPlayer + " Win仚", 10, dsHH + 65 );
}
}
g.unlock(true);
gameStat = GS_GAMEOVER;
}
public void GameMenuClose(int _action) {
if ( _action == 1 ) {
Dialog dialog = new Dialog( Dialog.DIALOG_YESNO, "奐巒妋擣" );
dialog.setText( "怴婯偵僎乕儉傪奐巒偟傑偡丅\n傛傠偟偄偱偡偐丠\n\n" );
int ans = dialog.show();
if ( Dialog.BUTTON_YES == ans ) {
start();
}
}
if ( _action == 2 ) {
Dialog dialog = new Dialog( Dialog.DIALOG_YESNO, "廔椆妋擣" );
dialog.setText( "僎乕儉傪廔椆偟傑偡丅\n傛傠偟偄偱偡偐丠\n\n" );
int ans = dialog.show();
if ( Dialog.BUTTON_YES == ans ) {
parent.endGame();
}
}
}
public synchronized void paint(Graphics _g) {}
public void start() {}
public void prev() {}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -