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

📄 roundcanvas.java

📁 DoCoMo 手机Java源码 -- Game For Cricket
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

import com.nttdocomo.ui.Canvas;
import com.nttdocomo.ui.Dialog;
import com.nttdocomo.ui.Display;
import com.nttdocomo.ui.Font;
import com.nttdocomo.ui.Graphics;

public class RoundCanvas extends Canvas {
    // control class
    private Cricket             parent          = null;
    private ScoreManager        scoreMgr        = null;
    private Graphics            g				= null;
    // Position data
    private TRectangle          rectMain        = new TRectangle();
    private TRectangle[]        rectBody        = new TRectangle[TConst.MAIN_RECT];
    private TRectangle[]        rectLeftCursor  = new TRectangle[TConst.SUB_CURSOR];
    private TRectangle[]        rectRightCursor = new TRectangle[TConst.SUB_CURSOR];
    private TRectangle[]        rectLeftRdCnt   = new TRectangle[TConst.ONE_ROUND_COUNT];
    private TRectangle[]        rectRightRdCnt  = new TRectangle[TConst.ONE_ROUND_COUNT];
    private Font                ft_default      = null;
    // Display control data
    private TParameter          pmData          = new TParameter();
    private int                 curPosY         = 0;
    private int[]               closePos        = new int[TConst.SUB_CURSOR];
    private boolean             gameOver        = false;

    public RoundCanvas(Cricket _parent, ScoreManager _scoreMgr) {
        super();
        
    	this.g        = getGraphics();
        this.parent   = _parent;
        this.scoreMgr = _scoreMgr;
        this.getRectsValue();
        this.getSuiteFont();
    }
    
    public void initialize() {
    	// initialize data
        this.curPosY  = 0;
        for ( int i=0 ; i<TConst.SUB_CURSOR ; i++ ) {
        	closePos[i] = -1;
        }
        this.gameOver = false;
        this.pmData.initialize();
        this.scoreMgr.initialize();
    }

    public void paintMainWinowAll() {
        // 1. draw main window
    	g.lock();
        drawMainWindow();					  // 儊僀儞夋柺
        drawTitleText();                      // 僞僀僩儖 
        drawRankText();						  // Rank
        drawScoreAll();   					  // Score
        drawLeftStyleAll();
        drawRightStyleAll();
        drawClosedAll();
        drawRoundCircleAll();
        drawCursor(); 						  // Cursor
        setSoftkeyName();
        g.unlock(true);
        //System.out.println("paintMainWinow");
    }

    public void paint(Graphics canvas) {
        // update panel input value
    	this.updatePanelInput();
        // Draw User Interface for display
        this.paintMainWinowAll();
    }

    /**
     * 僀儀儞僩偑敪惗偟偨帪偵屇傃弌偝傟傞儊僜僢僪偱偡丅
     * @param _type 僀儀儞僩偺庬椶
     * @param _param 僀儀儞僩偺庬椶偵懳墳偡傞僷儔儊乕僞
     */
    public void processEvent(int _type, int _param) {
        // 僀儀儞僩偺庬椶傪摿掕丗丂僉乕僾儗僗
        if (Display.KEY_PRESSED_EVENT == _type) {
            if ( Display.KEY_SELECT == _param ) {
            	if ( gameOver == false ) {
            		parent.showPanel();
            	}
            } else if ( Display.KEY_0 == _param ) {
            	keyValuePressed(TConst.KEY_0);
            } else if ( Display.KEY_1 == _param ) {
            	keyValuePressed(TConst.KEY_1);
            } else if ( Display.KEY_2 == _param ) {
            	keyValuePressed(TConst.KEY_2);
            } else if ( Display.KEY_3 == _param ) {
            	keyValuePressed(TConst.KEY_3);
            } else if ( Display.KEY_5 == _param ) {
            	keyUndoPressed(TConst.KEY_5);
            } else if ( Display.KEY_6 == _param ) {
            	keyValuePressed(TConst.KEY_6);
            } else if ( Display.KEY_DOWN == _param ) {
            	nextCursor();
            } else if ( Display.KEY_UP == _param ) {
            	prevCursor();
            } else if (Display.KEY_SOFT1 == _param) {
                Dialog dialog = new Dialog(Dialog.DIALOG_YESNO, "栠傞");
                dialog.setText("僞僀僩儖夋柺偵栠傝傑偡丄\n慡偰偺僨乕僞偑幐偄傑偡丅\n傛傠偟偄偱偡偐丠\n\n");
                int ans = dialog.show();
                if (Dialog.BUTTON_YES == ans) {
                    parent.showTitle();
                }
            } else if (Display.KEY_SOFT2 == _param) {
            	int round  = scoreMgr.getCurrentRound( pmData );
            	if ( round > TConst.MAX_ROUND ) {
            		round = TConst.MAX_ROUND ;
            	}
            	String title  = "摑寁--Round: " + round;
            	Dialog dialog = new Dialog(Dialog.DIALOG_INFO, title);
                dialog.setText(this.scoreMgr.getCalculateAll());
                dialog.show();
            }
        }
    }
    
    private void keyUndoPressed(int key){
    	if ( gameOver ) {
    		gameOver = false;
    	}
    	
    	
    	pmData.pos = curPosY;
    	boolean bOK = scoreMgr.valueChanged(0, key, pmData);
    	if ( bOK == false ) {
    		return;
    	}
    	
    	if ( pmData.drawUserChg ) {
    		if ( pmData.currentUser == 0 && scoreMgr.getOneRoundCount(pmData) == 0 ){
    			return;
    		}

    		changeToPrevPlayer();
    		scoreMgr.valueChanged(0, key, pmData);
    	}

		curPosY = pmData.pos;
		if ( scoreMgr.isClosable(curPosY) ) {
			closePos[curPosY] = curPosY;
		} else {
			closePos[curPosY] = -1;
		}

		paintMainWinowAll();
    }
    
    private void keyValuePressed(int key){
    	// 僎乕儉僆乕僶乕側傜丄張棟偟側偄偙偲
    	if ( gameOver ) {
    		return;
    	}
    	// BULL偺応崌丄俁攞偑柍岠
    	if ( key == TConst.KEY_3 && curPosY == TConst.SUB_CURSOR-1 ) {
    		return;
    	}
    	
    	pmData.pos = curPosY;
    	int value = TConst.getMarkFromPos(curPosY);
    	boolean chgOK = scoreMgr.valueChanged(value, key, pmData);
    	if ( !chgOK ) {
    		return;
    	}

    	// get redo position
    	clearCursor(pmData.isLeft(), curPosY);
    	if ( key == TConst.KEY_6 ) {
    		curPosY = pmData.pos;
    	}

    	// 儐乕僓曄傢傝
    	if ( pmData.drawUserChg ) {
    		if ( scoreMgr.isClosable(curPosY) ) {
    			closePos[curPosY] = curPosY;
    		}
    		changeToNextPlayer();
    		paintMainWinowAll();
    		isGameOver();
    	} else {
        	// Mark丗乛亊仜
        	if ( pmData.drawMark ) {
        		if ( scoreMgr.isClosable(curPosY) ) {
        			closePos[curPosY] = curPosY;
            		drawClosed( curPosY );
            		isGameOver();
        		} else {
	        		int mark = scoreMgr.getMarkStyle( pmData );
	        		markStyle(mark, pmData.isLeft(), curPosY);
        		}
        	}
        	// 揰悢
        	if ( pmData.drawScore ) {
        		int score = scoreMgr.getMarkScore( pmData );
        		drawScore(pmData.isLeft(), score);
        	}
    		// Cursor
        	drawRoundCircle(pmData.isLeft());
        	drawCursor();
    	}
    }
    
    private void updatePanelInput() {
    	// check input key
    	int key = scoreMgr.getPanelInput();
    	scoreMgr.setPanelInput(-1);
    	if ( key < 0 ) {
    		return;
    	}

    	// check reflect
    	pmData.pos = curPosY;
    	int value = TConst.getMarkFromPos(curPosY);
    	boolean bOK = scoreMgr.valueChanged(value, key, pmData);
    	if ( bOK == false ) {
    		return;
    	}

    	// check close
    	if ( scoreMgr.isClosable(curPosY) ) {
			closePos[curPosY] = curPosY;
		}
    	
    	// change player
    	if ( pmData.drawUserChg ){
    		changeToNextPlayer();
    	}
    	
        isGameOver();
    }
    
    private void changeToNextPlayer() {
    	int playerCnt = scoreMgr.getPlayerCnt();

    	// Player Count == 1, no change
    	if ( playerCnt <= 1 ) {
    		return;
    	}

    	
    	if ( playerCnt == 2 ) {// Player Count == 2, left<==>right
    		if ( pmData.isLeft() ) {
    			pmData.currentUser = pmData.rightUser;
    		} else {
    			pmData.currentUser = pmData.leftUser;
    		}
    	}
    	else if ( pmData.isLeft() ) {// Player Count > 2, 0,1-->1,2-->2,3-->3,4...-->0,1
    		pmData.currentUser = pmData.rightUser;
    	} else {
    		if ( pmData.rightUser < (playerCnt-1) ) {
    			pmData.leftUser    = pmData.rightUser;
    			pmData.rightUser   = pmData.leftUser + 1;
    			pmData.currentUser = pmData.rightUser;
    		} else {
    			pmData.leftUser    = 0;
    			pmData.rightUser   = 1;
    			pmData.currentUser = 0;
    		}
    	}

    	scoreMgr.setOneRoundToZero(pmData);
    }

    private void changeToPrevPlayer() {
    	int playerCnt = scoreMgr.getPlayerCnt();

    	// Player Count == 1, no change
    	if ( playerCnt <= 1 ) {
    		return;
    	}

    	// Player Count == 2, left<==>right
    	if ( playerCnt == 2 ) {
    		if ( pmData.isLeft() ) {
    			pmData.currentUser = pmData.rightUser;
    		} else {
    			pmData.currentUser = pmData.leftUser;
    		}
    		return;
    	}

    	// Player Count > 2, 0,1-->1,2-->2,3-->3,4...-->0,1
    	if ( pmData.isLeft() ) {
    		if ( pmData.leftUser <= 0 ) {
    			pmData.leftUser    = playerCnt - 2;
    			pmData.rightUser   = playerCnt - 1;
    			pmData.currentUser = pmData.rightUser;
    		} else {
    			pmData.rightUser   = pmData.leftUser;
    			pmData.leftUser    = pmData.leftUser - 1;
    			pmData.currentUser = pmData.leftUser;
    		}
    	} else {
    		pmData.currentUser = pmData.leftUser;
    	}
    }
    
    private void drawCursor() {
    	if ( closePos[curPosY] < 0 ) {
    		drawCursor(pmData.isLeft(), curPosY);
    	} else {
    		if ( nextCursor() ) {
    			return;
    		}

⌨️ 快捷键说明

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