Double Dispatch example improvements.
This commit is contained in:
		| @@ -13,21 +13,21 @@ public class Meteoroid extends GameObject { | ||||
|  | ||||
| 	@Override | ||||
| 	public void collisionResolve(FlamingAsteroid asteroid) { | ||||
| 		System.out.println(String.format("%s hits %s", asteroid.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 		System.out.println(String.format("%s hits %s.", asteroid.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void collisionResolve(Meteoroid meteoroid) { | ||||
| 		System.out.println(String.format("%s hits %s", meteoroid.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 		System.out.println(String.format("%s hits %s.", meteoroid.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void collisionResolve(SpaceStationMir mir) { | ||||
| 		System.out.println(String.format("%s hits %s", mir.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 		System.out.println(String.format("%s hits %s.", mir.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void collisionResolve(SpaceStationIss iss) { | ||||
| 		System.out.println(String.format("%s hits %s", iss.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 		System.out.println(String.format("%s hits %s.", iss.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 	}	 | ||||
| } | ||||
|   | ||||
| @@ -13,26 +13,34 @@ public class SpaceStationMir extends GameObject { | ||||
|  | ||||
| 	@Override | ||||
| 	public void collisionResolve(FlamingAsteroid asteroid) { | ||||
| 		System.out.println(String.format("%s hits %s", asteroid.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 		System.out.println(String.format("%s hits %s. %s is damaged! %s is set on fire!",  | ||||
| 				asteroid.getClass().getSimpleName(), this.getClass().getSimpleName(),  | ||||
| 				this.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 		setDamaged(true); | ||||
| 		setOnFire(true); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void collisionResolve(Meteoroid meteoroid) { | ||||
| 		System.out.println(String.format("%s hits %s", meteoroid.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 		System.out.println(String.format("%s hits %s. %s is damaged!",  | ||||
| 				meteoroid.getClass().getSimpleName(), this.getClass().getSimpleName(),  | ||||
| 				this.getClass().getSimpleName())); | ||||
| 		setDamaged(true); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void collisionResolve(SpaceStationMir mir) { | ||||
| 		System.out.println(String.format("%s hits %s", mir.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 		System.out.println(String.format("%s hits %s. %s is damaged!",  | ||||
| 				mir.getClass().getSimpleName(), this.getClass().getSimpleName(),  | ||||
| 				this.getClass().getSimpleName())); | ||||
| 		setDamaged(true); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void collisionResolve(SpaceStationIss iss) { | ||||
| 		System.out.println(String.format("%s hits %s", iss.getClass().getSimpleName(), this.getClass().getSimpleName())); | ||||
| 		System.out.println(String.format("%s hits %s. %s is damaged!",  | ||||
| 				iss.getClass().getSimpleName(), this.getClass().getSimpleName(),  | ||||
| 				this.getClass().getSimpleName())); | ||||
| 		setDamaged(true); | ||||
| 	}	 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user