common.java

来自「j2me 连连看源代码」· Java 代码 · 共 134 行

JAVA
134
字号

import javax.microedition.lcdui.Font;

/*
 * Created on 2006-1-18
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author aaron
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Common {
	
	//#if S176_220
	//# public static short SCREEN_WIDTH = 176;
    //# public static short SCREEN_HEIGHT = 220;
    //# public static short VIEW_WIDTH = 176;
    //# public static short VIEW_HEIGHT = 208;
	//#endif
	
	//#if S176_208
	//# public static short SCREEN_WIDTH = 176;
    //# public static short SCREEN_HEIGHT = 208;
    //# public static short VIEW_WIDTH = 176;
    //# public static short VIEW_HEIGHT = 208;
    //#endif
	
	//#if S208_208
	//# public static short SCREEN_WIDTH = 208;
    //# public static short SCREEN_HEIGHT = 208;
    //# public static short VIEW_WIDTH = 176;
    //# public static short VIEW_HEIGHT = 208;
    //#endif
    
    //#if S176_204
    //# public static short SCREEN_WIDTH = 176;
    //# public static short SCREEN_HEIGHT = 204;
    //# public static short VIEW_WIDTH = 176;
    //# public static short VIEW_HEIGHT = 204;
    //#endif
    
    //#if S40 || K500
    //# 
    //#if V872
    //# public static short SCREEN_WIDTH = 128;
    //# public static short SCREEN_HEIGHT = 142;
    //#else
    //# public static short SCREEN_WIDTH = 128;
    //# public static short SCREEN_HEIGHT = 128;
    //#endif
    //# 
    //# public static short VIEW_WIDTH = 128;
    //# public static short VIEW_HEIGHT = 128;
    //#endif
    
    //#if S240_320 || S240_260
    public static short SCREEN_WIDTH = 240;
    public static short SCREEN_HEIGHT = 320;
    public static short VIEW_WIDTH = 240;
    public static short VIEW_HEIGHT = 240;
    //#endif
	
    public static short SCREEN_HALF_WIDTH = (short) (MainGame.screen_width >> 1);
    public static short SCREEN_HALF_HEIGHT = (short) (MainGame.screen_height >> 1);
    public static final int FONT_LINE_H = MainGame.font .getHeight()+1;
    
    //#if MEDIUM
	//# public static final byte TILE_WIDTH = 16;  // the pixel width of the tile
	//# public static final byte TILE_HEIGHT = 16; // the pixel height of the tile
	//#endif
	//#if SMALL
	//# public static final byte TILE_WIDTH = 12;  // the pixel width of the tile
	//# public static final byte TILE_HEIGHT = 12; // the pixel height of the tile
	//#endif
	
    //#if BIG
	public static final byte TILE_WIDTH = 20;  // the pixel width of the tile
	public static final byte TILE_HEIGHT = 20; // the pixel height of the tile
	//#endif

    
	public static final byte ROW_COUNT = 11;   // the number of row 
	public static final byte LINE_COUNT = 12;   // the number of line
		
	//a general method to split the string
    //but you must dedignate the parameter cFlag
	public static String[] splitString(String sStr,char cFlag,int iLines){
		String[] aResult=new String[iLines];
		int iIndex;
		for(int i=0;i<iLines;i++){
			iIndex=sStr.indexOf(cFlag);
			aResult[i]=sStr.substring(0,iIndex);
			// System.out.println(aResult[i]);
			sStr=sStr.substring(iIndex+1);
		}
		return aResult;
	}
	
	public static String[] splitString(String sStr,Font pFont,int iW){
	if(sStr==null || pFont==null){
	return null;
	}
	StringBuffer sStrBuff=new StringBuffer(sStr);
	char[] aChars=sStr.toCharArray();
	int iLength=aChars.length;
	int iTempW=0;
	int iLines=0;    //  to calculate how many lines the string will be splited
	int iCounter=0;  //  to calculate how many chars added to the string
	for(int i=0;i<iLength;i++){
	if(aChars[i]=='\n'){
	iLines++;
	iTempW=0;
	continue;
	}
	
	iTempW+=pFont.charWidth(aChars[i]);
	if(iTempW>iW){
	sStrBuff=sStrBuff.insert(i+iCounter,'\n');
	iLines++;
	iCounter++;
	iTempW=pFont.charWidth(aChars[i]);
	}
	}
	iLines++;
	sStrBuff=sStrBuff.append('\n');
	return splitString(sStrBuff.toString(),'\n',iLines);
	}
}

⌨️ 快捷键说明

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