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

📄 maincanvas.java

📁 Source code for j2me game WordSearch
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
//Author Jeremiah McLeod xdebugx http://www.xdebugx.netpackage wordSearch20;import java.util.*;import javax.microedition.lcdui.*;//import javax.microedition.lcdui.game.*;public class mainCanvas extends Canvas {  static int CORNER_X;  static int CORNER_Y;   Display myDisplay;  wordSearch20 myWordSearch;  static boolean go;  private int letSpacer;  private int width,height;  private boolean upDown;  int boardN[]=new int[150];  int letMatSize,listX;  int res;  Random myRandom = new Random();  boolean myInitialized;  Image lets;  int R,G,B,targetR,targetG,targetB,spect;  private int letStart;  private int letsWidth,letsHeight;  static boolean myImagesLoaded;    int wordDirection[] = new int [10];     int wordPlace[] = new int [10];     int wordFoundFirstPlaceX[]=new int[10];     int wordFoundFirstPlaceY[]=new int[10];     int wordFoundLastPlaceX[]=new int[10];     int wordFoundLastPlaceY[]=new int[10];      boolean boardColor[] = new boolean [150];     final int numWords=10; String wordsRead[] = new String [10]; int lettersSel;  int lastPlaceX=0;  int lastPlaceY=0;   int firstPlaceX=0;   int firstPlaceY=0;   int secPlaceX=0;   int secPlaceY=0;  char board[] = new char [150];  boolean boardLetSel[]= new boolean [150];    boolean wordFound[] = new boolean[25];  char Cwords[] [] = new char [10] [25];  String words[] = new String [180];   int lettersPerWord [] = new int [14];   int letWidth,letHeight;   int squareX,squareY;    private boolean notBuffered;       private Image imgDoubleBuffer;       private Graphics doubleBuffer;   Image letsBlue,splash;   Image letsAlpha[]=new Image [26];   Image letsAlphaBlue[]=new Image [26]; public mainCanvas(wordSearch20 midlet) {  //  super(false);    myDisplay = Display.getDisplay(midlet);    myWordSearch = midlet;    myInitialized=false;    go=false;    notBuffered=false;  }  void start() {    myDisplay.setCurrent(this);    repaint();  }  void reset() {     }  //-------------------------------------------------------  //  graphics methods  /**   * paint the game graphic on the screen.   */  public void paint(Graphics g) {	  Graphics saved=null;	  int index;	  String letter;	  String word;	  int gg;	  int directionAddition;	  boolean foundPlace;	  // Class c = this.getClass();	  		int p,t,h,i;    // perform the calculations if necessary:    if(!myInitialized) {		myRandom=new Random ((long)(32));		 myRandom = new Random(System.currentTimeMillis());		for (p=0;p<10;p++) wordFound[p]=false;		upDown=false;	 	R=0+getRandomInt(250);		G=0+getRandomInt(250);		B=0+getRandomInt(250);		spect=0+getRandomInt(3);		targetR=0+getRandomInt (250);		targetG=0+getRandomInt (250);		targetB=0+getRandomInt (250);			if (spect==0) {				if (targetR==R) targetR+=10;				if (targetR>R) upDown=true; else upDown=false;			}			if (spect==1) {				if (targetG==G) targetG+=10;				if (targetG>G) upDown=true; else upDown=false;			}			if (spect==2) {				if (targetB==B) targetB+=10;				if (targetB>B) upDown=true; else upDown=false;			}if (R>254) R=125;if (G>254) G=125;if (B>254) B=125;if (R<0) R=0;if (G<0) G=0;if (B<0) B=0;		notBuffered=this.isDoubleBuffered();	      CORNER_X = g.getClipX();	      CORNER_Y = g.getClipY();	      width= g.getClipWidth();	      height = g.getClipHeight();		  res=0;		  if (width>170) res=1;		  if (width>230) res=3;		  if (width>330) res=2;	squareX=1;	squareY=1;	   letStart=0;	   lettersSel=0;if (res==0) {	letSpacer=2;	letWidth=5;    letHeight=5;}if (res==1) {letSpacer=2;letWidth=7;letHeight=11;}if (res==2) {letSpacer=4;letWidth=12;letHeight=14;}if (res==3) {letSpacer=4;letWidth=9;letHeight=14;}letMatSize=13*(letWidth+letSpacer);listX=letMatSize+2;  setWords();setBoard();       if (notBuffered==true) {	  	  			imgDoubleBuffer=Image.createImage (width,height);	  	  			doubleBuffer=imgDoubleBuffer.getGraphics ();			}		myImagesLoaded=false;      myInitialized = true;    }     if (notBuffered==true) {			saved=g;			g=imgDoubleBuffer.getGraphics();			}    if (go==true) {	int inc=1;if (spect==0) {if (upDown==true) R+=inc; else R-=inc;if ((upDown==true && R>targetR)||(upDown==false && R<targetR)) {	targetR=0+getRandomInt (250);	spect=0+getRandomInt(3);	if (spect==0) {		if (targetR==R) targetR+=1;		if (targetR>R) upDown=true; else upDown=false;	}	if (spect==1) {		if (targetG==G) targetG+=1;		if (targetG>G) upDown=true; else upDown=false;	}	if (spect==2) {		if (targetB==B) targetB+=1;		if (targetB>B) upDown=true; else upDown=false;	}}}if (spect==1) {if (upDown==true) G+=inc; else G-=inc;if ((upDown==true && G>targetG)||(upDown==false && G<targetG)) {	targetG=0+getRandomInt (250);	spect=0+getRandomInt(3);		if (spect==0) {			if (targetR==R) targetR+=1;			if (targetR>R) upDown=true; else upDown=false;		}		if (spect==1) {			if (targetG==G) targetG+=1;			if (targetG>G) upDown=true; else upDown=false;		}		if (spect==2) {			if (targetB==B) targetB+=1;			if (targetB>B) upDown=true; else upDown=false;		}}}if (spect==2) {if (upDown==true) B+=inc; else B-=inc;if ((upDown==true && B>targetB)||(upDown==false && B<targetB)) {	targetB=0+getRandomInt (250);	spect=0+getRandomInt(3);		if (spect==0) {			if (targetR==R) targetR+=1;			if (targetR>R) upDown=true; else upDown=false;		}		if (spect==1) {			if (targetG==G) targetG+=1;			if (targetG>G) upDown=true; else upDown=false;		}		if (spect==2) {			if (targetB==B) targetB+=1;			if (targetB>B) upDown=true; else upDown=false;		}}}if (R>253) R=253;if (G>253) G=253;if (B>253) B=253;if (R<0) R=0;if (G<0) G=0;if (B<0) B=0;	g.setColor(R,G,B);	g.fillRect (0,0,width,height);	boardToN();	g.setColor (255,255,255);	g.fillRect (0,0,13*(letWidth+letSpacer),11*(letHeight+letSpacer));	g.fillRect (listX,0,(letWidth+1)*7,10*(letHeight+letSpacer));	for (t=0;t<11;t++)	for (p=0;p<13;p++) {	//	g.setClip (0+p*(letWidth+letSpacer),0+t*(letHeight+letSpacer)-1,letWidth,letHeight);		g.drawImage (letsAlpha[(int)(boardN[p+(t*13)])],0+(p*(letWidth+letSpacer)),0+t*(letHeight+letSpacer),0);	}for (p=0;p<10;p++)	for (t=0;t<lettersPerWord[p];t++)		for (i=0;i<26;i++) if ((char) (i+97)==Cwords [p][t]) {			//g.setClip (listX+(t*(letWidth+1)),0+(p*(letHeight+letSpacer)),letWidth,letHeight);			if (wordFound[p]==false) g.drawImage (letsAlpha[i],listX+(t*(letWidth+1)),p*(letHeight+letSpacer),0);			else			g.drawImage (letsAlphaBlue[i],listX+(t*(letWidth+1)),p*(letHeight+letSpacer),0);			}g.setColor (0,0,255);int saveFirstPlaceX=firstPlaceX;int saveLastPlaceX=lastPlaceX;int saveSecPlaceX=secPlaceX;int saveFirstPlaceY=firstPlaceY;int saveLastPlaceY=lastPlaceY;int saveSecPlaceY=secPlaceY;for (p=0;p<10;p++) {	if (wordFound[p]==true) {		firstPlaceX=wordFoundFirstPlaceX[p];		lastPlaceX=wordFoundLastPlaceX[p];		firstPlaceY=wordFoundFirstPlaceY[p];		lastPlaceY=wordFoundLastPlaceY[p];if (wordDirection[p]==0) {	secPlaceX=firstPlaceX;	secPlaceY=firstPlaceY-1;}if (wordDirection[p]==1) {	secPlaceX=firstPlaceX;	secPlaceY=firstPlaceY+1;}if (wordDirection[p]==2) {	secPlaceX=firstPlaceX-1;	secPlaceY=firstPlaceY;}if (wordDirection[p]==3) {	secPlaceX=firstPlaceX+1;	secPlaceY=firstPlaceY;}if (wordDirection[p]==4) {

⌨️ 快捷键说明

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