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

📄 gameoverwinframe.java

📁 简单的用Java做的小游戏主要是用了自己的框架来
💻 JAVA
字号:
package frame;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

import role.BaseRole;
import role.Chip;
import role.Dale;
import role.Flame;
import role.StreamBall;
import role.WinChip;
import assistant.PublicVar;
import assistant.Music;
import assistant.TrackerWinImage;

public class GameOverWinFrame extends JFrame implements Runnable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 579073533873337660L;

	/** 花园图片 */
	public static Image gameOverWinImage = new ImageIcon("image/garden.jpg")
			.getImage();

	/** 汽球图片 */
	public static Image steamBallImage = new ImageIcon("image/steamBall.gif")
			.getImage();

	/** 花心图片 */
	public static Image hartImage = new ImageIcon("image/hart.gif").getImage();

	/** 取得双缓冲画布 */
	private Image memoryImage;

	/** 产生双缓冲画笔 */
	private Graphics memoryGraphics;

	/** 媒体追踪器tracker */
	private MediaTracker tracker;

	public static Image[][] daleImage;

	/** 烟花产生计数器 */
	private int flameCount;

	/** 松鼠 */
	public static Chip chip;

	/** 角色产生计数器 */
	private int count;

	/** 是否产生角色 */
	private boolean isCreate = true;

	public GameOverWinFrame() {
		/* 设置窗体大小 */
		this.setSize(650, 550);

		/* 设置窗体可见 */
		this.setVisible(true);

		/* 设置点击关闭,程序结束 */
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);

		/* 设置窗口不可改变 */
		this.setResizable(false);

		/* 得到当前屏幕大小的Dimension对象 */
		Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();

		/* 设置窗口位于屏幕的正中 */
		this.setLocation((dimension.width - 650) / 2,
				(dimension.height - 550) / 2);

//		PublicVar.isBoss = true;
		GameStartFrame.isRightScroll = false;

		tracker = new MediaTracker(this);
		TrackerWinImage.trackerImage(tracker, this);// 媒体追踪

		PublicVar.roleList.clear();// 清空集合中元素

		PublicVar.roleList.add(new Flame(30, 160));

		/* 创建画布 */
		memoryImage = this.createImage(650, 550);

		/* 得到画笔对象 */
		memoryGraphics = memoryImage.getGraphics();

		// 播放背景音乐
		Music.playSingleMusic(Music.PLAY_GAMEWIN);

		Thread thread = new Thread(this);
		thread.start();

	}

	public void run() {
		// TODO 自动生成方法存根
		while (PublicVar.isStart) {
			repaint();// 窗体重绘

			/*
			 * 产生烟花
			 */
			if (flameCount > 20) {
				double tempDouble = Math.random();
				int tempX = (int) (tempDouble * 580 + 30);
				PublicVar.roleList.add(new Flame(tempX, 160));
				flameCount = 0;
			}

			flameCount++;

			/**
			 * 产生烟花之外角色
			 */
			if (this.isCreate) {
				this.count++;

				/**
				 * 产生男松鼠
				 */
				if (count ==770) {//490
					PublicVar.roleList.add(new WinChip(-50, 500, 0));
				}

				/**
				 * 产生汽球
				 */
				if (count == 1950) {//2200
					PublicVar.roleList.add(new Dale());
					PublicVar.roleList.add(new StreamBall());
					
					this.isCreate = false;
				}

			}

			
			
			try {
				Thread.sleep(20);// 线程休眠
			} catch (InterruptedException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
	}

	public void update(Graphics g) {

		memoryGraphics.drawImage(gameOverWinImage, 0, 0, this);

		for (int i = 0; i < PublicVar.roleList.size(); i++) {
			BaseRole role = PublicVar.roleList.get(i);
			role.drawMyself(memoryGraphics, this);// 绘制角色
		}

		/** 将内存中的图像画在画布上 */
		g.drawImage(memoryImage, 0, 0, this);

	}

	public static void main(String[] args) {
		new GameOverWinFrame();
	}
}

⌨️ 快捷键说明

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