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

📄 gamemanager.java

📁 一个关于沉船的J2ME小游戏
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
 					gameEffects.playCrash();
				if (this.inGamePause(50))
				{
					closePressed();
				}
				break;

			case GM_LEVEL_BONUS:
				if (this.inGamePause(4))
				{
					if (this.plane.moveDown())
					{
						this.redrawAll();
						this.status = GM_LANDED;
						gameEffects.playComplete();
					}
					else
					{
						this.bonus++;
						this.score += 10;
						this.redrawAll();
					}
				}
				break;
		}
	}

	boolean inGamePause(int count)
	{
		this.ticks++;
		if (this.ticks >= count || this.gameActionFire == 1)
		{
			this.gameActionFire = 0;
			this.ticks = 0;
			return true;
		}
		return false;
	}

	void initLevel()
	{
		int blocks, speedInc;

		speedInc = 21 / (this.level + 1);
		if (speedInc < 5) speedInc = 5;
		blocks = (this.level * 20) + this.buildInit;
		if (blocks > this.buildMax) blocks = this.buildMax;
		this.plane.init(1, speedInc);
		this.bomb.status = 0;
		this.initCity(blocks);
		this.redrawAll();
	}

	// Make the city
	public void initCity(int buildSize)
	{
		Building building;
		int	maxAttempt = 500, iRand, prevColor = 0, firstLayer;
		boolean firstPass = true;

		firstLayer = buildSize - this.maxBuilding;
		this.buildingLeft = buildSize;
		while (buildSize > 0)
		{
			for (int i = 0; i < this.maxBuilding; i++)
			{
				building = (Building) city.elementAt(i);
				iRand = Util.getRandomInt(0, 100);
				if ((buildSize > firstLayer || iRand < 50 || maxAttempt <= 0) && building.blocks < this.buildMaxCol)
				{
					// Decide what color the building is going to be
					if (firstPass)
					{
						iRand /= 25;
						if (iRand == prevColor) iRand++;
						if (iRand > 3) iRand = 0;
						prevColor = iRand;
						building.color = iRand * this.buildsize;
						building.hit = false;
						building.blocks = 0;
					}
					building.blocks++;
					buildSize--;
				}
				if (buildSize == 0) break;
			}
			firstPass = false;
			maxAttempt--;
		}
	}

	boolean collision()
	{
		int ix, iy;
		Building building;

		ix = (this.plane.getX() + this.iColOffsetC) / this.buildsize;
		iy = this.iColOffsetA - (this.plane.getY() + this.iColOffsetB) / this.buildsizeY;
		if (ix >= 0 && ix < this.maxBuilding)
		{
			building = (Building) city.elementAt(ix);
			if (building.blocks >= iy)
			{
				return true;
			}
		}

		if (this.bomb.status == 0) return false;
		ix = (this.bomb.x - this.buildstart) / this.buildsize;
		iy = this.iColOffsetA - ((this.bomb.y + this.iColOffsetB) / this.buildsizeY);
		if (ix >= 0 && ix < this.maxBuilding)
		{
			building = (Building) city.elementAt(ix);
			if (building.blocks > iy && iy >= 0)
			{
				building.blocks = iy;
				building.hit = true;
				this.bomb.strength--;
				this.bomb.columnHit = ix;
				if (this.bomb.strength <= 0) this.bomb.status = 0;
				this.buildingLeft--;
				this.score+=10;
				this.redrawScore = true;
				if (this.buildingLeft <= 0)
				{
					this.bomb.status = 0;
					this.status = GM_LEVEL_BONUS;
				}
			}
		}

		return false;
	}

	public Canvas getCanvas()
    	{
        	return canvas;
    	}

    private void drawBackground(Graphics g)
    {
		Building building;
		int ix;

//if (true) return;
		if (this.redrawBackground)
		{
			// Redraw the whole background
			g.setClip(0, 0, this.gameWidth, this.gameHeight);
			g.drawImage(this.gfx, 0, 0, Graphics.TOP | Graphics.LEFT);
			this.redrawBackground = false;
		}
		else
		{
			// Restore the background of any previously draw gfx

			// 1. Restore background of the plane at old location
			g.setClip(this.plane.getOldX(),this.plane.getOldY(),this.plane.getWidth(),this.plane.getHeight());
			g.drawImage(this.gfx, 0, 0, Graphics.TOP | Graphics.LEFT);

			// 2. Restore background of the bomb at old location
			if (this.bomb.redraw)
			{
				g.setClip(this.bomb.oldX, this.bomb.oldY, this.bomb.width, this.bomb.height);
				g.drawImage(this.gfx, 0, 0, Graphics.TOP | Graphics.LEFT);
				this.bomb.redraw = false;
			}

			// 3. Restore BG where building is now part building
			if (this.bomb.columnHit != -1)
			{
				ix = this.bomb.columnHit;
				building = (Building) city.elementAt(ix);
				// Draw broken bit if there is any of the column left
				if (building.blocks >= 0)
				{
					g.setClip((ix * this.buildsize) + this.buildstart, this.ground - (building.blocks * this.buildsizeY), this.buildsize, this.buildsizeY);
					g.drawImage(this.gfx, 0, 0, Graphics.TOP | Graphics.LEFT);
//					g.drawImage(this.gfx, 0, -(this.gfxStart), Graphics.TOP | Graphics.LEFT);
				}
			}

			// 4. Redraw BG where the score is displayed
			if (this.redrawScore)
			{
				if (this.scoreStyle == 1)
				{
					g.setClip(0, this.gameHeight - this.scoreHeight, this.gameWidth, this.scoreHeight);
					g.drawImage(this.gfx, 0, 0, Graphics.TOP | Graphics.LEFT);
				}
				else
				{
					g.setClip(0, this.scoreY, this.gameWidth, this.scoreHeight);
					g.drawImage(this.gfx, 0, 0, Graphics.TOP | Graphics.LEFT);
				}
			}

		}
    }

	public void paint(Graphics g)
	{
		Building building;
		int ix;

		if (this.status == GM_NEW_GAME || (this.status == GM_NEW_LEVEL && this.ticks <= 1)) return;

		// Fudge to get score to display on 3510i
		if (this.scoreStyle != 1 && this.plane.y <= 5) this.redrawScore = true;
		// draw/redraw the background
		drawBackground(g);

		// Draw Buildings if required
		if (this.redrawBuilding)
		{
			this.redrawBuilding = false;
			for (ix = 0; ix < this.maxBuilding; ix++)
			{
				building = (Building) city.elementAt(ix);
				if (building.blocks == 0) continue;
				for (int iy = 1; iy < (building.blocks); iy++)
				{
					g.setClip((ix * this.buildsize) + this.buildstart, this.ground - (iy * this.buildsizeY), this.buildsize, this.buildsizeY);
					g.drawImage(this.loaded, ((ix * this.buildsize) + this.buildstart) - (this.build1 + building.color), (this.ground - (iy * this.buildsizeY)) - gfxStart, Graphics.TOP | Graphics.LEFT);
				}

				g.setClip((ix * this.buildsize) + this.buildstart, this.ground - (building.blocks * this.buildsizeY), this.buildsize, this.buildsizeY);
				if (building.hit)
					g.drawImage(this.loaded, ((ix * this.buildsize) + this.buildstart) - (this.build2 + building.color), (this.ground - (building.blocks * this.buildsizeY)) - gfxStart, Graphics.TOP | Graphics.LEFT);
				else
					g.drawImage(this.loaded, ((ix * this.buildsize) + this.buildstart) - (this.build3 + building.color), (this.ground - (building.blocks * this.buildsizeY)) - gfxStart, Graphics.TOP | Graphics.LEFT);

			}
		}
		else
		{
			// Check to see if a block has just been hit.
			if (this.bomb.columnHit != -1)
			{
				// If so we need to draw the broken bit after the background redraw
				ix = this.bomb.columnHit;
				building = (Building) city.elementAt(ix);
				// Draw broken bit if there is any of the column left
				if (building.blocks != 0)
				{
					g.setClip((ix * this.buildsize) + this.buildstart, this.ground - (building.blocks * this.buildsizeY), this.buildsize, this.buildsizeY);
					g.drawImage(this.loaded, ((ix * this.buildsize) + this.buildstart) - (this.build2 + building.color), (this.ground - (building.blocks * this.buildsizeY)) - gfxStart, Graphics.TOP | Graphics.LEFT);
				}
				this.bomb.columnHit = -1;
			}
		}

		// Draw the Bomb
		if (this.bomb.status != 0)
		{
			g.setClip(this.bomb.x, this.bomb.y, this.bomb.width, this.bomb.height);
			g.drawImage(this.loaded, this.bomb.x - this.plane.getWidth(), this.bomb.y - gfxStart, Graphics.TOP | Graphics.LEFT);
		}

		// Draw the plane at the new location
		if (this.status == GM_CRASH || this.status == GM_HISCORE)
		{
			g.setClip(this.plane.getX(),this.plane.getY(),this.plane.getWidth(),this.plane.getHeight());
			g.drawImage(this.loaded,this.plane.getX() - this.planeCrash,this.plane.getY() - gfxStart, Graphics.TOP | Graphics.LEFT);
		}
		else
		{
			g.setClip(this.plane.getX(),this.plane.getY(),this.plane.getWidth(),this.plane.getHeight());
			g.drawImage(this.loaded,this.plane.getX(),this.plane.getY() - gfxStart, Graphics.TOP | Graphics.LEFT);
 		}

		g.setClip(0,0, this.gameWidth, this.gameHeight);
		g.setFont(GAME_FONT);

        StringBuffer buf = new StringBuffer("");
        StringBuffer bufScore = new StringBuffer("");
		StringBuffer bufBonus = new StringBuffer("");

		// Is the level complete?
		if (this.status == GM_LANDED && this.ticks < 45)
		{
	        buf.append(this.dict.getString(Dictionary.TEXT_GAME_LEVEL_COMPLETE));
	        g.setColor(0,0,0);
			g.drawString(buf.toString(), this.gameWidth / 2, (this.gameHeight / 2) + 5, Graphics.HCENTER | Graphics.BOTTOM );
      	    g.setColor(255,255,255);
			g.drawString(buf.toString(), (this.gameWidth / 2) - 1, (this.gameHeight / 2) + 4, Graphics.HCENTER | Graphics.BOTTOM );
		}
		// Is this a new level?
		if (this.status == GM_NEW_LEVEL)
		{
	        buf.append(this.dict.getString(Dictionary.TEXT_GAME_LEVEL));
			buf.append(this.level);
	    	g.setColor(0,0,0);
			g.drawString(buf.toString(), this.gameWidth / 2, this.gameHeight / 2, Graphics.HCENTER | Graphics.BOTTOM );
      	    g.setColor(255,255,255);
			g.drawString(buf.toString(), (this.gameWidth / 2) - 1, (this.gameHeight / 2) - 1, Graphics.HCENTER | Graphics.BOTTOM );
		}
		// Do we have a new hi score
		if (this.status == GM_HISCORE)
		{
			buf.append(this.dict.getString(Dictionary.TEXT_GAME_NEW_HISCORE));
			if (this.scoreStyle ==1)
			{
				buf.append(this.score);
				g.setColor(0,0,0);
				g.drawString(buf.toString(), this.gameWidth / 2, this.gameHeight / 2, Graphics.HCENTER | Graphics.BOTTOM );
				g.setColor(255,255,255);
				g.drawString(buf.toString(), (this.gameWidth / 2) - 1, (this.gameHeight / 2) - 1, Graphics.HCENTER | Graphics.BOTTOM );
			}
			if (this.scoreStyle != 1)
			{
		    	StringBuffer bufTemp = new StringBuffer("");
				bufTemp.append(this.score);
				g.setColor(0,0,0);
				g.drawString(buf.toString(), this.gameWidth / 2, (this.gameHeight / 2) - 7, Graphics.HCENTER | Graphics.BOTTOM );
				g.drawString(bufTemp.toString(), this.gameWidth / 2, (this.gameHeight / 2) + 7, Graphics.HCENTER | Graphics.BOTTOM );
				g.setColor(255,255,255);
				g.drawString(buf.toString(), (this.gameWidth / 2) - 1, (this.gameHeight / 2) - 8, Graphics.HCENTER | Graphics.BOTTOM );
				g.drawString(bufTemp.toString(), (this.gameWidth / 2) - 1, (this.gameHeight / 2) + 6, Graphics.HCENTER | Graphics.BOTTOM );
			}
		}
		if (this.status == GM_CRASH)
		{
	        buf.append(this.dict.getString(Dictionary.TEXT_GAME_YOU_LOST));
	        g.setColor(0,0,0);
			g.drawString(buf.toString(), this.gameWidth / 2, this.gameHeight / 2, Graphics.HCENTER | Graphics.BOTTOM );
      	    g.setColor(255,255,255);
			g.drawString(buf.toString(), (this.gameWidth / 2) - 1, (this.gameHeight / 2) - 1, Graphics.HCENTER | Graphics.BOTTOM );
		}

		if (this.status == GM_LEVEL_BONUS || (this.status == GM_LANDED && this.ticks < 45))
		{
	        bufBonus.append(this.dict.getString(Dictionary.TEXT_GAME_LEVEL_BONUS));
			bufBonus.append(this.bonus);
			bufBonus.append(" X 10 = ");
			bufBonus.append((this.bonus * 10));
	        g.setColor(0,0,0);
			g.drawString(bufBonus.toString(), this.gameWidth / 2, ((this.gameHeight / 2) + 5) - this.fontHeight, Graphics.HCENTER | Graphics.BOTTOM );
      	    g.setColor(255,255,255);
			g.drawString(bufBonus.toString(), (this.gameWidth / 2) - 1, ((this.gameHeight / 2) + 4) - this.fontHeight, Graphics.HCENTER | Graphics.BOTTOM );
		}

        g.setColor(255,255,0);
		if (this.redrawScore)
		{
			if (this.scoreStyle == 1)
			{
		        bufScore.append(this.score);
				g.drawString(bufScore.toString(), this.scoreX,this.gameHeight - this.scoreY, Graphics.BOTTOM|Graphics.LEFT );
			}
			else
			{
				int iUnit, iTen, iHund, iThou,iTenThou;
				iUnit    = (this.score % 10) << 2;
				iTen     = ((this.score / 10) % 10) << 2;
				iHund    = ((this.score / 100) % 10) << 2;
				iThou    = ((this.score / 1000) % 10) << 2;
				iTenThou = ((this.score / 10000) % 10) << 2;

				g.setClip(this.scoreX, this.scoreY, 4,5);
				g.drawImage(this.loaded, (-iTenThou + this.scoreX), (-82 + this.scoreY), Graphics.TOP|Graphics.LEFT);
				g.setClip(this.scoreX + 4, this.scoreY, 4,5);
				g.drawImage(this.loaded, (-iThou + this.scoreX + 4), (-82 + this.scoreY), Graphics.TOP|Graphics.LEFT);
				g.setClip(this.scoreX + 8, this.scoreY, 4,5);
				g.drawImage(this.loaded, (-iHund + this.scoreX + 8), (-82 + this.scoreY), Graphics.TOP|Graphics.LEFT);
				g.setClip(this.scoreX + 12, this.scoreY, 4,5);
				g.drawImage(this.loaded, (-iTen + this.scoreX + 12), (-82 + this.scoreY), Graphics.TOP|Graphics.LEFT);
				g.setClip(this.scoreX + 16, this.scoreY, 4,5);
				g.drawImage(this.loaded, (-iUnit + this.scoreX + 16), (-82 + this.scoreY), Graphics.TOP|Graphics.LEFT);

			}
			this.redrawScore = false;
		}


//            buf.append(iDEBUG);
//		g.drawString(this.DEBUG, 5,5, Graphics.TOP|Graphics.LEFT );
//		g.drawString(buf.toString(), 5,1, Graphics.TOP|Graphics.LEFT );

//            StringBuffer buf2 = new StringBuffer("");
//            buf2.append(iDEBUG2);
//		g.drawString(buf2.toString(), 5,10, Graphics.TOP|Graphics.LEFT );

	}


	void endDebug(long one, long two, long three, long four, long five,
			  long six, long seven, long eight, long nine, long ten)
	{
		StringBuffer buf1 = new StringBuffer("");
		StringBuffer buf2 = new StringBuffer("");
		StringBuffer buf3 = new StringBuffer("");
		StringBuffer buf4 = new StringBuffer("");
		StringBuffer buf5 = new StringBuffer("");
		StringBuffer buf6 = new StringBuffer("");
		StringBuffer buf7 = new StringBuffer("");
		StringBuffer buf8 = new StringBuffer("");
		StringBuffer buf9 = new StringBuffer("");
		StringBuffer buf10 = new StringBuffer("");
            buf1.append(one);
            buf2.append(two);
            buf3.append(three);
            buf4.append(four);
            buf5.append(five);
            buf6.append(six);
            buf7.append(seven);
            buf8.append(eight);
            buf9.append(nine);
            buf10.append(ten);
           	throw new IllegalArgumentException(
     	        	                       "Global : "
							+ DEBUG
							+ " "
							+ buf1.toString()
							+ " "
							+ buf2.toString()
							+ " "
							+ buf3.toString()
							+ " "
							+ buf4.toString()
							+ " "
							+ buf5.toString()
							+ " "
							+ buf6.toString()
							+ " "
							+ buf7.toString()
							+ " "
							+ buf8.toString()
							+ " "
							+ buf9.toString()
							+ " "
							+ buf10.toString()
							);
	}

}

⌨️ 快捷键说明

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