유니티3D 프로그래밍
C# 1주차 4일 연습 과제 (21.03.11) 본문
App 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class App
{
//생성자
public App()
{
Console.WriteLine("App 생성자 호출됨");
Console.WriteLine();
Hydra hydra;
hydra = new Hydra();
Console.WriteLine("히드라의 체력 : {0}", hydra.GetHp());
Console.WriteLine();
Firebat firebat;
firebat = new Firebat();
Console.WriteLine("파이어뱃의 현재 체력 : {0}", firebat.GetFierbatHp());
firebat.SetFierbatHp(50);
Console.WriteLine("파이어뱃의 체력을 50으로 설정 : {0}", firebat.GetFierbatHp());
Console.WriteLine();
Ghost ghost;
ghost = new Ghost();
Console.WriteLine("클로킹을 사용합니다.");
ghost.UseSkill("클로킹");
Console.WriteLine("마나를 회복시킵니다.");
ghost.ManaUp(50);
Console.WriteLine("클로킹을 사용합니다.");
ghost.UseSkill("클로킹");
Console.WriteLine();
Gateway gateway;
gateway = new Gateway();
Console.WriteLine("다크템플러를 생성합니다. {0}", gateway.CreateDarkTemplar());
Console.WriteLine();
Factory factroy;
factroy = new Factory();
Console.WriteLine("골리앗을 생성합니다.");
Goliath goliath1 = factroy.CreateGoliath();
factroy.mineral = 100;
factroy.gas = 50;
Console.WriteLine("골리앗을 생성합니다.");
goliath1 = factroy.CreateGoliath();
Console.WriteLine();
Goliath goliath = new Goliath();
Console.WriteLine("골리앗의 업그레이드 전 사거리 : {0}", goliath.attackRange);
goliath.UpgradeAttackRange();
Console.WriteLine("골리앗의 업그레이드 후 사거리 : {0}", goliath.attackRange);
Console.WriteLine();
Valture valture = new Valture();
for(int i = 0; i < 4; i++)
{
valture.InstallMine();
}
Console.WriteLine();
DarkTemplar darkTemplar1 = new DarkTemplar();
DarkTemplar darkTemplar2 = new DarkTemplar();
darkTemplar1.name = "손오공";
darkTemplar2.name = "베지터";
Console.WriteLine("{0}과 {1}의 합체", darkTemplar1.name, darkTemplar2.name);
DarkArchon darkArchon = darkTemplar1.Combination(darkTemplar1, darkTemplar2);
darkArchon.name = "오지터";
Console.WriteLine("합체 결과 : {0}", darkArchon.name);
Console.WriteLine();
SCV scv = new SCV();
Console.Write("건물을 건설합니다. : ");
string input = Console.ReadLine();
scv.CreateBuild(input);
Console.WriteLine();
DarkArchon darkArchon1 = new DarkArchon();
Console.WriteLine("마인드컨트롤을 사용합니다.");
darkArchon.UseSkill("마인드컨트롤");
darkArchon.ManaRecovery();
Console.WriteLine("마인드컨트롤을 사용합니다.");
darkArchon.UseSkill("마인드컨트롤");
Console.WriteLine();
}
}
}
Hydra 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class Hydra
{
private float hp = 70;
//생성자
public Hydra()
{
Console.WriteLine("Hydra 생성자 호출");
}
public float GetHp()
{
return this.hp;
}
}
}
Firebat 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class Firebat
{
private float hp = 70;
//생성자
public Firebat()
{
Console.WriteLine("Firebat 생성자 호출");
}
public void SetFierbatHp(float hp)
{
this.hp = hp;
}
public float GetFierbatHp()
{
return this.hp;
}
}
}
Ghost 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class Ghost
{
private int mana = 100;
private int maxMana = 200;
private int skillMana = 150;
//생성자
public Ghost()
{
Console.WriteLine("Ghost 생성자 호출");
}
public void UseSkill(string skillName)
{
if(skillName == "클로킹")
{
if(this.mana < skillMana)
{
Console.WriteLine("마나가 부족합니다. 스킬을 사용할 수 없습니다.");
}
else
{
Console.WriteLine("스킬을 사용합니다.");
}
}
}
public void ManaUp(int num)
{
this.mana += num;
}
}
}
Gateway 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class Gateway
{
//생성자
public Gateway()
{
Console.WriteLine("Gateway 생성자 호출");
}
public DarkTemplar CreateDarkTemplar()
{
return new DarkTemplar();
}
}
}
Factory 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class Factory
{
public int mineral;
public int gas;
//생성자
public Factory()
{
Console.WriteLine("Factory 생성자 호출");
}
public Goliath CreateGoliath()
{
if(mineral < 100 || gas < 50)
{
Console.WriteLine("자원이 부족합니다.");
return null;
}
else
{
Console.WriteLine("골리앗이 생성됩니다.");
return new Goliath();
}
}
}
}
Goliath 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class Goliath
{
public int attackRange = 5;
//생성자
public Goliath()
{
Console.WriteLine("Goliath 생성자 호출");
}
public void UpgradeAttackRange()
{
this.attackRange = 8;
}
}
}
Valture 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class Valture
{
private int mine = 3;
//생성자
public Valture()
{
Console.WriteLine("Valture 생성자 호출");
}
public void InstallMine()
{
if(mine > 0)
{
Console.WriteLine("마인을 설치합니다.");
this.mine -= 1;
}
else
{
Console.WriteLine("마인이 없습니다.");
}
}
}
}
DarkTemplar 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class DarkTemplar
{
public string name;
//생성자
public DarkTemplar()
{
Console.WriteLine("DarkTemplar 생성자 호출");
}
public DarkArchon Combination(DarkTemplar dark1, DarkTemplar dark2)
{
return new DarkArchon();
}
}
}
SCV 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class SCV
{
//생성자
public SCV()
{
Console.WriteLine("SCV 생성자 호출");
}
public void CreateBuild(string buildingName)
{
if(buildingName == "팩토리")
{
Console.WriteLine("팩토리를 지었습니다.");
}
else if(buildingName == "배럭")
{
Console.WriteLine("배럭을 지었습니다.");
}
}
}
}
DarkArchon 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
public class DarkArchon
{
public string name;
private int mana = 100;
private int maxMana = 200;
private int skillMana = 150;
//생성자
public DarkArchon()
{
Console.WriteLine("DarkArchon 생성자 호출");
}
public void UseSkill(string skillName)
{
if (skillName == "마인드컨트롤")
{
if (this.mana < skillMana)
{
Console.WriteLine("마나가 부족합니다. 스킬을 사용할 수 없습니다.");
}
else
{
Console.WriteLine("스킬을 사용합니다.");
}
}
}
public void ManaRecovery()
{
for(int i = 0; ; i++)
{
mana += 10;
Console.WriteLine("마나를 10씩 회복합니다. 현재 마나 : {0}", this.mana);
if (this.mana >= maxMana)
{
this.mana = maxMana;
Console.WriteLine("마나가 가득 찼습니다.");
break;
}
}
}
}
}
'C# > 수업과제' 카테고리의 다른 글
C# 2주차 1일 수업 과제 (21.03.15) (0) | 2021.03.15 |
---|---|
C# 1주차 5일 연습 과제 (21.03.12) (0) | 2021.03.12 |
C# 1주차 3일 연습 과제 (21.03.10) (0) | 2021.03.10 |
C# 1주차 2일 연습 과제 (21.03.09) (0) | 2021.03.09 |
C# 1주차 1일 연습 과제 (21.03.08) (0) | 2021.03.08 |