package Game;

import java.applet.AudioClip;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JApplet;

class Cannonball {
	static int y = 560, score = 0;
	int temp = 240;
	ClassLoader classLoader = this.getClass().getClassLoader();

	public void paint(Graphics g, int x2) {
		int t = 0;
		if (y == 560) {
			temp = x2;
		}
		g.setColor(Color.red);
		g.fillOval(temp + 20, y, 10, 10);
		if (y < 560)
			y--;
		g.setColor(Color.LIGHT_GRAY);
		g.fillOval(temp + 20, y + 10, 10, 10);
		if (((temp + 20) % 40 == 0 && y == 70 && HoneyBee.a[0][(temp + 20) / 40 - 1] == 1)
				|| ((temp + 20) % 40 == 0 && y == 110 && HoneyBee.a[1][(temp + 20) / 40 - 1] == 1)
				|| ((temp + 20) % 40 == 0 && y == 150 && HoneyBee.a[2][(temp + 20) / 40 - 1] == 1)) {
			AudioClip au = JApplet.newAudioClip(classLoader
					.getResource("112.wav"));
			au.play();
			g.setColor(Color.LIGHT_GRAY);
			g.fillRect(temp + 20, y, 20, 30);
			if (y == 70) {
				t = 0;
			} else if (y == 110) {
				t = 1;
			} else if (y == 150) {
				t = 2;
			}
			HoneyBee.a[t][(temp + 20) / 40 - 1] = 0;
			score += 100;
			y = 560;
		}
		if (y == 0) {
			y = 560;
		}
	}
}

public class HoneyBee extends Frame {
	static int x1 = 200;
	static int[][] a = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, };
	ClassLoader classLoader = this.getClass().getClassLoader();

	public HoneyBee() {
		AudioClip au = JApplet.newAudioClip(classLoader
				.getResource("start.wav"));
		au.play();
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				dispose();
				System.exit(0);
			}
		});
		addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				int keycode = e.getKeyCode();
				if (keycode == KeyEvent.VK_LEFT) {
					x1 = x1 - 10;
				} else if (keycode == KeyEvent.VK_RIGHT) {
					x1 = x1 + 10;
				} else if (keycode == KeyEvent.VK_SPACE) {
					if (Cannonball.y == 560) {
						AudioClip au = JApplet.newAudioClip(classLoader
								.getResource("BONG.wav"));
						au.play();
						Cannonball.y = 559;
					} else {
					}
				}
				repaint();
			}
		});

	}

	public void paint(Graphics g) {
		int num;
		g.setColor(Color.BLUE);
		g.drawString("分数:" + Cannonball.score, 20, 50);
		g.fillOval(x1, 560, 50, 30);
		g.setColor(Color.BLACK);
		num = 0;
		for (int i = 0; i < 11; i++) {
			if (a[0][i] == 1)
				g.fillOval(num = num + 40, 70, 10, 10);
			else
				num = num + 40;
		}
		num = 0;
		for (int i = 0; i < 11; i++) {
			if (a[1][i] == 1)
				g.fillOval(num = num + 40, 110, 10, 10);
			else
				num = num + 40;
		}
		num = 0;
		for (int i = 0; i < 11; i++) {
			if (a[2][i] == 1)
				g.fillOval(num = num + 40, 150, 10, 10);
			else
				num = num + 40;
		}
	}

	public static void main(String[] args) {
		HoneyBee th = new HoneyBee();
		th.setBackground(Color.LIGHT_GRAY);
		th.setSize(500, 600);
		th.setTitle("小蜜蜂游戏");
		th.setVisible(true);
		Graphics g = th.getGraphics();
		Cannonball cb = new Cannonball();

		while (true) {
			try {
				Thread.sleep(4);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			cb.paint(g, x1);
		}
	}
}
最近下载更多
ldx1234  LV4 2021年5月24日
huanchu  LV1 2020年11月24日
woxingma  LV1 2020年11月23日
liangge2115  LV27 2020年11月22日
_reed_  LV3 2020年6月5日
llmllm  LV1 2019年12月27日
xsbxh520  LV2 2019年12月23日
勤奋的蜜蜂  LV2 2019年12月22日
qazxswedcv  LV1 2019年12月17日
233111  LV1 2019年12月15日
最近浏览更多
jkjfdgbkl  LV2 2023年11月1日
wangjialiang1  LV17 2023年8月23日
hougui  LV1 2023年6月20日
wjl0529  LV3 2021年12月21日
Demo1111  LV30 2021年12月9日
木子折口 2021年9月19日
暂无贡献等级
prudy520  LV6 2021年6月28日
pipichao  LV6 2021年6月20日
zq1234仲  LV1 2021年5月24日
ldx1234  LV4 2021年5月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友