본문 바로가기
JAVA

[JAVA] Star Craft 만들기

by 개폰지밥 2019. 2. 22.
반응형

1. 스타크래프트

과거에 학교 과제로 스타크래프트 게임 과제가 존재했다. (그래픽 제외)

처음에는 어떻게 시작해야 할지 감도 안잡혔지만 하다보니 만들고있었다.

물론 100%로 완성된 소스코드도 아니고, 실행이 잘못되는 것도 있지만 뿌듯한 시간이었다.

시간이 되면 정확히 실행이 되지 않는 것을 수정해보도록 해야겠다.

 

1.1 스타크래프트 다이어그램

 

1.2 클래스 세부설계표

1.3 소스코드

1.3.1 Marin

package dmirae.starcraft.units;
import dmirae.starcraft.buildings.Building;
public class Marine extends Unit implements attackAble{
 final int MAXHP=100;
 private int attackPower;
 public Marine(String name) {
 super(name);
 currentHP=MAXHP;
 this.attackPower=10;
 // TODO Auto-generated constructor stub
 }
 public Marine(String name, int x, int y) {
 super(name, x, y);
 this.currentHP=MAXHP;
 this.attackPower=10;
 }
 public int getAttackPower() {
 return attackPower;
 }
 public void setAttackPower(int attackPower) {
 this.attackPower = attackPower;
 }
 public void attack(Unit U) {
 System.out.println("유닛 공격하는 중이자나~");
 if(currentHP>0) {
 currentHP=-1;
 }
 else {
 super.alive=false;
 super.die();
 }
 }
 public void attack(Building b) {
 System.out.println("빌딩 공격하는 중이자나~");
 b.setCurrentHP(getCurrentHP()-this.attackPower);
 }
 public void stimPack() {
 System.out.println("스팀팩을 이용하고 있어요 힘이나요 웡웡");
 if(this.currentHP>=10) {
 this.attackPower=+10;
 this.currentHP=-10;
 }
 }
 public String toString() {
 return "이름:"+this.getName()+"생존여부:"+this.isAlive()+"/n"+
 "현재체력:"+this.getCurrentHP()+"공격력:"+this.getAttackPower()+"/n"
 +"현재 좌표"+this.getX()+"."+this.getY()+"/n";
 }
 }

1.3.2 Medic

package dmirae.starcraft.units;
public class Medic extends Unit{
 public int healPower;
 final int MAXHP=40;
 public Medic(String name) {
 super(name);
this.alive=true;
this.currentHP=MAXHP;
this.healPower=100;
 // TODO Auto-generated constructor stub
 }
 public Medic(String name, int x, int y){
 super(name,x,y);
 this.alive=true;
 this.currentHP=MAXHP;
 this.healPower=100; 
 }
 public int getHealPower() {
 return healPower;
 }
 public void setHealPower(int healPower) {
 this.healPower = healPower;
 }
 public void heal(Marine mar) {
 System.out.println("마륀 치료를 시작합니다");
 mar.setCurrentHP(mar.getCurrentHP());
 this.healPower=-1;
 }
 public void heal(Medic med) {
 System.out.println("메뒥 치료를 시작합니다");
 med.setCurrentHP(getCurrentHP());
 this.healPower=-1;
 }
 public void charge() {
 System.out.println("치료 가능한 능력 충전");
 this.healPower=100;
 }
 public String toString() {
 return "이름:"+this.getName()+"생존여부:"+this.isAlive()+"/n"+
 "현재체력:"+this.getCurrentHP()+"공격력:"+this.getAttackPower()+"/n"
 +"현재 좌표"+this.getX()+"."+this.getY()+"치료 가능 능력:"+this.getHealPower()+"/n";
}
}

1.3.3 SVC

package dmirae.starcraft.units;

import dmirae.starcraft.buildings.Building;

public class SCV extends Unit implements attackAble{
 final int MAXHP=20;

 public SCV(String name) {
 super(name);
 this.alive=true;
 this.currentHP=MAXHP;
 this.setAttackPower(2);
 }
 SCV(String name, int x, int y){
 super(name,x,y);
 this.alive=true;
 this.currentHP=MAXHP;
 this.setAttackPower(2);

 }
 public void attack(Unit u) {
 System.out.println("유닛 공격하는 중이자나~");
 if(this.currentHP>0) {
 this.currentHP=-1;}
 else 
 this.die();

 }
 public void attack(Building b) {
 System.out.println("빌딩 공격하는 중이자나~");
 b.setCurrentHP(b.getCurrentHP() - this.getAttackPower());


 }
 public void repair(String name, Tank ta, DropShip drs) {
 if(name=="Tank") {
 System.out.println("땡끄 수선하는 중이자나");
 ta.setCurrentHP(100); 
 }
 else if(name=="DropShip") {
 System.out.println("뜨롭쉽 수선하는 중이자나");
 drs.setCurrentHP(100);
 }
 }
}

1.3.4 Tank

package dmirae.starcraft.units;

import dmirae.starcraft.buildings.Building;

public class Tank extends Unit implements attackAble{
private boolean siegeMode;
final int MAXHP =20;

public Tank(String name) {
super(name);
this.alive=true;
this.currentHP=this.MAXHP;
this.attackPower=10;
this.siegeMode=false;
 }

 public Tank(String name, int x, int y) {
 super(name, x, y);
 this.alive=true;
 this.currentHP=this.MAXHP;
 this.attackPower=10;
 this.siegeMode=false;
 }

 public boolean isSiegeMode() {
 return siegeMode;
 }

 public void setSiegeMode(boolean siegeMode) {
 this.siegeMode = siegeMode;
 }

 public void attack(Unit u) {
 System.out.println("유닛 공격하는 중이자나~");
 if(this.currentHP>0) {
 this.currentHP=-1;}
 else 
 this.die();
 }

 public void attack(Building b) {
 System.out.println("빌딩 공격하는 중이자나~");
 b.setCurrentHP(b.getCurrentHP() - this.getAttackPower());
 if(siegeMode=true) {
 b.setCurrentHP(b.getCurrentHP()-(this.getAttackPower())*2);
 }
 }

 public void chandMode() {
 System.out.println("siege모드 변경중!!");
 if(siegeMode=true) {
 siegeMode=false;
 }else
 siegeMode=true;
 }

 public String toString() {
 return "이름:"+this.getName()+"생존여부:"+this.isAlive()+"/n"+
 "현재체력:"+this.getCurrentHP()+"공격력:"+this.getAttackPower()+"/n"
 +"현재 좌표"+this.getX()+"."+this.getY()+"시즈모드:"+this.isSiegeMode()+"/n";
 }
}

1.3.5 Wraith

package dmirae.starcraft.units;

public class Wraith extends Unit{
private boolean cloakingMode;
final int MAXHP=250;
private int maxCnt;

public Wraith(String name) {
 super(name);
 alive=true;
 currentHP=MAXHP;
 maxCnt=4;
 }

 public Wraith(String name, int x, int y) {
 super(name,x,y);
 alive=true;
 currentHP=MAXHP;
 maxCnt=4;
 }

 public void changeMode(){
 if(cloakingMode=false) {
 System.out.println("클라킹 모드 변경합니다");
 cloakingMode=true;
 } else
 System.out.println("클라킹 모드 변경합니다");
 cloakingMode=false;
 }

 public void upgrade() {
 System.out.println("엄중하게 공격력 증가");
 attackPower=+100;
 }
}

1.3.6 Barrack

package dmirae.starcraft.buildings;

import dmirae.starcraft.units.Marine;
import dmirae.starcraft.units.Medic;
import dmirae.starcraft.units.SCV;
import dmirae.starcraft.units.Unit;

public class Barrack extends Building implements CreatAble{
 final int MAXHP=300;
 private boolean status;

 public Barrack(String name) {
 super(name);
 destroyed=true;
 currentHP=MAXHP;
 }

 public Barrack(String name, int x, int y) {
 super(name,x,y);
 destroyed=true;
 currentHP=MAXHP;
 }

 public void destroy() {
 System.out.println("파괴되다");
 if(currentHP>0) {
 destroyed=false;
 }
 }

 public void liftOff() {

 System.out.println("이륙하다");
 this.status=true;
 }

 public void land() {
 this.status=false;
 }

 @Override
 public Unit creat(int menu, String name) {
 Unit mms = null;
 if(menu==1) {
mms = new Marine(name);
 }else if(menu==2) {
 mms = new Medic(name);
 }else if(menu==3) {
 mms = new SCV(name);
 }else
 System.out.println("nono");
 return mms;
 }
 }

1.3.7 Building

package dmirae.starcraft.buildings;

public class Bunker extends Building{

 final int MAXHP=200;
 protected int maxCnt=4;
 private int currentCnt=0;

 public Bunker(String name) {
 super(name);
 destroyed=true;
 currentHP=MAXHP;
 }
 public Bunker(String name, int x, int y) {
 super(name,x,y);
 destroyed=true;
 currentHP=MAXHP;
 }
 public void destroy() {
 System.out.println("파괴되다");
 if(currentHP>0) {
 destroyed=false;
 }
 }
 public void enter(int cnt) {
 if(this.maxCnt>this.currentCnt) {
 System.out.println("들어가다");
 this.currentCnt=this.currentCnt+cnt;

 }else
 System.out.println("나레나레 안되우");

}
 public void comeout() {
 System.out.println("나오라우 빨리빨리");
 if(this.currentCnt<=0) {
 System.out.println("임무완수 다내렸다우");
 }
 }
 public void upgrade(){
 if(maxCnt<10) {
 System.out.println("업그레이드 될 준비가 되었습니다");
 maxCnt=+2;
 }
 }


}

1.3.8 CreateAble

package dmirae.starcraft.buildings;

import dmirae.starcraft.units.Unit;

public interface CreatAble {
 public Unit creat(int menu, String name);

}

 

1.3.9 Factory

package dmirae.starcraft.buildings;

import dmirae.starcraft.units.DropShip;
import dmirae.starcraft.units.Tank;
import dmirae.starcraft.units.Unit;

public class Factory extends Building implements CreatAble{
 private boolean status;
 final int MAXHP=500;

 public Factory(String name) {
 super(name);
 destroyed=true;
 currentHP=MAXHP;

 }

 public Factory(String name, int x, int y) {
 super(name, x, y);
 destroyed=true;
 currentHP=MAXHP;
 }
 public void destory() {
 if(currentHP<=0) {
 destroyed = false;
 }
 }
 public Unit creat(int menu, String name) {
 Unit tds= null;
 if(menu==1) {
 tds = new Tank(name);
 System.out.println("땡크 생성합니당");
 }else if(menu==2) {
 tds = new DropShip(name);
 System.out.println("드롭십 생성합니당");

 }
 return tds;
 } 
}

1.3.10 AttackTest

package dmirae.starcraft.test;

import dmirae.starcraft.buildings.Barrack;
import dmirae.starcraft.buildings.Factory;
import dmirae.starcraft.units.Marine;
import dmirae.starcraft.units.Tank;

public class AttackTest {

public static void main(String[] args) {
Barrack b = new Barrack("b");
Factory f = new Factory("f");
Marine m = new Marine("m");
Tank t = new Tank("t");

 System.out.println(b.toString());
 System.out.println(f.toString());
 System.out.println(m.toString());
 System.out.println(t.toString());

m.attack(t);
 System.out.println(m.toString());
 System.out.println(t.toString());
 }
}

1.3.11 BarrackCreate Test

package dmirae.starcraft.test;
import dmirae.starcraft.buildings.Barrack;
import dmirae.starcraft.units.Marine;
import dmirae.starcraft.units.Medic;
import dmirae.starcraft.units.SCV;

public class BarrackCreateTest {

public static void main(String[] args) {
 Barrack b = new Barrack("b");
 Marine marine = (Marine) b.creat(1, "marine1");
 Medic medic = (Medic) b.creat(2, "medic1");
 SCV scv = (SCV) b.creat(3, "scv1");
System.out.println(marine.toString());
 System.out.println(medic.toString());
 System.out.println(scv.toString());
System.out.println(b.toString());
 b.liftOff();
 System.out.println(b.toString()); 
 b.land();
 System.out.println(b.toString());
 }
 
}

1.3.12 FactoryCreate Test

package dmirae.starcraft.test;

import dmirae.starcraft.buildings.Factory;
import dmirae.starcraft.units.DropShip;
import dmirae.starcraft.units.Tank;

public class FactoryCreateTest {

 public static void main(String[] args) {
 Factory f = new Factory("f");

 Tank tank3 =(Tank) f.creat(1,"tank3");

 DropShip dropship1 = (DropShip) f.creat(2, "dropship1");

 System.out.println(f.toString());
 System.out.println(tank3.toString());
 System.out.println(dropship1.toString());

 }

}

1.3.13 Medic Test

package dmirae.starcraft.test;

import dmirae.starcraft.units.Marine;
import dmirae.starcraft.units.Medic;
import dmirae.starcraft.units.Tank;

public class MedicTest {

 public static void main(String[] args) {
 Marine marine = new Marine("marine");
 Medic medic = new Medic("medic");
 Tank tank = new Tank("tank");

 System.out.println(marine.toString());
 System.out.println(medic.toString());
 System.out.println(tank.toString());

 tank.attack(marine);

 medic.heal(marine);

 System.out.println(marine.toString());
 System.out.println(medic.toString());
 System.out.println(tank.toString());


 }

}

1.3.14 Tank Test

package dmirae.starcraft.test;

import dmirae.starcraft.buildings.Factory;
import dmirae.starcraft.units.Tank;

public class TankTest {

 public static void main(String[] args) {
 Factory factory = new Factory("factory");

 Tank tank1 = (Tank) factory.creat(1, "tank1");
 Tank tank2 = (Tank) factory.creat(1, "tank2");

 System.out.println(factory.toString());
 System.out.println(tank1.toString());
 System.out.println(tank2.toString());

 tank1.attack(factory);
 System.out.println();
 tank2.isSiegeMode();
 tank2.attack(factory);

 System.out.println(factory.toString());
 System.out.println(tank1.toString());
 System.out.println(tank2.toString());


 }

}
반응형

'JAVA' 카테고리의 다른 글

190329  (0) 2019.03.28
[JAVA] Scanner, 형변환, 연산자, if문  (0) 2019.03.28
자바 생성자  (0) 2019.01.29
자바 클래스 객체 인스턴스 메서드의 차이  (0) 2019.01.29
자바 기초 관련 (JVM, JDK, API, Main 메소드)  (0) 2019.01.29

댓글