package shooting.example.examplestage;

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

/// AĨTv
public class ExampleAI extends Player {
	public static final int DEFAULT_WIDTH = 30;	///< ftHg̕
	public static final int DEFAULT_HEIGHT = 30;	///< ftHg̍
	public static final int MAX_DAMAGE = 100;	///< ő_[W
	/// ̎擾
	/// @return 
	public int getWidth() { return getImage() != null ? getImage().getWidth(null) : DEFAULT_WIDTH; }
	/// ̎擾
	/// @return 
	public int getHeight() { return getImage() != null ? getImage().getHeight(null) : DEFAULT_HEIGHT; }
	/// ő_[W̎擾
	/// @return ő_[W
	public int getMaxDamage() { return MAX_DAMAGE; }
	private Weapon subWeapon;	///< Player.weaponƂ͕ʂWeapon

	/// RXgN^
	/// @param shooting ShootingNX̃IuWFNg
	/// @param team `[ԍ
	/// @param x zu鍶ォXW
	/// @param y zu鍶ォYW
	/// @param sx ˂̕EXW
	/// @param sy ˂̕EYW
	public ExampleAI(Shooting shooting, int team, int x, int y, int sx, int sy) {
		this(shooting, null, team, x, y, sx, sy);
	}

	/// RXgN^
	/// @param shooting ShootingNX̃IuWFNg
	/// @param image @̂̉摜
	/// @param team `[ԍ
	/// @param x zu鍶ォXW
	/// @param y zu鍶ォYW
	/// @param sx ˂̕EXW
	/// @param sy ˂̕EYW
	public ExampleAI(Shooting shooting, Image image, int team, int x, int y, int sx, int sy) {
		super(shooting, team, x, y, sx, sy);
		setImage(image);
		setWeapon(new ExampleWeapon(this));
		setMovingX(1);
		subWeapon = new DefaultWeapon(this);
	}

	/// C[vĂ΂鏈
	///
	/// ł͈ړƃ[U̔ˏsĂ
	public void runMainLoopJob() {
		// subWeapon͌Ă鎞͖񌂂
		subWeapon.shoot();
		if (getWeapon().isCharged()) {
			// WeapongpłꍇAGAI_ʒuɂ邩𔻒fĂ猂
			for (Player player : getShooting().getPlayers()) {
				if (player.getTeam() != this.getTeam()) {
					int shootxpos = this.getX() + this.getWidth()/2;
					if (player.getMovingX() > 0) {
						// EɈړĂꍇ̕␳
						shootxpos -= 50;
					} else if (player.getMovingX() < 0) {
						// ɈړĂꍇ̕␳
						shootxpos += 50;
					}
					if (shootxpos >= player.getX() && shootxpos <= player.getX()+player.getWidth()) {
						getWeapon().shoot();
					}
				}
			}
		}

		// 1/400̊mŕ]
		if ((int)(Math.random()*400) == 0) {
			setMovingX(-getMovingX());
		}

		for (Lazer lazer : getShooting().getLazers()) {
			if (lazer.getPlayer().getTeam() != this.getTeam()) {
				// 100pxȓɓGLazer߂ÂĂĂ悤Ƃ
				if (lazer.getY()-(getY()+getHeight()) <= 100) {
					if (lazer.getX() >= this.getX()-20 && lazer.getX()+lazer.getWidth() <= this.getX()+this.getWidth()+20) {
						setMovingX(lazer.getX() < this.getCenterX() ? 1 : -1);
					}
				}
			}
		}

		// ȏ㍡̌֐i߂ȂȂ]
		if (!canMoveTo(getX()+getMovingX(), getY(), getWidth(), getHeight())) {
			setMovingX(-getMovingX());
		}
		setX(getX()+getMovingX());
	}
}


@@ -2242,16 +2242,46 @@
 %0A%09%09%7D%0D%0A%0D%0A
+%09%09boolean nearlazer = false;%0D%0A
 %09%09for (L
@@ -2631,33 +2631,307 @@
  1 : -1);%0D%0A%09%09%09%09%09
-%7D
+%09nearlazer = true;%0D%0A%09%09%09%09%09%7D%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09if (!nearlazer) %7B%0D%0A%09%09%09// Lazer%C9%82%E8%82%BB%C5%82%CD%82%C8%82%CC%82%C5%93K%C8%93G%C9%8B%DF%82%C3%82%C6%82%0D%0A%09%09%09for (Player player : getShooting().getPlayers()) %7B%0D%0A%09%09%09%09if (player.getTeam() != this.getTeam()) %7B%0D%0A%09%09%09%09%09setMovingX(player.getCenterX() %3C this.getCenterX() ? -1 : 1);%0D%0A%09%09%09%09%09break;
 %0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09

Improve ExampleAI