package shooting.example;

import shooting.core.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class ShootingApplet extends JApplet {
	JButton resumePauseButton;
	JButton leftButton;
	JButton rightButton;
	JButton shootButton;
	StatusPanel statusPanel;
	Shooting shooting;
	ControllablePlayer player;
	Player[] enemies;

	public void init() {
		setLayout(null);

		shooting = new Shooting();
		shooting.setBounds(5, 5, getWidth()-(5*2), getHeight()-50-5);
		add(shooting);

		player = new ControllablePlayer(shooting, 0, shooting.getWidth()/2, shooting.getHeight()-60, 0, -1);
		player.getKeyConfig().setMoveLeftKey(37, 65535);	// 
		player.getKeyConfig().setMoveRightKey(39, 65535);	// 
		player.getKeyConfig().setShootKey(32, 32);			// Xy[X

		int ctrlY = getHeight()-50;

		resumePauseButton = new JButton("Jn");
		resumePauseButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (shooting.isRunning()) {
					shooting.setPaused();
				} else {
					shooting.setRunning();
				}
			}
		});
		shooting.addShootingListener(new ShootingAdapter() {
			public void onGameResumed() {
				resumePauseButton.setText("ꎞ~");
			}
			public void onGamePaused() {
				resumePauseButton.setText("ĊJ");
			}
		});
		resumePauseButton.setBounds(5, ctrlY+5, 100, 40);
		add(resumePauseButton);

		leftButton = new JButton("");
		leftButton.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				player.setMovingX(-1);
			}

			public void mouseReleased(MouseEvent e) {
				player.setMovingX(0);
			}
		});
		leftButton.setBounds(110, ctrlY+5, 50, 40);
		add(leftButton);

		rightButton = new JButton("");
		rightButton.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				player.setMovingX(1);
			}

			public void mouseReleased(MouseEvent e) {
				player.setMovingX(0);
			}
		});
		rightButton.setBounds(165, ctrlY+5, 50, 40);
		add(rightButton);

		shootButton = new JButton("");
		shootButton.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (shooting.isRunning()) {
					player.getWeapon().shoot();
				}
			}
		});
		shootButton.setBounds(220, ctrlY+5, 50, 40);
		add(shootButton);

		statusPanel = new StatusPanel();
		statusPanel.setBounds(275, ctrlY+5, getWidth()-275-5, 40);
		add(statusPanel);

		shooting.addPlayer(player);
		player.addPlayerListener(new PlayerAdapter() {
			public void scoreUpdated() {
				statusPanel.repaint();
			}
			public void damageUpdated() {
				statusPanel.repaint();
			}
			public void notHitCountUpdated() {
				statusPanel.repaint();
			}
		});

		enemies = new Player[4];
		enemies[0] = new AIPlayer(shooting, 1, shooting.getWidth()/2, 60, 0, 1);
		enemies[1] = new AIPlayer(shooting, 1, 30, 90, 0, 1);
		enemies[2] = new AIPlayer(shooting, 1, shooting.getWidth()/2+40, 120, 0, 1);
		enemies[3] = new AIPlayer(shooting, 1, shooting.getWidth()-30, 150, 0, 1);
		for (Player enemy : enemies) {
			enemy.addPlayerListener(new PlayerAdapter() {
				public void playerDestroyed() {
					System.out.println("destroyed");
				}
			});
			shooting.addPlayer(enemy);
		}
	}

	class StatusPanel extends JPanel {
		public void paintComponent(Graphics g) {
			super.paintComponent(g);
			g.drawString("" + player.getHitPercent() + "%(" + player.getHitCount() + "/" + (player.getHitCount()+player.getNotHitCount()) + ") damage:" + player.getDamage() + " score:" + player.getScore(), 0, 10);
		}
	}
}


@@ -3104,219 +3104,8 @@
 );%0D%0A
-%09%09for (Player enemy : enemies) %7B%0D%0A%09%09%09enemy.addPlayerListener(new PlayerAdapter() %7B%0D%0A%09%09%09%09public void playerDestroyed() %7B%0D%0A%09%09%09%09%09System.out.println(%22destroyed%22);%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D);%0D%0A%09%09%09shooting.addPlayer(enemy);%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A

Remove debug text