pl/mbogusz3/invaders/model/Enemy.java
/**
	 * Move the enemy army.
	 * @param time time for which the army has moved (fraction of second).
	 * @throws InvadersGameEndException if enemy has reached obstacles
	 */
Move the enemy army.
@param time time for which the army has moved (fraction of second).
@throws InvadersGameEndException if enemy has reached obstacles
Move the enemy army . @param time time for which the army has moved ( fraction of second ) . @throws InvadersGameEndException if enemy has reached obstacles
public void move(double time) throws InvadersGameEndException {
		double halfWidth = this.unitWidth * ((double)(this.lastColumn - this.firstColumn + 1) - 0.5);
		if(this.direction == 1) {
			if(this.positionLeft < (1.0 - halfWidth)) {
				this.positionLeft += this.speed * time;
				if(this.positionLeft > (1.0 - halfWidth)) {
					this.positionLeft = 1.0 - halfWidth;
				}
			} else {
				this.positionTop += Enemy.unitHeight / 2;
				this.direction = -1;
			}
		} else if (direction == -1) {
			if(this.positionLeft > halfWidth) {
				this.positionLeft -= this.speed * time;
				if(this.positionLeft < halfWidth) {
					this.positionLeft = halfWidth;
				}
			} else {
				this.positionTop += Enemy.unitHeight / 2;
				this.direction = 1;
			}
		} else {
			System.out.println("Something strange happened... enemy direction was incorrect");
			this.direction = 1;
		}
		double height = (2 * this.firstRow + 1) * Enemy.unitHeight;
		if(this.positionTop + height >= 0.8) {
			System.out.println("GAME END");
			throw new InvadersGameEndException();
		}
	}
public void move ( double time ) throws InvadersGameEndException { double halfWidth = this . unitWidth * ( ( double ) ( this . lastColumn - this . firstColumn + 1 ) - 0.5 ) ; if ( this . direction == 1 ) { if ( this . positionLeft < ( 1.0 - halfWidth ) ) { this . positionLeft += this . speed * time ; if ( this . positionLeft > ( 1.0 - halfWidth ) ) { this . positionLeft = 1.0 - halfWidth ; } } else { this . positionTop += Enemy . unitHeight / 2 ; this . direction = - 1 ; } } else if ( direction == - 1 ) { if ( this . positionLeft > halfWidth ) { this . positionLeft -= this . speed * time ; if ( this . positionLeft < halfWidth ) { this . positionLeft = halfWidth ; } } else { this . positionTop += Enemy . unitHeight / 2 ; this . direction = 1 ; } } else { System . out . println ( "Something strange happened... enemy direction was incorrect" ) ; this . direction = 1 ; } double height = ( 2 * this . firstRow + 1 ) * Enemy . unitHeight ; if ( this . positionTop + height >= 0.8 ) { System . out . println ( "GAME END" ) ; throw new InvadersGameEndException ( ) ; } }
Move the enemy army.
Move the enemy army .
// Determine enemy "army" width // Compare half the width of army with maximum position // If not yet at the edge, simply move forward // Else, reverse movement direction and move half row down // Same for opposite direction // Detect end of game