~cpp public class person { private String name; private boolean state; // true study public person( String Aname ){ name = Aname; state = true; } public void sayName(){ System.out.println("name"); } public void showState(){ if( state ){ System.out.println("study"); }else System.out.println("rest"); } public void toRest(){ state = false; this.showState(); } public void toStudy(){ state = true; this.showState(); } public static void main( String args [] ){ person LSH = new person("lee seung han"); LSH.toStudy(); } }
~cpp public class Main { //메인 클래스를 따로 만드는 것도 코드를 읽기에는 상당히 편할것 같습니다. public static void main(String[] args) { Zelot partyZelot = new Zelot(); Dragon partyDragon = new Dragon(); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); partyDragon.attaced( partyZelot.attac() ); } }
~cpp public class Unit { //멤버 변수들 protected int force; //생산된 진영 protected int hp; protected int attacRating; protected int state; //1공격, 2홀드, 3무브, 4스탑 protected boolean possibleAirAttac; //공중 공격 가능여부 //생성자 public Unit(){ force = 1; hp = 1; attacRating = 0; state = 4; possibleAirAttac = false; } public Unit(int aForce, int aHp, int aAttacRating, int aState, boolean aPossibleAirAttac ){ force = aForce; hp = aHp; attacRating = aAttacRating; state = aState; possibleAirAttac = aPossibleAirAttac; } //멤버 함수 //공격을 받는다. public boolean attaced( int AattacRating ){ if( hp > 0 ){ hp -= AattacRating; System.out.println(hp); if( hp > 0){ return true; }else{ System.out.println("die."); return false; } }else { System.out.println("dead."); return false; } } protected int attac( ){ state = 1; //공격 return attacRating; } protected void shiled( int Ashiled ){ hp+= Ashiled; } }
~cpp public class Dragon extends Unit{ //생성자 입니다. public Dragon(){ super(1, 100, 10, 4, false); setUnit( 1 ); } public Dragon(int aForce){ super(aForce, 100, 10, 4, true); } public void setUnit( int aForce ){ shiled ( 150 ); System.out.println("I am returned."); } }
~cpp public class Zelot extends Unit{ //생성자 입니다. public Zelot(){ super(1, 100, 10, 4, false); shiled( 100 ); System.out.println("My Life for Aiur..."); } }