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

📄 roundcanvas.java

📁 DoCoMo 手机Java源码 -- Game For Cricket
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                g.drawLine(rectLeftCursor[pos].x + 2,
                           rectLeftCursor[pos].y + rectLeftCursor[pos].height/2 +i,
                           rectLeftCursor[pos].x + rectLeftCursor[pos].width -2,
                           rectLeftCursor[pos].y + rectLeftCursor[pos].height/2 +i );
            }
        } else {
            g.setColor(getRightColor());
            for ( int i= -1 ; i<2 ; i++){
                g.drawLine(rectRightCursor[pos].x + 2,
                           rectRightCursor[pos].y + rectRightCursor[pos].height/2 +i,
                           rectRightCursor[pos].x + rectRightCursor[pos].width -2,
                           rectRightCursor[pos].y + rectRightCursor[pos].height/2 +i );
            }
        }
    }
    
    private void drawMainWindow() {
        try {
            // clear all
            g.clearRect(rectMain.x, rectMain.y, rectMain.width, rectMain.height);
            g.setColor(TConst.BACKGROUND);
            g.fillRect(rectMain.x, rectMain.y, rectMain.width, rectMain.height);
            g.setColor(TConst.FOREGROUND);
            g.drawRect(rectMain.x, rectMain.y, rectMain.width, rectMain.height);

            // draw main window
            g.setColor(TConst.FOREGROUND);
            for (int i = 0; i < TConst.MAIN_RECT; i++) {
                g.drawRect(rectBody[i].x, rectBody[i].y, rectBody[i].width, rectBody[i].height);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    
    private void drawTitleText() {
        try {
            // title
        	String name = scoreMgr.getPlayerName( pmData.currentUser );
        	int crRound = scoreMgr.getPlayerRound( pmData.currentUser );
        	if ( crRound > TConst.MAX_ROUND ) {
        		crRound = TConst.MAX_ROUND;
        	}
            String str  = "Round " + crRound + "/" + TConst.MAX_ROUND + "~" + name;
            g.setFont(ft_default);
            g.setColor(TConst.BACKGROUND);
            g.fillRect(rectBody[0].x, rectBody[0].y, rectBody[0].width, rectBody[0].height);
            g.setColor(TConst.FOREGROUND);
            g.drawRect(rectBody[0].x, rectBody[0].y, rectBody[0].width, rectBody[0].height);
            g.setColor(TConst.FOREGROUND);
            g.drawString(str, (rectMain.width-ft_default.getBBoxWidth(str))/2, rectBody[0].height-TConst.DIVIDE_MARGIN);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    private void drawRankText() {
        try {
            // draw rank
            String str = null;
            g.setFont(ft_default);
            g.setColor(TConst.FOREGROUND);
            for ( int i=0 ; i<TConst.SUB_CURSOR; i++) {
                if ( i == TConst.SUB_CURSOR-1 ) {
                    str = "BULL";
                } else {
                    str = "" + (20-i);
                }
                g.drawString(str, (rectMain.width-ft_default.getBBoxWidth(str))/2, rectLeftCursor[i].y + ft_default.getAscent() );
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    
    private void drawScoreAll() {
    	int score    = 0;
    	int saveUser = pmData.currentUser;
    	
    	pmData.currentUser = pmData.leftUser;
    	score = scoreMgr.getMarkScore(pmData);
    	drawScore(pmData.isLeft(), score);
    	pmData.currentUser = pmData.rightUser;
    	score = scoreMgr.getMarkScore(pmData);
    	drawScore(pmData.isLeft(), score);
    	
    	pmData.currentUser = saveUser;
    }
    
    private void drawScore(boolean left, int value) {
        String str = "" + value;

        if ( left ) {
            drawLeftScore( str );
        } else {
            drawRightScore( str );
        }
    }

    private void drawLeftScore(String str) {
        try {
            g.setFont(ft_default);
            g.setColor(TConst.BACKGROUND);
            g.fillRect(rectBody[3].x, rectBody[3].y, rectBody[3].width, rectBody[3].height);
            g.setColor(TConst.FOREGROUND);
            g.drawRect(rectBody[3].x, rectBody[3].y, rectBody[3].width, rectBody[3].height-1);
            g.setColor(getLeftColor());
            g.drawString(str, (rectMain.width/2-ft_default.getBBoxWidth(str))/2, rectMain.height - TConst.DIVIDE_MARGIN );
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    private void drawRightScore(String str) {
        try {
            g.setFont(ft_default);
            g.setColor(TConst.BACKGROUND);
            g.fillRect(rectBody[4].x, rectBody[4].y, rectBody[4].width, rectBody[4].height);
            g.setColor(TConst.FOREGROUND);
            g.drawRect(rectBody[4].x, rectBody[4].y, rectBody[4].width, rectBody[4].height-1);
            g.setColor(getRightColor());
            g.drawString(str, rectMain.width/2+(rectMain.width/2-ft_default.getBBoxWidth(str))/2, rectMain.height - TConst.DIVIDE_MARGIN );
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    
    private void drawRoundCircle(boolean left) {
        if ( left ) {
        	drawLeftRoundCircle();
        } else {
        	drawRightRoundCircle();
        }
    }

    private void drawRoundCircleAll() {
    	int saveUser = pmData.currentUser;
    	
    	pmData.currentUser = pmData.leftUser;
    	drawLeftRoundCircle();
    	pmData.currentUser = pmData.rightUser;
    	drawRightRoundCircle();
    	
    	pmData.currentUser = saveUser;
    }

    private void drawLeftRoundCircle() {
    	try {
        	int okCir = scoreMgr.getOneRoundCount( pmData );
			for (int i = 0; i < TConst.ONE_ROUND_COUNT; i++) {
				if ( i < okCir ){
		        	g.setColor(getLeftColor());
					g.fillArc(rectLeftRdCnt[i].x, rectLeftRdCnt[i].y, rectLeftRdCnt[i].width, rectLeftRdCnt[i].height, 0, 360);
				} else {
		        	g.setColor(TConst.BACKGROUND);
					g.fillArc(rectLeftRdCnt[i].x, rectLeftRdCnt[i].y, rectLeftRdCnt[i].width, rectLeftRdCnt[i].height, 0, 360);
		        	g.setColor(getLeftColor());
					g.drawArc(rectLeftRdCnt[i].x, rectLeftRdCnt[i].y, rectLeftRdCnt[i].width, rectLeftRdCnt[i].height, 0, 360);
				}
			}
		} catch (Exception e) {
            System.out.println(e.getMessage());
		}
    }

    private void drawRightRoundCircle() {
    	try {
        	int okCir = scoreMgr.getOneRoundCount( pmData );
			for (int i = 0; i < TConst.ONE_ROUND_COUNT; i++) {
				if ( i < okCir ){
		        	g.setColor(getRightColor());
					g.fillArc(rectRightRdCnt[i].x, rectRightRdCnt[i].y, rectRightRdCnt[i].width, rectRightRdCnt[i].height, 0, 360);
				} else {
		        	g.setColor(TConst.BACKGROUND);
					g.fillArc(rectRightRdCnt[i].x, rectRightRdCnt[i].y, rectRightRdCnt[i].width, rectRightRdCnt[i].height, 0, 360);
		        	g.setColor(getRightColor());
					g.drawArc(rectRightRdCnt[i].x, rectRightRdCnt[i].y, rectRightRdCnt[i].width, rectRightRdCnt[i].height, 0, 360);
				}
			}
		} catch (Exception e) {
            System.out.println(e.getMessage());
		}
    }

    private Font getSuiteFont() {
        Font ft = Font.getFont(Font.FACE_SYSTEM | Font.SIZE_LARGE | Font.STYLE_BOLD);

        if ( ft.getAscent() > rectBody[0].height ) {
            ft = Font.getFont(Font.FACE_SYSTEM | Font.SIZE_MEDIUM | Font.STYLE_BOLD);
            if ( ft.getAscent() > rectBody[0].height ) {
                ft = Font.getFont(Font.FACE_SYSTEM | Font.SIZE_SMALL | Font.STYLE_BOLD);
                if ( ft.getAscent() > rectBody[0].height ) {
                    ft = Font.getFont(Font.FACE_SYSTEM | Font.SIZE_TINY | Font.STYLE_BOLD);
                }
            }
        }
        ft_default = ft;
        
        return ft;
    }
    
    private int getLeftColor(){
        return TConst.getTermColor(pmData.leftUser);
    }
    private int getRightColor(){
        return TConst.getTermColor(pmData.rightUser);
    }
    
    private void getRectsValue() {
        // 儊僀儞
        rectMain.x = 0;
        rectMain.y = 0;
        rectMain.width  = getWidth();
        rectMain.height = getHeight();
        
        // 儃僨傿
        int unitX = rectMain.width / TConst.DIVIDE_MAIN_X;
        int unitY = rectMain.height / TConst.DIVIDE_MAIN_Y;
        rectBody[0] = new TRectangle();     // Top
        rectBody[0].x = 0;
        rectBody[0].y = 0;
        rectBody[0].width  = rectMain.width;
        rectBody[0].height = unitY;
        rectBody[1] = new TRectangle();     // Middle, left
        rectBody[1].x = 0;
        rectBody[1].y = unitY;
        rectBody[1].width  = unitX;
        rectBody[1].height = rectMain.height - unitY * 2;
        rectBody[2] = new TRectangle();     // Middle, right
        rectBody[2].x = rectMain.width - unitX;
        rectBody[2].y = unitY;
        rectBody[2].width  = unitX;
        rectBody[2].height = rectMain.height - unitY * 2;
        rectBody[3] = new TRectangle();     // Bottom, left
        rectBody[3].x = 0;
        rectBody[3].y = rectMain.height - unitY;
        rectBody[3].width  = rectMain.width / 2;
        rectBody[3].height = unitY;
        rectBody[4] = new TRectangle();     // Bottom, right
        rectBody[4].x = rectMain.width / 2;
        rectBody[4].y = rectMain.height - unitY;
        rectBody[4].width  = rectMain.width / 2;
        rectBody[4].height = unitY;
        
        // Cursor: Left & Right
        int length = ( rectBody[1].height-TConst.DIVIDE_MARGIN*(TConst.DIVIDE_SUB_CURSOR+1) ) / TConst.DIVIDE_SUB_CURSOR ;
        int margin = TConst.DIVIDE_MARGIN ;
        int offset = ( rectBody[1].width - length ) / 2;
        for ( int i=0; i<TConst.SUB_CURSOR ; i++ ) {
            // left
            rectLeftCursor[i] = new TRectangle();
            rectLeftCursor[i].x      = offset;
            rectLeftCursor[i].y      = rectBody[1].y + margin * (i+1) + length * i;
            rectLeftCursor[i].width  = length;
            rectLeftCursor[i].height = length;
            // right
            rectRightCursor[i] = new TRectangle();
            rectRightCursor[i].x      = rectMain.width - length - offset;
            rectRightCursor[i].y      = rectBody[1].y + margin * (i+1) + length * i;
            rectRightCursor[i].width  = length;
            rectRightCursor[i].height = length;
        }

		// circle count
        int z = 3;
		int x = TConst.CIRCLE_WIDTH;
		if ( x >= offset ) {
			x = offset + z;
		}
		int y = rectMain.height - unitY - (x + z) * 3;
        for ( int i=0; i<TConst.ONE_ROUND_COUNT ; i++ ) {
            // left
            rectLeftRdCnt[i]        = new TRectangle();
            rectLeftRdCnt[i].x      = z;
            rectLeftRdCnt[i].y      = y + (x + z) * i;
            rectLeftRdCnt[i].width  = x;
            rectLeftRdCnt[i].height = x;
            // right
            rectRightRdCnt[i]        = new TRectangle();
            rectRightRdCnt[i].x      = rectMain.width - x - z;
            rectRightRdCnt[i].y      = y + (x + z) * i;
            rectRightRdCnt[i].width  = x;
            rectRightRdCnt[i].height = x;
        }
    }
    
    private void setSoftkeyName() {
        /* 僜僼僩僉乕侾儔儀儖偺愝掕 */
        setSoftLabel(SOFT_KEY_1, "栠傞");
        /* 僜僼僩僉乕俀儔儀儖偺愝掕 */
        setSoftLabel(SOFT_KEY_2, "摑寁");
    }

    private void isGameOver() {
    	if ( isGameOverByClose() || scoreMgr.isGameOverByRound() ) {
    		gameOver = true;
    		String name = scoreMgr.getWinnerPlayerName();
        	String title  = " 僎乕儉丂僆乕僶乕 ";
        	Dialog dialog = new Dialog(Dialog.DIALOG_INFO, title);
            dialog.setText("僎乕儉廔椆丅\n\n丂彑幰丗" + name + "\n");
            dialog.show();
    	}
    }

}

⌨️ 快捷键说明

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