2019.03.26 과제 (와우 케릭터 만들기 C#콘솔)
Unity3D/C# 2019. 3. 27. 00:44반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp6 { class Program { static void Main(string[] args) { new App(); Console.ReadKey(); } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp6 { class Mask { public static GameEnums.eTribe allianceMask = GameEnums.eTribe.Human | GameEnums.eTribe.Dwarf | GameEnums.eTribe.NightElf | GameEnums.eTribe.Gnome | GameEnums.eTribe.Draenei | GameEnums.eTribe.Worgen | GameEnums.eTribe.Pandaren; public static GameEnums.eTribe hordeMask = GameEnums.eTribe.Orc | GameEnums.eTribe.Undead | GameEnums.eTribe.Tauren | GameEnums.eTribe.Troll | GameEnums.eTribe.BloodElf | GameEnums.eTribe.Goblin | GameEnums.eTribe.Pandaren; //클래스 (얼라) public static GameEnums.eClass humanClassMask = GameEnums.eClass.DeathKnight | GameEnums.eClass.Hunter | GameEnums.eClass.Rogue | GameEnums.eClass.Monk | GameEnums.eClass.Mage | GameEnums.eClass.Warlock | GameEnums.eClass.Priest | GameEnums.eClass.Paladin | GameEnums.eClass.Warrior; public static GameEnums.eClass dwarfClassMask = GameEnums.eClass.DeathKnight | GameEnums.eClass.Rogue | GameEnums.eClass.Hunter | GameEnums.eClass.Monk | GameEnums.eClass.Mage | GameEnums.eClass.Warlock | GameEnums.eClass.Priest | GameEnums.eClass.Paladin | GameEnums.eClass.Shaman | GameEnums.eClass.Warrior; public static GameEnums.eClass nightElfClassMask = GameEnums.eClass.DemonHunter | GameEnums.eClass.DeathKnight | GameEnums.eClass.Druid | GameEnums.eClass.Rogue | GameEnums.eClass.Hunter | GameEnums.eClass.Monk | GameEnums.eClass.Mage | GameEnums.eClass.Priest | GameEnums.eClass.Warrior; //Gnome public static GameEnums.eClass gnomeClassMask = GameEnums.eClass.DeathKnight | GameEnums.eClass.Hunter | GameEnums.eClass.Monk | GameEnums.eClass.Priest | GameEnums.eClass.Warlock | GameEnums.eClass.Warrior | GameEnums.eClass.Mage | GameEnums.eClass.Rogue; //Draenei public static GameEnums.eClass draeneiClassMask = GameEnums.eClass.DeathKnight | GameEnums.eClass.Hunter | GameEnums.eClass.Monk | GameEnums.eClass.Mage | GameEnums.eClass.Priest | GameEnums.eClass.Paladin | GameEnums.eClass.Shaman | GameEnums.eClass.Warrior; //Worgen public static GameEnums.eClass worgenClassMask = GameEnums.eClass.DeathKnight | GameEnums.eClass.Druid | GameEnums.eClass.Rogue | GameEnums.eClass.Hunter | GameEnums.eClass.Mage | GameEnums.eClass.Priest | GameEnums.eClass.Warlock | GameEnums.eClass.Warrior; //Pandaren public static GameEnums.eClass pandarenClassMask = GameEnums.eClass.Monk | GameEnums.eClass.Rogue | GameEnums.eClass.Hunter | GameEnums.eClass.Mage | GameEnums.eClass.Priest | GameEnums.eClass.Shaman | GameEnums.eClass.Warrior; //클래스 (오크) public static GameEnums.eClass orcClassMask = GameEnums.eClass.DeathKnight | GameEnums.eClass.Monk | GameEnums.eClass.Hunter | GameEnums.eClass.Mage | GameEnums.eClass.Rogue | GameEnums.eClass.Warlock | GameEnums.eClass.Shaman | GameEnums.eClass.Warrior; public static GameEnums.eClass undeadClassMask = GameEnums.eClass.DeathKnight | GameEnums.eClass.Hunter | GameEnums.eClass.Mage | GameEnums.eClass.Monk | GameEnums.eClass.Priest | GameEnums.eClass.Rogue | GameEnums.eClass.Warlock| GameEnums.eClass.Warrior; public static GameEnums.eClass taurenClassMask = GameEnums.eClass.DeathKnight | GameEnums.eClass.Hunter | GameEnums.eClass.Druid | GameEnums.eClass.Monk | GameEnums.eClass.Priest | GameEnums.eClass.Paladin | GameEnums.eClass.Shaman | GameEnums.eClass.Warrior; public static GameEnums.eClass trollClassMask = GameEnums.eClass.Monk | GameEnums.eClass.Hunter | GameEnums.eClass.Druid | GameEnums.eClass.Mage | GameEnums.eClass.Priest | GameEnums.eClass.Rogue | GameEnums.eClass.Warlock | GameEnums.eClass.Shaman | GameEnums.eClass.Warrior; public static GameEnums.eClass bloodElfClassMask = GameEnums.eClass.DemonHunter | GameEnums.eClass.DeathKnight | GameEnums.eClass.Hunter | GameEnums.eClass.Mage | GameEnums.eClass.Monk | GameEnums.eClass.Paladin | GameEnums.eClass.Priest | GameEnums.eClass.Rogue | GameEnums.eClass.Warlock | GameEnums.eClass.Warrior; public static GameEnums.eClass goblinClassMask = GameEnums.eClass.DeathKnight | GameEnums.eClass.Hunter | GameEnums.eClass.Mage | GameEnums.eClass.Priest | GameEnums.eClass.Rogue | GameEnums.eClass.Warlock | GameEnums.eClass.Shaman | GameEnums.eClass.Warrior; } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp6 { class GameEnums { public enum eStep { None = -1, SelectCamp, SelectTribe, SelectClass, SelectCharacterName, Done } //https://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/enumeration-types [Flags] public enum eCamp { None = 0, Alliance = 1, Horde = 2 } [Flags] public enum eTribe { //얼라진영 None = 0, Human = 1, Dwarf = 2, NightElf = 4, Gnome = 8, Draenei = 16, Worgen = 32, //호드진영 Orc = 64, Undead = 128, Tauren = 256, Troll = 512, BloodElf = 1024, Goblin = 2048, Pandaren = 4096, //Pandaren, } [Flags] public enum eClass { None = 0, DeathKnight = 1, DemonHunter = 2, Druid = 4, Hunter = 8, Mage = 16, Monk = 32, Paladin = 64, Priest = 128, Rogue = 256, Shaman = 512, Warlock = 1024, Warrior = 2048, } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp6 { class App { private Dictionary<GameEnums.eTribe, GameEnums.eClass> dicClasses; private GameEnums.eCamp selectedCamp = GameEnums.eCamp.None; private GameEnums.eTribe selectedTribe = GameEnums.eTribe.None; private GameEnums.eClass selectedClass = GameEnums.eClass.None; private string selectedCharacterName; //생성자 public App() { //Orc = 64, //Undead = 128, //Tauren = 256, //Troll = 512, //BloodElf = 1024, //Goblin = 2048, //Pandaren = 4096, this.dicClasses = new Dictionary<GameEnums.eTribe, GameEnums.eClass>() { { GameEnums.eTribe.Human, Mask.humanClassMask }, { GameEnums.eTribe.Dwarf, Mask.dwarfClassMask }, { GameEnums.eTribe.NightElf, Mask.nightElfClassMask }, { GameEnums.eTribe.Gnome, Mask.gnomeClassMask }, { GameEnums.eTribe.Draenei, Mask.draeneiClassMask }, { GameEnums.eTribe.Worgen, Mask.worgenClassMask }, { GameEnums.eTribe.Pandaren, Mask.pandarenClassMask }, { GameEnums.eTribe.Orc, Mask.orcClassMask }, { GameEnums.eTribe.Undead, Mask.undeadClassMask }, { GameEnums.eTribe.Tauren, Mask.taurenClassMask }, { GameEnums.eTribe.Troll, Mask.trollClassMask }, { GameEnums.eTribe.BloodElf, Mask.bloodElfClassMask }, { GameEnums.eTribe.Goblin, Mask.goblinClassMask }, }; this.MoveStep(GameEnums.eStep.SelectCamp, GameEnums.eStep.None); } //진영 private void SelectCamp() { while (true) { Console.WriteLine("진영을 선택 해주세요(얼라이언스 / 호드)?"); var input = Console.ReadLine(); if (input == "얼라이언스") { this.selectedCamp = GameEnums.eCamp.Alliance; this.MoveStep(GameEnums.eStep.SelectTribe, GameEnums.eCamp.Alliance); break; } else if (input == "호드") { this.selectedCamp = GameEnums.eCamp.Horde; this.MoveStep(GameEnums.eStep.SelectTribe, GameEnums.eCamp.Horde); break; } else { Console.WriteLine("잘못입력하셨습니다."); continue; } } } private void SelectTribe(GameEnums.eCamp selectedCamp) { Console.WriteLine($"selectedCamp: {this.selectedCamp}"); var strTribes = this.GetAvailableTribesString(); Console.WriteLine($"종족을 선택해주세요 [{strTribes}] "); while (true) { var keyChar = Console.ReadKey().KeyChar; int inputNum; Int32.TryParse(keyChar.ToString(), out inputNum); if (inputNum == 0) { //뒤로 돌아가기 this.MoveStep(GameEnums.eStep.SelectCamp, GameEnums.eStep.None); break; } else { //선택한 종족 this.selectedTribe = this.GetSelectedTribe(selectedCamp, inputNum); Console.WriteLine($"selectedTribe: {selectedTribe}"); //클래스 선택 하기 this.MoveStep(GameEnums.eStep.SelectClass, this.selectedTribe); break; } } } private GameEnums.eTribe GetSelectedTribe(GameEnums.eCamp selectedCamp, int inputNum) { string[] arrTribe = null; switch (selectedCamp) { case GameEnums.eCamp.Alliance: { arrTribe = Mask.allianceMask.ToString().Split(','); } break; case GameEnums.eCamp.Horde: { arrTribe = Mask.hordeMask.ToString().Split(','); } break; } return (GameEnums.eTribe)Enum.Parse(typeof(GameEnums.eTribe), arrTribe.GetValue(inputNum - 1).ToString().Trim()); } private GameEnums.eClass GetAvailableClass(GameEnums.eTribe selectedTribe, int index) { var availableClasses = dicClasses[selectedTribe]; string[] arrClasses = availableClasses.ToString().Split(','); return (GameEnums.eClass)Enum.Parse(typeof(GameEnums.eClass), arrClasses[index - 1].Trim()); } private string GetAvailableClassesString(GameEnums.eTribe selectedTribe) { var availableClasses = dicClasses[selectedTribe]; var sb = new StringBuilder(); string[] arrClasses = availableClasses.ToString().Split(','); int i = 1; foreach (var availableClass in arrClasses) { sb.Append(string.Format("{0}:{1} ", i, availableClass.Trim())); i++; } sb.Append(string.Format("{0}:돌아가기 ", 0)); return sb.ToString(); } private string GetAvailableTribesString() { var sb = new StringBuilder(); string[] arrTribe = null; switch (selectedCamp) { case GameEnums.eCamp.Alliance: { arrTribe = Mask.allianceMask.ToString().Split(','); } break; case GameEnums.eCamp.Horde: { arrTribe = Mask.hordeMask.ToString().Split(','); } break; } int i = 1; foreach (var tribe in arrTribe) { sb.Append(string.Format("{0}:{1} ", i, tribe.Trim())); i++; } sb.Append(string.Format("{0}:돌아가기 ", 0)); return sb.ToString(); } private void SelectClass(GameEnums.eTribe selectedTribe) { Console.WriteLine($"selectedTribe: {selectedTribe}"); //선택한 종족에 따라 직업군 보여주기 while (true) { var strAvailableClasses = GetAvailableClassesString(selectedTribe); Console.WriteLine($"직업을 선택해주세요 [ {strAvailableClasses} ] "); var keyChar = Console.ReadKey().KeyChar; int selectedNum; Int32.TryParse(keyChar.ToString(), out selectedNum); if (selectedNum == 0) { this.MoveStep(GameEnums.eStep.SelectTribe, this.selectedCamp); break; } else { this.selectedClass = this.GetAvailableClass(this.selectedTribe, selectedNum); this.MoveStep(GameEnums.eStep.SelectCharacterName, null); break; } } } private void MoveStep(GameEnums.eStep step, object selectedValue) { switch (step) { case GameEnums.eStep.SelectCamp: { this.SelectCamp(); } break; case GameEnums.eStep.SelectTribe: { this.SelectTribe((GameEnums.eCamp)selectedValue); } break; case GameEnums.eStep.SelectClass: { this.SelectClass((GameEnums.eTribe)selectedValue); } break; case GameEnums.eStep.SelectCharacterName: { this.SelectCharacterName(); } break; case GameEnums.eStep.Done: { this.Done(); } break; } } private void Done() { Console.WriteLine("케릭터가 생성되었습니다."); Console.WriteLine($"이름: {this.selectedCharacterName}"); Console.WriteLine($"진영: {this.selectedCamp}"); Console.WriteLine($"종족: {this.selectedTribe}"); Console.WriteLine($"직업: {this.selectedClass}"); Console.WriteLine("프로그램을 종료합니다."); } private void SelectCharacterName() { while (true) { Console.WriteLine("케릭터 이름을 정해주세요 : "); var input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { continue; } else { this.selectedCharacterName = input; this.MoveStep(GameEnums.eStep.Done, null); break; } } } } //진영선택 //얼라/호드 //종족선택 //1.오크/2.언데드/3.타우렌/4.트롤/5.블러드엘프/6.고블린/7.판다렌/0.뒤로돌아가기 //직업선택 (종족에따라) //1:죽음의기사 2: 사냥꾼, 3: 마법사, 4:수도사, 5:사제, 6:도적, 7:흑마법사, 8:전사 } | cs |
반응형
'Unity3D > C#' 카테고리의 다른 글
C#. 쓰레드(Thread) (0) | 2019.04.01 |
---|---|
컬렉션(C#) (0) | 2019.03.28 |
enum과 비트마스크 (0) | 2019.03.26 |
C# Array Value Type or Reference (0) | 2019.03.12 |
CLR(Common Language Runtime) (0) | 2019.03.12 |