Java/chapter2

ch13 GateWay(Unit연계)

낭구리 2021. 8. 30. 18:49
package ch13;

public class DarkTempler extends Unit{
	public DarkTempler(String name) {
		this.name = name;
		this.power = 10;
		this.hp = 100;
	}
}

 

 

package ch13;

public class Dragon extends Unit {
	public Dragon(String name) {
		this.name = name;
		this.power = 10;
		this.hp = 100;
	}
}

 

 

package ch13;

public class GateWay {

	public static int zealotCount;
	public static int dragonCount;
	public static int darkTemplerCount;
	private int gateWayId;
	private String name;
	
	public GateWay(int id) {
		this.gateWayId = id;
		name = "게이트웨이";
	}
	//메서드 리턴 타입으로 객체를 생성
	//질럿을 생산하기
	
	public Unit createUnit(int target) {
		//매개변수 1. 질럿
		zealotCount++;
		System.out.println("질럿을 생산합니다.");
		if(target ==1) {
			return new Zealot("질럿" + zealotCount);			
		}else if (target ==2){
			return new Dragon("드라곤" + dragonCount);			
		}else {
			return new DarkTempler("다크템플러" + darkTemplerCount);			
		}
		
	}

	
}

 

 

package ch13;

public class MainTest2 {

	public static void main(String[] args) {

		GateWay gateWay = new GateWay(1);
		
		Unit Unit1 = gateWay.createUnit(1);
		Unit Unit2 = gateWay.createUnit(2);
		Unit Unit3 = gateWay.createUnit(3);
		
//		zealot1.attack(zealot3);
		System.out.println(GateWay.zealotCount);
		
	}

}

'Java > chapter2' 카테고리의 다른 글

ch13 Unit  (0) 2021.08.30
ch12 ArrayListMainTest  (0) 2021.08.27
ch12 Book(Array)  (0) 2021.08.27
ch11 MainTest2  (0) 2021.08.26
ch11 ArrayMainTest  (0) 2021.08.26