'C#/과제'에 해당되는 글 17건

  1. 2019.04.10 롤 구현하기
  2. 2019.04.08 Character의 Move, Attack, MoveAttack 구현
  3. 2019.04.07 Inventory + Singleton
  4. 2019.04.04 Hash란?
  5. 2019.03.27 13. 인벤토리 구현하기
  6. 2019.03.27 12. WoW 캐릭터 생성 과제 (2단계+α 까지 완료)
  7. 2019.03.27 11. const(상수)와 enum(열거형)
  8. 2019.03.27 10. Class의 생성흐름 읽기 (동영상)

롤 구현하기

C#/과제 2019. 4. 10. 19:47

사용한 것 

Singleton Pattern, Dictionary, List, Interface, Json(load, save), DataTable, Vector, UML, 상속




인터페이스 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public interface IAttackable
    {
        bool Attack(Character target);
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public interface IMoveable
    {
        void Move(Vector2 targetPosition);
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class Character
    {
        public CharacterInfo charInfo;
 
        //생성자
        public Character(CharacterInfo info)
        {
            this.charInfo = info;
        }
 
        //피해메소드
        public virtual bool GetDamage(int damage)
        {
            return true;
        }
 
    }
}
 
cs


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 AniviaVsNashor
{
    public class Champion : Character
    {
        //생성자
        public Champion(CharacterInfo info) : base(info)
        {
 
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
 
namespace AniviaVsNashor
{
    public class Anivia : Champion, IAttackable,  IMoveable
    {
        private float moveSpeed = 3.25f;
        private DataStorage dataStorage = DataStorage.GetInstance();
        private Dictionary<int, CharacterData> dicData;
 
        //생성자
        public Anivia(CharacterInfo info) : base(info)
        {
            this.dicData = this.dataStorage.dicCharData;
        }
 
        //피해메소드
        public override bool GetDamage(int damage)
        {
            Console.WriteLine("{0}의 데미지를 입었습니다!", damage);
            this.charInfo.remainHp -= damage;
            if (this.charInfo.remainHp <= 0)
            {
                Console.WriteLine("체력이 0이 되어 에그니비아로 환생합니다.");
                Console.WriteLine("환생까지 10턴이 소모됩니다.");
                Thread.Sleep(500);
                return false;
            }
            Console.WriteLine("현재 체력 : ({0}/{1})"this.charInfo.remainHp, this.dicData[this.charInfo.id].maxHp);
            return true;
        }
 
        //거리를 리턴해주는 메소드
        public float GetDistance(Vector2 targetPosition)
        {
            return Vector2.GetDistance(this.charInfo.position, targetPosition);
        }
 
        #region IAttackable, IMoveable 구현부분
        public bool Attack(Character target)
        {
            Thread.Sleep(500);
            Console.WriteLine("\n{0}을 공격합니다."this.dicData[target.charInfo.id].name);
            Console.WriteLine("{0}에게 {1}의 피해를 주었습니다!"this.dicData[target.charInfo.id].name, this.dicData[this.charInfo.id].damage);
            var alive = target.GetDamage(this.dicData[this.charInfo.id].damage);
            return alive;
        }
        public void Move(Vector2 targetPosition) //애니비아 이동속도 3.25 가정한다.
        {
            var distanceVector = targetPosition - this.charInfo.position; //거리벡터
            var normalizeVector = Vector2.Normalize(distanceVector); //거리벡터의 단위벡터(방향벡터)
            var speedVector = normalizeVector * moveSpeed; //스칼라곱을 통하여 방향벡터로 향하는 속도벡터 산출
            var distance = Vector2.GetDistance(this.charInfo.position, targetPosition); //타겟과의 거리 산출
 
            while(true)
            {
                distance = Vector2.GetDistance(this.charInfo.position, targetPosition);
                Thread.Sleep(500);
                if (distance > this.dicData[this.charInfo.id].attackRange)
                {
                    Console.WriteLine("사거리가 닿지 않아 이동합니다.");
                    this.charInfo.position += speedVector;
                    Console.WriteLine("현재 {0}의 위치 : ({1}/{2})"this.dicData[this.charInfo.id].name, this.charInfo.position.x, this.charInfo.position.y);
                }
                else if (distance <= this.dicData[this.charInfo.id].attackRange)
                {
                    Console.WriteLine("사거리 내에 바론이 있습니다. 이동을 멈춥니다.");
                    break;
                }
            }
        }
        #endregion
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class Eggnivia : Champion
    {
        private DataStorage dataStorage = DataStorage.GetInstance();
        private Dictionary<int, CharacterData> dicData;
        private int remainTurn = 9;
 
        //생성자
        public Eggnivia(CharacterInfo info) : base(info)
        {
            this.dicData = this.dataStorage.dicCharData;
        }
 
        //피해메소드
        public override bool GetDamage(int damage)
        {
            Console.WriteLine("{0}의 데미지를 입었습니다!", damage);
            this.charInfo.remainHp -= damage;
            if (this.remainTurn > 0)
            {
                Console.WriteLine("현재 체력 : ({0}/{1})"this.charInfo.remainHp, this.dicData[this.charInfo.id].maxHp);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("애니비아의 환생까지 {0}턴 남았습니다."this.remainTurn);
                Console.ForegroundColor = ConsoleColor.Gray;
                this.remainTurn--;
                return false;
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("****에그니비아가 애니비아로 환생합니다!****");
            Console.ForegroundColor = ConsoleColor.Gray;
            remainTurn = 9;
            return true;
        }
    }
}
 
cs


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 AniviaVsNashor
{
    public class Monster : Character
    {
        //생성자
        public Monster(CharacterInfo info) : base(info)
        {
 
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class NashorBaron : Monster, IAttackable
    {
        private DataStorage dataStorage = DataStorage.GetInstance();
        private Dictionary<int, CharacterData> dicData;
 
        //생성자
        public NashorBaron(CharacterInfo info) : base(info)
        {
            this.dicData = this.dataStorage.dicCharData;
        }
 
        //피해메소드
        public override bool GetDamage(int damage)
        {
            this.charInfo.remainHp -= damage;
            if (this.charInfo.remainHp <= 0)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\n바론이 죽었습니다!");
                return false;
            }
            Console.WriteLine("{0}의 현재 체력 : ({1}/{2})"this.dicData[this.charInfo.id].name, this.charInfo.remainHp, this.dicData[this.charInfo.id].maxHp);
            return true;
        }
 
        #region IAttackable 구현부분
        public bool Attack(Character target)
        {
            Console.WriteLine("\n{0}이 {1}를 공격합니다."this.dicData[this.charInfo.id].name, this.dicData[target.charInfo.id].name);
            var alive = target.GetDamage(this.dicData[this.charInfo.id].damage);
            return alive;
        }
        #endregion
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class CharacterData
    {
        public int id;
        public string name;
        public int maxHp;
        public int remainHp;
        public int damage;
        public float attackRange;
 
        //생성자
        public CharacterData()
        {
 
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class DataStorage
    {
        private static DataStorage instance;
        public Dictionary<int, CharacterData> dicCharData;
 
        //생성자
        private DataStorage()
        {
 
        }
 
        //인스턴스 리턴 메서드
        public static DataStorage GetInstance()
        {
            if (DataStorage.instance == null)
            {
                DataStorage.instance = new DataStorage();
            }
            return DataStorage.instance;
        }
    }
}
 
cs




인포

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class CharacterInfo
    {
        public int id;
        public int remainHp { get; set; }
        public Vector2 position;
 
        //생성자
        public CharacterInfo(int id)
        {
            this.id = id;
        }
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class UserInfo
    {
        public GameInfo gameInfo;
        public int userId { get; set; }
        public string userName { get; set; }
 
        //생성자
        public UserInfo(GameInfo info)
        {
            this.gameInfo = info;
        }
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class GameInfo
    {
        public List<CharacterInfo> listCharInfo;
 
        //생성자
        public GameInfo()
        {
 
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class Vector2
    {
        public float x;
        public float y;
 
        //생성자
        public Vector2(float x, float y)
        {
            this.x = x;
            this.y = y;
        }
 
        //operator
        public static Vector2 operator +(Vector2 a, Vector2 b)
        {
            return new Vector2((a.x + b.x), (a.y + b.y));
        }
 
        public static Vector2 operator -(Vector2 a, Vector2 b)
        {
            return new Vector2((a.x - b.x), (a.y - b.y));
        }
 
        public static Vector2 operator *(Vector2 a, float b)
        {
            return new Vector2((a.x * b), (a.y * b));
        }
 
        //calculate vector
        //정규화 메소드
        public static Vector2 Normalize(Vector2 a)
        {
            return  new Vector2((a.x / Vector2.GetLength(a)), (a.y / Vector2.GetLength(a)));
        }
 
        //길이리턴 메소드
        public static float GetLength(Vector2 a)
        {
            return (float)Math.Sqrt(Math.Pow(a.x, 2+ Math.Pow(a.y, 2));
        }
 
        //거리리턴 메소드
        public static float GetDistance(Vector2 a, Vector2 b)
        {
            return (float)Math.Sqrt(Math.Pow(a.x - b.x, 2+ Math.Pow(a.y - b.y, 2));
        }
    }
}
 
cs




실행부

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 AniviaVsNashor
{
    class Program
    {
        static void Main(string[] args)
        {
            App app = new App();
            app.Start();
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AniviaVsNashor
{
    public class App
    {
        private GameLauncher gameLauncher;
 
        //생성자
        public App()
        {
            Console.WriteLine("App이 실행되었습니다.");
            this.gameLauncher = new GameLauncher();
        }
 
        //앱실행
        public void Start()
        {
            this.gameLauncher.Start();
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Threading;
using Newtonsoft.Json;
 
namespace AniviaVsNashor
{
    public class GameLauncher
    {
        private DataStorage dataStorage;
        private Anivia anivia;
        private NashorBaron baron;
        private Eggnivia eggnivia;
        private UserInfo userInfo;
 
        //생성자
        public GameLauncher()
        {
            this.dataStorage = DataStorage.GetInstance();
        }
 
        //런쳐실행
        public void Start()
        {
            bool success;
            success = this.LoadData("./data/character_data.json");
            if(success)
            {
                Console.WriteLine("데이터 로딩에 성공했습니다!");
            }
            success = this.LoadData("./info/user_info.json");
            if (success)
            {
                Console.WriteLine("환영합니다.");
            }
 
            this.SetData();
            this.UpdateData();
 
            this.GameStart();
        }
 
        //데이터로드
        public bool LoadData(string path)
        {
            switch(path)
            {
                case "./data/character_data.json":
                    {
                        var isExist = File.Exists(path);
                        if(isExist == false)
                        {
                            throw new Exception("게임을 플레이하기 위한 데이터가 없습니다");
                        }
                        this.dataStorage.dicCharData = new Dictionary<int, CharacterData>();
                        var temp = File.ReadAllText(path);
                        var dataJson = JsonConvert.DeserializeObject<CharacterData[]>(temp);
                        for (int index = 0; index < dataJson.Length; index++)
                        {
                            this.dataStorage.dicCharData.Add(index, dataJson[index]);
                        }
                        return true;
                    }
                case "./info/user_info.json":
                    {
                        var isExist = File.Exists(path);
                        if(isExist == false)
                        {
                            Console.WriteLine("새로운 유저의 데이터를 생성합니다.");
                            this.userInfo = new UserInfo(new GameInfo());
                            this.userInfo.userId = 0;
                            this.userInfo.userName = "유저";
                            this.userInfo.gameInfo.listCharInfo = new List<CharacterInfo>();
                            this.userInfo.gameInfo.listCharInfo.Add(new CharacterInfo(0));
                            this.userInfo.gameInfo.listCharInfo[0].remainHp = this.dataStorage.dicCharData[0].maxHp;
                            this.userInfo.gameInfo.listCharInfo[0].position = new Vector2(00);
                            this.userInfo.gameInfo.listCharInfo.Add(new CharacterInfo(1));
                            this.userInfo.gameInfo.listCharInfo[1].remainHp = this.dataStorage.dicCharData[1].maxHp;
                            this.userInfo.gameInfo.listCharInfo[1].position = new Vector2(00);
                            this.userInfo.gameInfo.listCharInfo.Add(new CharacterInfo(2));
                            this.userInfo.gameInfo.listCharInfo[2].remainHp = this.dataStorage.dicCharData[2].maxHp;
                            this.userInfo.gameInfo.listCharInfo[2].position = new Vector2(1515);
                        }
                        else if(isExist)
                        {
                            Console.WriteLine("기존 유저의 데이터를 불러옵니다.");
                            var temp = File.ReadAllText(path);
                            var dataJson = JsonConvert.DeserializeObject<UserInfo>(temp);
                            this.userInfo = dataJson;
                        }
                        return true;
                    }
                default:
                    {
                        Console.WriteLine("경로가 잘못되었습니다.");
                        return false;
                    }
            }
        }
 
        //객체생성
        public void SetData()
        {
            this.anivia = new Anivia(this.userInfo.gameInfo.listCharInfo[0]);
            this.eggnivia = new Eggnivia(this.userInfo.gameInfo.listCharInfo[1]);
            this.baron = new NashorBaron(this.userInfo.gameInfo.listCharInfo[2]);
        }
 
        //게임시작
        public void GameStart()
        {
            bool aniviaAlive = true;
            bool baronAlive = true;
            Console.WriteLine("**************게임을 시작합니다*************");
            while(true)
            {
                this.UpdateData();
                Console.WriteLine("\n1.계속하기 2.저장하고 종료하기");
                var continueKey = Console.ReadKey().Key;
                if(continueKey == ConsoleKey.D2)
                {
                    this.SaveData();
                    break;
                }
                if (this.dataStorage.dicCharData[this.anivia.charInfo.id].attackRange <= this.anivia.GetDistance(this.baron.charInfo.position))
                {
                    Thread.Sleep(500);
                    this.anivia.Move(this.baron.charInfo.position);
                }
                Thread.Sleep(500);
                baronAlive = this.anivia.Attack(this.baron);
                if(baronAlive == false)
                {
                    Console.WriteLine("\n*****축하합니다. 게임을 클리어하셨습니다!*****");
                    break;
                }
                Thread.Sleep(1000);
                aniviaAlive = this.baron.Attack(this.anivia);
                if(aniviaAlive == false)
                {
                    for(int remainTurn = 10; remainTurn > 0; remainTurn--)
                    {
                        Thread.Sleep(1000);
                        this.baron.Attack(this.eggnivia);
                    }
                    this.anivia.charInfo.remainHp = this.dataStorage.dicCharData[this.anivia.charInfo.id].maxHp;
                    this.eggnivia.charInfo.remainHp = this.dataStorage.dicCharData[this.eggnivia.charInfo.id].maxHp;
                }
            }
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("게임을 종료합니다.");
        }
 
        //데이터업데이트 (CharacterInfo List Update)
        public void UpdateData()
        {
            this.userInfo.gameInfo.listCharInfo[0].remainHp = this.anivia.charInfo.remainHp;
            this.userInfo.gameInfo.listCharInfo[0].position = this.anivia.charInfo.position;
            this.userInfo.gameInfo.listCharInfo[1].remainHp = this.eggnivia.charInfo.remainHp;
            this.userInfo.gameInfo.listCharInfo[1].position = this.eggnivia.charInfo.position;
            this.userInfo.gameInfo.listCharInfo[2].remainHp = this.baron.charInfo.remainHp;
            this.userInfo.gameInfo.listCharInfo[2].position = this.baron.charInfo.position;
        }
 
        //데이터를 파일로 저장
        public void SaveData()
        {
            if(Directory.Exists("./info"== false)
            {
                Directory.CreateDirectory("./info");
            }
            var dataJson = JsonConvert.SerializeObject(this.userInfo);
            File.WriteAllText("./info/user_info.json", dataJson);
        }
 
    }
}
 
cs


'C# > 과제' 카테고리의 다른 글

Character의 Move, Attack, MoveAttack 구현  (0) 2019.04.08
Inventory + Singleton  (0) 2019.04.07
Hash란?  (0) 2019.04.04
13. 인벤토리 구현하기  (0) 2019.03.27
12. WoW 캐릭터 생성 과제 (2단계+α 까지 완료)  (0) 2019.03.27
:

Character의 Move, Attack, MoveAttack 구현

C#/과제 2019. 4. 8. 21:16

1. Champion(애니비아)가 Monster(바론남작)을 향해 Move, Attack, MoveAttack(어택땅)하는 것을 구현

2. Vector를 이용하여 이동 속도, 이동 거리, 사거리 계산 및 구현

3. Json을 통하여 저장 및 불러오기가 가능




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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
 
namespace CharacterSystem
{
    public class Character
    {
        public int Hp { get; set; }
        public int Damage { get; set; }
        public int AttackRange { get; set; }
        public string Name { get; set; }
        public float MoveSpeed { get; set; }
 
        public Vector2 position { get; set; }
        public Vector2 targetPosition { get; set; }
        private Vector2 movePoint;
 
        //매개변수 3개 생성자
        public Character(int hp, int damage, int attackRange)
        {
            this.Hp = hp;
            this.Damage = damage;
            this.AttackRange = attackRange;
        }
 
        //이동 메서드
        public virtual void Move(Vector2 movePoint)
        {
            this.movePoint = movePoint;
            var distanceVector = new Vector2(this.movePoint.x - this.position.x, this.movePoint.y - this.position.y); //거리벡터(C)
            var normalizationVector = Vector2.Nomrmalization(distanceVector); //거리벡터의 단위벡터(방향벡터)
            var speedVector = new Vector2(normalizationVector.x * this.MoveSpeed, normalizationVector.y * this.MoveSpeed); //A벡터가 방향벡터로 이동하는 속도벡터
 
            while (true)
            {
                Thread.Sleep(300);
                this.position += speedVector;
                Console.WriteLine("{0}의 현재위치 : ({1}, {2})"this.Name, this.position.x, this.position.y);
                distanceVector = new Vector2(this.movePoint.x - this.position.x, this.movePoint.y - this.position.y); //거리벡터(C)
                if (distanceVector.x <= 0 && distanceVector.y <= 0)
                {
                    this.position = new Vector2(movePoint.x, movePoint.y);
                    Console.WriteLine("도착지점에 도착했습니다.");
                    Console.WriteLine("{0}의 현재위치 : ({1}, {2})"this.Name, this.position.x, this.position.y);
                    break;
                }
                else
                {
                    continue;
                }
            }
        }
 
        //공격 메서드
        public virtual void Attack(Character target, int attackCount)
        {
            var distanceVector = new Vector2(target.position.x - this.position.x, target.position.y - this.position.y);
            var distance = Vector2.GetLenght(distanceVector);
            if (distance <= this.AttackRange)
            {
                for(int i=0; i<attackCount; i++)
                {
                    target.TakeDamage(this.Damage);
                    Console.WriteLine("{0}회차 공격! {1}에게 {2}의 데미지를 입혔습니다!", i+1, target.Name, this.Damage);
                    Thread.Sleep(300);
                    Console.WriteLine("{0}의 남은 체력 : {1}", target.Name, target.Hp);
                }
            }
            else
            {
                Console.WriteLine("사거리가 닿지 않습니다.");
            }
 
        }
 
        //피해 메서드
        public virtual void TakeDamage(int damage)
        {
            this.Hp -= damage;
        }
 
        //이동공격 메서드
        public virtual void MoveAttack(Character target)
        {
            this.targetPosition = target.position;
            var distanceVector = new Vector2(target.position.x - this.position.x, target.position.y - this.position.y); //거리벡터
            var normalizationVector = Vector2.Nomrmalization(distanceVector); //거리벡터의 단위벡터
            var speedVector = new Vector2(normalizationVector.x * this.MoveSpeed, normalizationVector.y * this.MoveSpeed); //A벡터가 이동하는 속도벡터
            var distance = Vector2.GetDistance(this.targetPosition, this.position);
            var selectAttackContinue = ConsoleKey.D1;
 
            while (selectAttackContinue != ConsoleKey.N)
            {
                Thread.Sleep(300);
                distance = Vector2.GetDistance(this.targetPosition, this.position);
                if(target.Hp <= 0)
                {
                    Console.WriteLine("{0}가 죽었습니다.", target.Name);
                    break;
                }
                if (distance <= this.AttackRange)
                {
                    Console.WriteLine("{0}이 {1}의 공격사거리안에 들어왔습니다.\n공격을 시작합니다.", target.Name, this.Name);
                    for(int i=0; target.Hp > 0; i++)
                    {
                        target.Hp -= this.Damage;
                        Console.WriteLine("\n{0}회차 공격! {1}에게 {2}의 데미지를 입혔습니다!", i + 1, target.Name, this.Damage);
                        Console.WriteLine("{0}의 남은 체력 : {1}", target.Name, target.Hp);
                        Console.Write("계속 공격하시겠습니까? (Y/N) : ");
                        selectAttackContinue = Console.ReadKey().Key;
                        if(selectAttackContinue != ConsoleKey.Y)
                        {
                            Console.WriteLine("공격을 중지합니다.");
                            Thread.Sleep(1000);
                            break;
                        }
                    }
                }
                else if(distance >= this.AttackRange)
                {
                    Console.WriteLine("사거리가 닿지 않아 타겟을 향해 이동합니다.");
                    this.position += speedVector;
                }
            }
        }
    }
}
 
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace CharacterSystem
{
    public class Champion : Character
    {
 
        //매개변수 3개 생성자
        public Champion(int hp, int damage, int attackRange) : base(hp, damage, attackRange)
        {
 
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
 
namespace CharacterSystem
{
    public class Anivia : Champion
    {
 
        //매개변수 3개 생성자
        public Anivia(int hp, int damage, int attackRange) : base(hp, damage, attackRange)
        {
            this.Name = "애니비아";
            this.MoveSpeed = 1.5f;
            this.position = new Vector2(00);
            Console.WriteLine("애니비아 데미지 {0}"this.Damage);
        }
 
        //JsonConstructor
        [JsonConstructor]
        public Anivia(Vector2 position, Vector2 targetPosition, int hp, int damage, int attackRange, string name, float moveSpeed) : base(hp, damage, attackRange)
        {
            this.position = position;
            this.targetPosition = targetPosition;
            this.Name = name;
            this.MoveSpeed = moveSpeed;
        }
    }
}
 
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace CharacterSystem
{
    public class Monster : Character
    {
 
        //매개변수 3개 생성자
        public Monster(int hp, int damage, int attackRange) : base (hp, damage, attackRange)
        {
 
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
 
namespace CharacterSystem
{
    public class BaronNashor : Monster
    {
 
        //매개변수 3개 생성자
        public BaronNashor(int hp, int damage, int attackRange) : base(hp, damage, attackRange)
        {
            this.Name = "내셔남작";
            this.position = new Vector2(1515);
            this.targetPosition = new Vector2(00);
        }
 
        //저장된 데이터 기반 생성자
        public BaronNashor(int hp, int damage, int attackRange, string name, Vector2 position) : base(hp, damage, attackRange)
        {
            this.Name = name;
            this.position = position;
        }
 
        public override void Move(Vector2 movePoint)
        {
            Console.WriteLine("{0}은 이동할 수 없습니다.");
        }
 
        [JsonConstructor]
        public BaronNashor(Vector2 position, Vector2 targetPosition, int hp, int damage, int attackRange, string name, float moveSpeed) : base(hp, damage, attackRange)
        {
            this.position = position;
            this.targetPosition = targetPosition;
            this.Name = name;
            this.MoveSpeed = moveSpeed;
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace CharacterSystem
{
    public class Vector2
    {
        public float x;
        public float y;
 
        //생성자
        public Vector2(float x, float y)
        {
            this.x = x;
            this.y = y;
        }
 
        //Vector2 Class Operator Overload
        public static Vector2 operator+(Vector2 a, Vector2 b)
        {
            return new Vector2(a.x + b.x, a.y + b.y);
        }
        public static Vector2 operator -(Vector2 a, Vector2 b)
        {
            return new Vector2(a.x - b.x, a.y - b.y);
        }
        public static Vector2 operator *(Vector2 a, Vector2 b)
        {
            return new Vector2(a.x * b.x, a.y * b.y);
        }
        public static Vector2 operator /(Vector2 a, Vector2 b)
        {
            return new Vector2(a.x / b.x, a.y / b.y);
        }
 
        //Distance
        public static float GetDistance(Vector2 position, Vector2 targetPosition)
        {
            return (float)Math.Sqrt(Math.Pow(position.x - targetPosition.x, 2+ Math.Pow(position.y - targetPosition.y, 2));
        }
 
        //Nomalization
        public static Vector2 Nomrmalization(Vector2 vector)
        {
            return new Vector2(vector.x / Vector2.GetLenght(vector), vector.y / Vector2.GetLenght(vector));
        }
 
        //Lenght
        public static float GetLenght(Vector2 vector)
        {
            return (float)Math.Sqrt((vector.x * vector.x) + (vector.y * vector.y));
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Threading;
using System.IO;
 
namespace CharacterSystem
{
    public class GameLauncher
    {
        public ConsoleKey menuKey;
        public ConsoleKey secondMenuKey;
        private DataStorage dataStorage;
 
        private BaronNashor baron;
        private Anivia anivia;
 
        //생성자
        public GameLauncher(DataStorage dataStorage)
        {
            Console.WriteLine("GameLauncher 생성자 호출");
            this.dataStorage = dataStorage;
        }
 
        //게임실행 메서드
        public void Start()
        {
            while (menuKey != ConsoleKey.D3)
            {
                Console.WriteLine("바론남작 죽이기 게임");
                Console.WriteLine("1.새로하기 2.불러오기 3.종료하기");
                menuKey = Console.ReadKey().Key;
                if(menuKey == ConsoleKey.D3)
                {
                    Console.WriteLine("바론남작 죽이기 게임을 종료합니다.");
                    break;
                }
                else if(menuKey == ConsoleKey.D1 || menuKey == ConsoleKey.D2)
                {
                    this.CreateData(menuKey);
                    Console.WriteLine("게임을 시작합니다.");
                    Thread.Sleep(1000);
                }
                else
                {
                    Console.WriteLine("잘못된 입력입니다.");
                    continue;
                }
                while(secondMenuKey != ConsoleKey.D7)
                {
                    this.ChoiceSecondMenu();
                    switch(secondMenuKey)
                    {                        
                        case ConsoleKey.D1:
                            Console.WriteLine("현재 {0}의 위치 : ({1}, {2})"this.baron.Name, this.baron.position.x, this.baron.position.y);
                            Console.WriteLine("나와의 거리 : {0}", Vector2.GetDistance(this.anivia.position, this.baron.position));
                            Console.ReadKey();
                            break;
                        case ConsoleKey.D2:
                            Console.WriteLine("현재 나의 위치 : ({0}, {1})"this.anivia.position.x, this.anivia.position.y);
                            Console.WriteLine("바론과의 거리 : {0}", Vector2.GetDistance(this.anivia.position, this.baron.position));
                            Console.ReadKey();
                            break;
                        case ConsoleKey.D3:
                            Console.Write("어디까지 이동하시겠습니까?(x y공백으로 구분하여 입력) : ");
                            int x, y;
                            var tempStr = Console.ReadLine();
                            string[] tempStrArr = tempStr.Split(' ');
                            Int32.TryParse(tempStrArr[0], out x);
                            Int32.TryParse(tempStrArr[1], out y);
                            anivia.Move(new Vector2(x, y));
                            break;
                        case ConsoleKey.D4:
                            Console.Write("몇회 공격하시겠습니까? (최대 10회) : ");
                            int attackCount;
                            if (Int32.TryParse(Console.ReadLine(), out attackCount))
                            {
                                anivia.Attack(baron, attackCount);
                            }
                            else
                            {
                                Console.WriteLine("잘못된 입력입니다.");
                            }
                            break;
                        case ConsoleKey.D5:
                            this.anivia.MoveAttack(baron);
                            break;
                        case ConsoleKey.D6:
                            this.UpdateData();
                            var aniviaJson = JsonConvert.SerializeObject(this.anivia);
                            File.WriteAllText("./data/anivia_data.json", aniviaJson, Encoding.UTF8);
                            var baronJson = JsonConvert.SerializeObject(this.baron);
                            File.WriteAllText("./data/baron_data.json", baronJson, Encoding.UTF8);
                            //this.UpdateData();
                            //var json = JsonConvert.SerializeObject(this.dataStorage.listCharacter);
                            //File.WriteAllText("./data/character_data.json", json, Encoding.UTF8);
                            //Console.WriteLine("저장을 완료했습니다! 게임을 종료합니다.");
                            Thread.Sleep(1000);
                            secondMenuKey = ConsoleKey.D7;
                            menuKey = ConsoleKey.D3;
                            break;
                        default:
                            Console.WriteLine("잘못된 입력입니다.");
                            break;
                    }
                }
                
            }
 
 
 
        }
 
        //데이터 생성 Method
        public void CreateData(ConsoleKey menuKey)
        {
            if(menuKey == ConsoleKey.D1)
            {
                //새로하기일 경우 초기값의 인스턴스 생성
                this.baron = new BaronNashor(1000010010);
                Console.WriteLine("{0}생성, 체력:{1}, 데미지:{2}, 사거리:{3}", baron.Name, baron.Hp, baron.Damage, baron.AttackRange);
                this.anivia = new Anivia(550255);
                Console.WriteLine("{0}생성, 체력:{1}, 데미지:{2}, 사거리:{3}", anivia.Name, anivia.Hp, anivia.Damage, anivia.AttackRange);
                Directory.CreateDirectory("./data/");
            }
            else if(menuKey == ConsoleKey.D2)
            {
                if(!(File.Exists("./data/anivia_data.json"|| File.Exists("./data/baron_data.json")))
                {
                    Console.WriteLine("저장된 데이터가 없습니다.");
                    Directory.CreateDirectory("./data/");
                    this.baron = new BaronNashor(1000010010);
                    Console.WriteLine("{0}생성, 체력:{1}, 데미지:{2}, 사거리:{3}", baron.Name, baron.Hp, baron.Damage, baron.AttackRange);
                    this.anivia = new Anivia(550255);
                    Console.WriteLine("{0}생성, 체력:{1}, 데미지:{2}, 사거리:{3}", anivia.Name, anivia.Hp, anivia.Damage, anivia.AttackRange);
                }
                else
                {
                    //애니비아 데이터 불러오기
                    var aniviaStr = File.ReadAllText("./data/anivia_data.json");
                    var aniviaArr = JsonConvert.DeserializeObject<Anivia>(aniviaStr);
                    this.anivia = aniviaArr;
 
                    //바론 데이터 불러오기
                    var baronStr = File.ReadAllText("./data/baron_data.json");
                    var baronArr = JsonConvert.DeserializeObject<BaronNashor>(baronStr);
                    this.baron = baronArr;
 
                    //생성 확인
                    Console.WriteLine("{0}생성, 체력:{1}, 데미지:{2}, 사거리:{3}", baron.Name, baron.Hp, baron.Damage, baron.AttackRange);
                    Console.WriteLine("{0}생성, 체력:{1}, 데미지:{2}, 사거리:{3}", anivia.Name, anivia.Hp, anivia.Damage, anivia.AttackRange);
                }
            }
        }
 
        //공격, 이동, 어택땅 선택 Method
        public void ChoiceSecondMenu()
        {
            Console.WriteLine("1.바론위치보기 2.내위치보기 3.이동하기 4.공격하기 5.어택땅 6.저장하고 돌아가기");
            this.secondMenuKey = Console.ReadKey().Key;
        }
 
        //데이터 업데이트 Method
        public void UpdateData()
        {
            this.dataStorage.listCharacter.Add(this.anivia);
            this.dataStorage.listCharacter.Add(this.baron);
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace CharacterSystem
{
    public class App
    {
        private GameLauncher gameLauncher;
        private DataStorage dataStorage;
        public App()
        {
            Console.WriteLine("App 생성자 호출");
            this.DataLoad();
            this.gameLauncher = new GameLauncher(this.dataStorage);
        }
 
        public void Start()
        {
            this.gameLauncher.Start();
        }
 
        public void DataLoad()
        {
            this.dataStorage = DataStorage.GetDataStorage();
        }
    }
}
 
cs





Anivia Class 와 BaronNashor Class에서 [JsonConstructor]라는 것이 있다.

이는 Newtonsoft.Json에서 지원하는 기능 중 하나로, JsonFile을 로드하여 그 File의 값을 통해 인스턴스를 생성할 때,

그에 맞는 Json전용 Constructor(생성자)를 선언할 수 있게 해주는 도구이다.



JsonConstructorAttribute (NewtonJson)

https://www.newtonsoft.com/json/help/html/JsonConstructorAttribute.htm


'C# > 과제' 카테고리의 다른 글

롤 구현하기  (0) 2019.04.10
Inventory + Singleton  (0) 2019.04.07
Hash란?  (0) 2019.04.04
13. 인벤토리 구현하기  (0) 2019.03.27
12. WoW 캐릭터 생성 과제 (2단계+α 까지 완료)  (0) 2019.03.27
:

Inventory + Singleton

C#/과제 2019. 4. 7. 21:16



Inventory 저장 및 불러오기 기능 + DataStorage Singleton 패턴으로 구현


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _0407
{
    public class WeaponData
    {
        public int id;
        public int count;
        public string name;
        public int damage;
        public WeaponData(int id, int count, string name, int damage)
        {
            this.id = id;
            this.count = 1;
            this.name = name;
            this.damage = damage;
        }
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _0407
{
    public class WeaponInfo : ItemInfo
    {
        public WeaponInfo(int id) : base(id)
        {
        }
    }
}
 
cs


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 _0407
{
    public class WeaponItem : Item
    {
        new public WeaponInfo info;
        public WeaponItem(WeaponInfo info) : base(info)
        {
            this.info = info;
        }
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _0407
{
    public class ItemInfo
    {
        public int id;
        public int count;
        public ItemInfo(int id)
        {
            this.id = id;
            this.count = 1;
        }
    }
}
 
cs


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 _0407
{
    public class Item
    {
        public ItemInfo info;
        public Item(ItemInfo info)
        { 
            this.info = info;
        }
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _0407
{
    public class InventoryInfo
    {
        private List<WeaponItem> itemList;
        public InventoryInfo(List<WeaponItem> list)
        {
            itemList = list;
        }
        public List<WeaponItem> ReturnList()
        {
            return this.itemList;
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.IO;
 
namespace _0407
{
    public class Inventory
    { 
        private List<WeaponItem> itemList;
        private DataStorage storage;
        public InventoryInfo info;
        public Inventory(InventoryInfo info)
        {
            this.info = info;
            this.itemList = info.ReturnList();
            this.storage = DataStorage.MakeDataStorage();
        }
 
        //추가 메서드
        public bool AddItem(string name)
        {
            var index = FindIndex(name);
            if (index != -1)
            {
                foreach(var item in itemList)
                {
                    if(item.info.id == index)
                    {
                        item.info.count++;
                        return true;
                    }
                }
                var weapon = new WeaponItem(new WeaponInfo(index));
                this.itemList.Add(weapon);
                Console.WriteLine("{0}이 인벤토리에 등록되었습니다.", name);
                return true;
            }
            Console.WriteLine("존재하지 않는 아이템입니다.");
            return false;
        }
        //dictionary key찾는메서드
        public int FindIndex(string name)
        {
            for (int index = 0; index < storage.dicWeaponData.Count; index++)
            {
                if (storage.dicWeaponData[index].name == name)
                {
                    return index;
                }
            }
            return -1;
        }
 
        //출력메서드
        public void PrintInventory()
        {
            foreach(var item in itemList)
            {
                Console.WriteLine("{0}x{1}",storage.dicWeaponData[item.info.id].name, item.info.count);
            }
        }
        //삭제메서드
        public bool RemoveItem(string name, int count)
        {
            var dicKey = FindIndex(name);
            int index = 0;
            if(dicKey != -1)
            {
                foreach (var item in itemList)
                {
                    if (item.info.id == dicKey)
                    {
                        if(item.info.count<=count)
                        {
                            Console.WriteLine("{0}를 {1}개 버렸습니다.", name, item.info.count);
                            itemList.RemoveAt(index);
                            return true;
                        }
                        Console.WriteLine("{0}를 {1}개 버렸습니다.", name, count);
                        item.info.count -= count;
                        return true;
                    }
                    index++;
                }
            }
            return false;
        }
        public void SaveInventory()
        {
            var json = JsonConvert.SerializeObject(this.itemList);
            File.WriteAllText("./inventory_info.json", json, Encoding.UTF8);
        }
    }
 
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _0407
{
    public class GameLauncher
    {
        private Inventory inventory;
        public GameLauncher(Inventory inventory)
        {
            this.inventory = inventory;
        }
 
        public void GameStart()
        {
            var menuKey = ConsoleKey.D5;
            while (menuKey!=ConsoleKey.D6)
            {
                Console.WriteLine("1.아이템제작  2.인벤토리보기  3.아이템꺼내기  4.저장후 종료");
                menuKey = Console.ReadKey().Key;
                switch (menuKey)
                {
                    case ConsoleKey.D1:
                        Console.WriteLine("프람베르그 / 무라마사 / 다마스커스 / 슈팅스타 / 등뒤를 베는자");
                        Console.Write("제작하실 아이템 이름을 입력하세요 : ");
                        var inputName = Console.ReadLine();
                        int createCount;
                        Console.Write("몇개 제작하시겠습니까?");
                        Int32.TryParse(Console.ReadLine(), out createCount);
                        for(int count=0; count<createCount; count++)
                        {
                           inventory.AddItem(inputName);
                        }
                        break;
                    case ConsoleKey.D2:
                        inventory.PrintInventory();
                        break;
                    case ConsoleKey.D3:
                        Console.Write("버리실 아이템 이름을 입력하세요 : ");
                        var dropItemName = Console.ReadLine();
                        int dropCount;
                        Console.Write("몇개 버리시겠습니까?");
                        Int32.TryParse(Console.ReadLine(), out dropCount);
                        var success = inventory.RemoveItem(dropItemName, dropCount);
                        if (success == false)
                        {
                            Console.WriteLine("인벤토리에 {0}이 존재하지 않습니다.", dropItemName);
                        }
                        break;
                    case ConsoleKey.D4:
                        inventory.SaveInventory();
                        Console.WriteLine("저장이 완료되었습니다.");
                        Console.WriteLine("프로그램을 종료합니다.");
                        menuKey = ConsoleKey.D6;
                        break;
                }
            }
        }
    }
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _0407
{
    public class DataStorage
    {
        private static DataStorage instance;
        public Dictionary<int, WeaponData> dicWeaponData = new Dictionary<int, WeaponData>();
        protected DataStorage()
        {
 
        }
        public static DataStorage MakeDataStorage()
        {
            if(instance == null)
            {
                instance = new DataStorage();
            }
            return instance;
        }
    }
 
}
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;
 
namespace _0407
{
    public class App
    {
        private GameLauncher gameLauncher;
        private DataStorage storage;
        public App()
        {
            this.gameLauncher = new GameLauncher(CreateInventory());
        }
 
        //시작 메서드
        public void Start()
        {
            this.LoadData();
            this.GameStart();
        }
 
        //데이터로드 메서드
        public void LoadData()
        {
            this.storage = DataStorage.MakeDataStorage();
            var str = File.ReadAllText("./weapon_item_data.json");
            var arrJson = JsonConvert.DeserializeObject<WeaponData[]>(str);
            foreach(var addJson in arrJson)
            {
                storage.dicWeaponData.Add(addJson.id, addJson);
            }
        }
 
        //인벤토리 제작 메서드
        public Inventory CreateInventory()
        {
            var isExist = File.Exists("./inventory_info.json");
            if (isExist)
            {
                var str = File.ReadAllText("./inventory_info.json");
                var arrJson = JsonConvert.DeserializeObject<List<WeaponItem>>(str);
                return new Inventory(new InventoryInfo(arrJson));
            }
            else
            {
                List<WeaponItem> list = new List<WeaponItem>();
                return new Inventory(new InventoryInfo(list));
            }
        }
        
        //런쳐시작 메서드
        public void GameStart()
        {
            this.gameLauncher.GameStart();
        }
    }
}
 
cs


'C# > 과제' 카테고리의 다른 글

롤 구현하기  (0) 2019.04.10
Character의 Move, Attack, MoveAttack 구현  (0) 2019.04.08
Hash란?  (0) 2019.04.04
13. 인벤토리 구현하기  (0) 2019.03.27
12. WoW 캐릭터 생성 과제 (2단계+α 까지 완료)  (0) 2019.03.27
:

Hash란?

C#/과제 2019. 4. 4. 00:34

Hash

해시는 Hashtable, Hashmap, SHA, MD와같이 알고리즘, 암호학에 사용된다.

해시함수를 통하여 어떠한 데이터를 고정길이의 데이터로 매핑한다. 원 데이터 값은 Key, 매핑 후의 값은 HashValue, 이 과정들을 Hashing이라한다.


Collision

Hashing은 Key를 고유의 계산식을 통하여 HashValue를 만드는 것이라고 하였다.

그럼 충돌은 무엇이고, 왜 일어날까?

충돌은 각각 다른 A, B의 Key를 Hashing했을 때, 둘 다 같은 HashValue를 가진 경우를 충돌했다고 한다.

서로 같은 HashValue를 들고 Bucket(저장공간)에 접근을 했다면, 충돌이 일어난 주소에는 누구를 저장해야할까?


위의 그림을 예시로 생각해보자.

그림이 마치 배열을 연상하게끔 하는데, 배열로 보면 {1,2,3,4,5,6,7}은 Index, 그 옆은 값을 저장하는 공간이고, 홍길동과 임꺽정은 포인터다.

배열에서는 각각의 값마다 고유의 Index를 가지고 정해진 양의 데이터를 정해진 공간에 저장하므로 같은 Index의 공간에 서로 저장하려고 하는 

저런 경우가 없지만, Hash는 Hash Function의 고유 계산식을 통해 값을 산출하는 방식이므로 위처럼 동일한 값이 나올 수 있다.

그래서 Key 홍길동의 HashValue는 3, Key 임꺽정의 HashValue는 3이라고 가정했을 때, 서로는 같은 곳을 차지하려하고 있다.

그렇게 동일 값이 나오면 어떻게 해야할까?


Collision Resolve

충돌을 해결하는 방법에는 첫번째로 chaining이 있다.

위처럼 같은 HashValue를 가질 경우, Bucket에 Linked-List를 이용하여 값을 연달아 저장하는 방식이다.

3번 Bucket에는 Linked-List가 있고, 첫번째는 길동이집주소가, 두번째에는 꺽정이집주소가 저장되는 것이다.


또, open addressing방식이 있다. 이는 chaining처럼 bucket에 Linked-List를 이용하여 여러 값을 넣는 것과는 달리 이는 한 bucket에 하나만 들어갈 수 있다.

linear probing(선형 탐색)은 꺽정이가 늦게 왔다고 가정했을 때, 3번 bucket에는 길동이가 먼저 차지했다. 그렇다면 꺽정이는 다음 방인

4번 bucket으로 가서 자리가 있는지 확인을 하고, 비어있다면 그 곳을 차지한다. 혹여나 4번 bucket에도 누군가 자리를 차지했다면 5번으로 간다.

즉 한칸씩 옆으로 가서 확인하고 자리를 차지하는 방식이다. (무조건 한칸씩이 아닌, 정해진 폭만큼 이동한다.(2칸씩일 수도 있다.))

quadratic probing(제곱 탐색)은 linear probing처럼 옆칸으로 가지만, 정해진 폭만큼이 아닌 제곱의 폭만큼 이동한다.

3번 bucket이 길동이가 차지하고 있어서 4번을 갔더니 거기도 누군가 차지하고 있었다. 그럼 4(2의 제곱)만큼 떨어진 7번 bucket으로 간다.

거기도 꽉차있으면 9(3의 제곱)만큼 떨어진 12번 bucket으로 간다. 거기도 꽉차있으면 16(4의 제곱)만큼 떨어진 19번 bucket으로 간다.

이를 제곱 탐색이라고 한다.

double hasing(더블 해싱)은 해시함수를 2개를 쓰는 방법인데, 1번 해시함수는 HashValue를 만든다. 그리고 2번 해시함수는 충돌시 이동하는 폭을 정한다. 단 이 방법은 1번 해시함수에서 나온 해시값과 2번 해시함수에서 나온 해시값은 서로소여야만하는 조건이 있다.


이 외에도 많은 collision resolve 방법이 있다.



Hash Function

해시함수는 해시값을 쉽게 계산해내고, 해시의 문제점인 Collision(충돌)을 최소화시키고, 그 충돌을 해결하고, 각 공간에 균일하게 값을 분포시키는 역할을 한다.

이 해시함수들은 각각 다른 고유의 계산식을 가지고 있어서 같은 Key를 Hashing하더라도 다른 HashValue가 도출된다.

Division Method(나눗셈법), Multiplication Method(2진수 연산에 최적화된 함수), Universal Hasing(다수의 해시함수를 두고 무작위로 골라 해싱) 등 여러 방법이 있다.

최적화된 해시함수는 임의의 Key가 특정한 HashValue로 치우치지 않고, 고루고루 분포되게 하는 함수가 최적의 함수이다.




참조

Hash Tables and Hash Functions (Computer Science)

https://www.youtube.com/watch?v=KyUTuwz_b7Q


What is a HashTable Data Structure - Intoduction to Hash Tables, Part 0 (Paul Programming)

https://www.youtube.com/watch?v=MfhjkfocRR0



:

13. 인벤토리 구현하기

C#/과제 2019. 3. 27. 22:27

 

List를 이용해 인벤토리 구현 및 아이템제작, 아이템버리기, 아이템사용 기능 구현

 

 

코드

Item.cs

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace study0327

{

    public class Item

    {

        public int itemCode;

        public string itemName;

        public string itemExplain;

        public Item()

        {

 

        }

    }

}

Colored by Color Scripter

cs

 

UseItem.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

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace study0327

{

    class UseItem : Item

    {

        public UseItem(string itemName)

        {

            this.itemCode = 1;

            this.itemName = itemName;

        }

        public string ItemExplain

        {

            get

            {

                return this.itemExplain;

            }

            set

            {

                if(!(this.itemExplain == null))

                {

                    this.itemExplain = value;

                }

            }

 

        }

    }

}

 

Colored by Color Scripter

cs

EquipItem.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

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace study0327

{

    class EquipItem : Item

    {

        public EquipItem(string itemName)

        {

            this.itemCode = 2;

            this.itemName = itemName;

        }

        public string ItemExplain

        {

            get

            {

                return this.itemExplain;

            }

            set

            {

                if (!(this.itemExplain == null))

                {

                    this.itemExplain = value;

                }

            }

 

        }

    }

}

 

Colored by Color Scripter

cs

 

EtcItem.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

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace study0327

{

    class EtcItem : Item

    {

        public EtcItem(string itemName)

        {

            this.itemCode = 3;

            this.itemName = itemName;

        }

        public string ItemExplain

        {

            get

            {

                return this.itemExplain;

            }

            set

            {

                if (!(this.itemExplain == null))

                {

                    this.itemExplain = value;

                }

            }

 

        }

    }

}

 

Colored by Color Scripter

cs

AvailableTest.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

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace study0327

{

    public static class AvailableTest

    {

        public static bool CanAddList(string inputItemName) //존재하는 아이템인지 체크하는 메서드

        {

            if (inputItemName == "빵" || inputItemName == "포션" || inputItemName == "마녀의 귀걸이" ||

                inputItemName == "헤르메스의 부츠" || inputItemName == "오크의 손톱")

            {

                return true;

            }

            else

            {

                return false;

            }

        }

        public static string MakeItem() //아이템을 제작가능한지 체크하고 가능하다면 이름을 리턴하는 메서드

        {

            Console.Clear();

            System.Threading.Thread.Sleep(500);

            Console.WriteLine("아이템을 제작합니다.");

            Console.WriteLine("1.빵 \t 2.포션 \t 3.마녀의 귀걸이");

            Console.WriteLine("4.헤르메스의 부츠 \t 5.오크의 손톱");

            Console.Write("6.되돌아가기 (한글로 입력하세요) : ");

            string inputItemName = Console.ReadLine();

            if (CanAddList(inputItemName) == true)

            {

                return inputItemName;

            }

            else if (inputItemName == "되돌아가기")

            {

                return "break";

            }

            else

            {

                Console.WriteLine("제작할 수 없는 아이템입니다.");

                return "x";

            }

        }

        public static bool UseToItem(string inputItemName) //아이템이 사용가능한지 체크하는 메서드

        {

            if (inputItemName == "빵" || inputItemName == "포션")

            {

                Console.Write("아이템을 사용했습니다.");

                System.Threading.Thread.Sleep(500);

                return true;

            }

            else

            {

                Console.Write("사용할 수 없는 아이템입니다.");

                System.Threading.Thread.Sleep(500);

                return false;

            }

        }

        public static bool CheckItem(List<Item> itemList, string InputItemName)

        {

            foreach (Item checkList in itemList)

            {

                if (checkList.itemName == InputItemName)

                {

                    return true;

                }

            }

            return false;

        }

    }

}

 

Colored by Color Scripter

cs

 

App.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

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace study0327

{

    class App

    {

        public App()

        {

            bool availability; //성공가능 여부 변수

            string inputItemName; //아이템 제작 변수

            string choiceItemName = null//인벤토리 아이템 선택 변수

            int keyToSelectMenu; //메뉴선택 키값을 변환한 정수형변수

            int count = 1//출력 카운트 변수

            int breadCount = 0//빵 카운트 변수

            int potionCount = 0//포션 카운트 변수

            int ringCount = 0//귀걸이 카운트 변수

            int bootsCount = 0//신발 카운트 변수

            int orcCount = 0//손톱 카운트 변수

            int menuCount = 1//목록 출력 변수

            ConsoleKey menuKey = ConsoleKey.D1; //메뉴선택키

            List<Item> inventory = new List<Item>(); //아이템 리스트

 

            while (menuKey != ConsoleKey.D9) //실행

            {

                menuKey = ConsoleKey.D0;

                while (menuKey == ConsoleKey.D0) //반복

                {

                    System.Threading.Thread.Sleep(500);

                    Console.Clear();

                    Console.WriteLine("※아이템은 최대 10개까지 소지할 수 있습니다※");

                    Console.Write("1.아이템제작 \t 2.인벤토리 \t 3.종료");

                    menuKey = Console.ReadKey().Key;

                    while (menuKey == ConsoleKey.D1) //제작

                    {

                        if ((inventory.Count) > 9//10칸 가득차면 제작 불가능

                        {

                            Console.WriteLine("인벤토리가 가득 찼습니다!!");

                            menuKey = ConsoleKey.D0;

                            break;

                        }

                        inputItemName = AvailableTest.MakeItem();

                        if (inputItemName == "되돌아가기"//자의적 탈출

                        {

                            menuKey = ConsoleKey.D0;

                        }

                        if (inputItemName == "빵" || inputItemName == "포션")

                        {

                            inventory.Add(new UseItem(inputItemName));

                            Console.Write("제작에 성공했습니다!");

                            menuKey = ConsoleKey.D0;

                        }

                        else if (inputItemName == "마녀의 귀걸이" || inputItemName == "헤르메스의 부츠")

                        {

                            inventory.Add(new EquipItem(inputItemName));

                            Console.Write("제작에 성공했습니다!");

                            menuKey = ConsoleKey.D0;

                        }

                        else if (inputItemName == "오크의 손톱")

                        {

                            inventory.Add(new EtcItem(inputItemName));

                            Console.Write("제작에 성공했습니다!");

                            menuKey = ConsoleKey.D0;

                        }

                        else

                        {

                            Console.WriteLine("제작할 수 없는 아이템입니다!");

                            menuKey = ConsoleKey.D0;

                        }

                    }

                    while (menuKey == ConsoleKey.D2) //인벤토리출력

                    {

                        Console.Clear();

                        if(inventory.Count<1)

                        {

                            Console.WriteLine("인벤토리가 비어있습니다.");

                            System.Threading.Thread.Sleep(500);

                            break;

                        }

                        breadCount = 0;

                        potionCount = 0;

                        ringCount = 0;

                        bootsCount = 0;

                        orcCount = 0;

                        menuCount = 1;

                        foreach (Item itemList in inventory) //아이템 갯수 확인

                        {

                            if (itemList.itemName == "빵")

                            {

                                breadCount++;

                            }

                            else if (itemList.itemName == "포션")

                            {

                                potionCount++;

                            }

                            else if (itemList.itemName == "마녀의 귀걸이")

                            {

                                ringCount++;

                            }

                            else if (itemList.itemName == "헤르메스의 부츠")

                            {

                                bootsCount++;

                            }

                            else if (itemList.itemName == "오크의 손톱")

                            {

                                orcCount++;

                            }

                        }

                        foreach (Item itemlist in inventory) //아이템 갯수 포함 출력

                        {

                            switch (itemlist.itemName)

                            {

                                case "빵":

                                    if (breadCount != -1)

                                    {

                                        Console.WriteLine("{0}. {1} x{2}", menuCount, itemlist.itemName, breadCount);

                                        breadCount = -1;

                                        menuCount++;

                                    }

                                    break;

                                case "포션":

                                    if (potionCount != -1)

                                    {

                                        Console.WriteLine("{0}. {1} x{2}", menuCount, itemlist.itemName, potionCount);

                                        potionCount = -1;

                                        menuCount++;

                                    }

                                    break;

                                case "마녀의 귀걸이":

                                    if (ringCount != -1)

                                    {

                                        Console.WriteLine("{0}. {1} x{2}", menuCount, itemlist.itemName, ringCount);

                                        ringCount = -1;

                                        menuCount++;

                                    }

                                    break;

                                case "헤르메스의 부츠":

                                    if (bootsCount != -1)

                                    {

                                        Console.WriteLine("{0}. {1} x{2}", menuCount, itemlist.itemName, bootsCount);

                                        bootsCount = -1;

                                        menuCount++;

                                    }

                                    break;

                                case "오크의 손톱":

                                    if (orcCount != -1)

                                    {

                                        Console.WriteLine("{0}. {1} x{2}", menuCount, itemlist.itemName, orcCount);

                                        orcCount = -1;

                                        menuCount++;

                                    }

                                    break;

                            }

                        }

                        Console.Write("1.아이템사용 2.아이템버리기 3.되돌아가기 : ");

                        Int32.TryParse(Console.ReadLine(), out keyToSelectMenu);

                        switch (keyToSelectMenu)

                        {

                            case 1:

                                Console.Write("사용할 아이템의 이름을 입력하세요 : ");

                                choiceItemName = Console.ReadLine();

                                availability = AvailableTest.CheckItem(inventory, choiceItemName);

                                if (availability == false)

                                {

                                    Console.WriteLine("존재하지 않는 아이템입니다.");

                                    System.Threading.Thread.Sleep(500);

                                }

                                if (availability == true)

                                {

                                    availability = AvailableTest.UseToItem(choiceItemName);

                                    if (availability == true)

                                    {

                                        count = 0;

                                        foreach (Item itemList in inventory)

                                        {

                                            if (itemList.itemName == choiceItemName)

                                            {

                                                inventory.RemoveAt(count);

                                                break;

                                            }

                                            count++;

                                        }

                                        System.Threading.Thread.Sleep(500);

                                    }

                                }

                                break;

                            case 2:

                                Console.Write("버릴 아이템의 이름을 입력하세요 : ");

                                choiceItemName = Console.ReadLine();

                                availability = AvailableTest.CheckItem(inventory, choiceItemName);

                                if (availability == true)

                                {

                                    count = 0;

                                    foreach (Item itemList in inventory)

                                    {

                                        if (itemList.itemName == choiceItemName)

                                        {

                                            inventory.RemoveAt(count);

                                            break;

                                        }

                                        count++;

                                    }

                                    Console.WriteLine("{0}을 버렸습니다.", choiceItemName);

                                    System.Threading.Thread.Sleep(500);

                                }

                                else

                                {

                                    Console.WriteLine("존재하지 않는 아이템입니다.");

                                    System.Threading.Thread.Sleep(500);

                                }

                                break;

                            case 3:

                                menuKey = ConsoleKey.D0;

                                break;

                            default:

                                Console.Write("잘못 입력하셨습니다.");

                                System.Threading.Thread.Sleep(500);

                                break;

                        }

                    }

                }

                if (menuKey == ConsoleKey.D3)

                {

                    Console.Write("\n프로그램을 종료합니다.");

                    System.Threading.Thread.Sleep(500);

                    break;

                }

            }

        }

    }

}

 

Colored by Color Scripter

cs

 

 

개선사항

           - 인벤토리 다양성

           - 아이템 설명추가

           - delegate를 통해 Sort활용

'C# > 과제' 카테고리의 다른 글

Inventory + Singleton  (0) 2019.04.07
Hash란?  (0) 2019.04.04
12. WoW 캐릭터 생성 과제 (2단계+α 까지 완료)  (0) 2019.03.27
11. const(상수)와 enum(열거형)  (0) 2019.03.27
10. Class의 생성흐름 읽기 (동영상)  (0) 2019.03.27
:

12. WoW 캐릭터 생성 과제 (2단계+α 까지 완료)

C#/과제 2019. 3. 27. 03:42

World Of Warcraft를 기반으로 진영, 종족, 직업 선택 및 특성 설명, 무기 착용까지 완료



플레이영상





코드


Program.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace WOW_Make_Character
{
    class Program
    {
        static void Main(string[] args)
        {
            new App();
        }
    }
}
 
cs



GameEnums.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace WOW_Make_Character
{
    class GameEnums
    {
        //Class 기본생성자
        public GameEnums()
        {
 
        }
        //진영 enum
        public enum eCamp
        {
            None = -1,
            Alliance,
            Horde
        }
        //얼라이언스 종족 enum
        public enum eAllianceTribe
        {
            None = -1,
            Human,
            Dwarf,
            NightElf,
            Gnome,
            Draenei,
            Worgen,
            Pandaren
        }
        //호드 종족 enum
        public enum eHordeTribe
        {
            None = -1,
            Orc,
            Undead,
            Tauren,
            Troll,
            BloodElf,
            Goblin,
            Pandaren
        }
        //직업 enum
        public enum eJob
        {
            None = -1,
            Warrior,
            Paladin,
            Hunter,
            Rogue,
            Priest,
            DeathKnight,
            Shamen,
            Mage,
            Warlock,
            Monk,
            Druid,
            DemonHunter
        }
    }
}
 
cs


Character.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace WOW_Make_Character
{
    public class Character
    {
        public string characterName; //닉네임
        public string characterCamp; //진영
        public string characterTribe; //종족
        public string characterJob; //직업
        public string characterWeapon; //무기
        public int characterWeaponDamage; //무기데미지
 
        //기본생성자
        public Character()
        {
 
        }
    }
}
 
cs


Color.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace WOW_Make_Character
{
    class Color
    {
        public Color()
        {
 
        }
        public void ColorReset()
        {
            Console.ForegroundColor = ConsoleColor.Gray;
        }
        public void ColorRed()
        {
            Console.ForegroundColor = ConsoleColor.DarkRed;
        }
        public void ColorBlue()
        {
            Console.ForegroundColor = ConsoleColor.DarkBlue;
        }
        public void ColorMagenta()
        {
            Console.ForegroundColor = ConsoleColor.DarkMagenta;
        }
        public void ColorGreen()
        {
            Console.ForegroundColor = ConsoleColor.DarkGreen;
        }
    }
}
 
cs


Trait.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace WOW_Make_Character
{
    class Trait
    {
        public Trait()
        {
 
        }
        public static void PrintTribeTrait(string characterTribe) //종족특성 출력함수
        {
            string text = System.IO.File.ReadAllText(@"E:\\workspace\\WOW_Make_Character\\Trait\\Tribe\\"+characterTribe+".txt");
            Console.WriteLine(text);
        }
        public static void PrintJobTrait(string characterJob) //직업특성 출력함수
        {
            string text = System.IO.File.ReadAllText(@"E:\\workspace\\WOW_Make_Character\\Trait\\Job\\" + characterJob + ".txt");
            Console.WriteLine(text);
        }
    }
}
 
cs



App.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace WOW_Make_Character
{
    class App
    {
        public App()
        {
            System.Media.SoundPlayer playMusic = new System.Media.SoundPlayer(@"E:\\workspace\\WOW_Make_Character\\wow.wav"); //음악파일 지정
            playMusic.PlayLooping(); //음악파일 루프재생
            string choiceCamp;
            int menuValue = 0;
            int parseValue;
            bool success;
            Character newCharacter = new Character(); //캐릭터 정보 저장 인스턴스
            Color color = new Color(); //컬러 변환 인스턴스
 
            while (menuValue != 100//생성실행
            {
                Console.Clear(); //콘솔창 지우기
 
                while (menuValue == 0)
                {
                    Console.Clear(); //콘솔창 지우기
                    Console.SetCursorPosition(3210);
                    Console.WriteLine("World Of Warcraft에 오신 것을 환영합니다. 모험가님");
                    System.Threading.Thread.Sleep(1000);
                    Console.WriteLine("\n\t\t\t\t플레이하실 종족을 선택하세요");
                    System.Threading.Thread.Sleep(1000);
                    color.ColorBlue();
                    Console.Write("\n\t\t\t\t{0}", GameEnums.eCamp.Alliance);
                    color.ColorReset();
                    Console.Write(" VS ");
                    color.ColorRed();
                    Console.Write("{0}\t\t\t", GameEnums.eCamp.Horde);
                    color.ColorReset();
                    choiceCamp = Console.ReadLine();
                    if (choiceCamp == "얼라이언스" || choiceCamp == nameof(GameEnums.eCamp.Alliance) || choiceCamp == "alliance")
                    {
                        Console.Write("\n\n\t\t\t\t정의의 진영, 얼라이언스를 선택하시겠습니까? (Y/N) : ");
                        ConsoleKey choiceYesOrNo = Console.ReadKey().Key;
                        if (choiceYesOrNo == ConsoleKey.Y)
                        {
                            newCharacter.characterCamp = nameof(GameEnums.eCamp.Alliance);
                            menuValue = 1;
                            break;
                        }
                        else if (choiceYesOrNo == ConsoleKey.N)
                        {
                            Console.WriteLine("\n\t\t\t\t종족 선택화면으로 돌아갑니다.");
                            System.Threading.Thread.Sleep(1000);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("\n\t\t\t\t잘못 입력하였습니다!");
                            System.Threading.Thread.Sleep(1000);
                            Console.WriteLine("\n\t\t\t\t종족 선택화면으로 돌아갑니다.");
                            System.Threading.Thread.Sleep(1000);
                            break;
                        }
                    }
                    else if (choiceCamp == "호드" || choiceCamp == nameof(GameEnums.eCamp.Horde) || choiceCamp == "horde")
                    {
                        Console.Write("\n\n\t\t\t\t신념의 진영, 호드를 선택하시겠습니까? (Y/N) : ");
                        ConsoleKey choiceYesOrNo = Console.ReadKey().Key;
                        if (choiceYesOrNo == ConsoleKey.Y)
                        {
                            newCharacter.characterCamp = nameof(GameEnums.eCamp.Horde);
                            menuValue = 1;
                            break;
                        }
                        else if (choiceYesOrNo == ConsoleKey.N)
                        {
                            Console.WriteLine("\n\t\t\t\t종족 선택화면으로 돌아갑니다.");
                            System.Threading.Thread.Sleep(1000);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("\n\t\t\t\t잘못 입력하였습니다!");
                            System.Threading.Thread.Sleep(1000);
                            Console.WriteLine("\n\t\t\t\t종족 선택화면으로 돌아갑니다.");
                            System.Threading.Thread.Sleep(1000);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("\n\t\t\t\t잘못 입력하였습니다!");
                        System.Threading.Thread.Sleep(1000);
                        Console.WriteLine("\n\t\t\t\t종족 선택화면으로 돌아갑니다.");
                        System.Threading.Thread.Sleep(1000);
                        break;
                    }
                }//진영 선택
 
                while (menuValue == 1)
                {
                    Console.Clear();
                    if (newCharacter.characterCamp == nameof(GameEnums.eCamp.Alliance))
                    {
                        Console.SetCursorPosition(3210);
                        Console.WriteLine("{0}진영에 속하는 종족 중 하나를 선택합니다.", newCharacter.characterCamp);
                        Console.WriteLine("\n\t\t\t\t1.휴먼 2.드워프 3.나이트엘프 4.노움");
                        Console.Write("\n\t\t\t\t5.드레나이 6.늑대인간 7.판다렌 8.돌아가기    : ");
                        success = Int32.TryParse(Console.ReadLine(), out parseValue);
                        if (success)
                        {
                            switch (parseValue)
                            {
                                case 1:
                                    newCharacter.characterTribe = nameof(GameEnums.eAllianceTribe.Human);
                                    menuValue = 2;
                                    break;
                                case 2:
                                    newCharacter.characterTribe = nameof(GameEnums.eAllianceTribe.Dwarf);
                                    menuValue = 2;
                                    break;
                                case 3:
                                    newCharacter.characterTribe = nameof(GameEnums.eAllianceTribe.NightElf);
                                    menuValue = 2;
                                    break;
                                case 4:
                                    newCharacter.characterTribe = nameof(GameEnums.eAllianceTribe.Gnome);
                                    menuValue = 2;
                                    break;
                                case 5:
                                    newCharacter.characterTribe = nameof(GameEnums.eAllianceTribe.Draenei);
                                    menuValue = 2;
                                    break;
                                case 6:
                                    newCharacter.characterTribe = nameof(GameEnums.eAllianceTribe.Worgen);
                                    menuValue = 2;
                                    break;
                                case 7:
                                    newCharacter.characterTribe = nameof(GameEnums.eAllianceTribe.Pandaren);
                                    menuValue = 2;
                                    break;
                                case 8:
                                    menuValue = 0;
                                    break;
                                default:
                                    Console.Write("\t\t\t\t잘못된 입력입니다! 다시 선택해주세요!");
                                    System.Threading.Thread.Sleep(1000);
                                    Console.Clear();
                                    break;
                            }
                        }
                        else
                        {
                            Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                            System.Threading.Thread.Sleep(1000);
                            Console.Clear();
                        }
                    }
                    else if (newCharacter.characterCamp == nameof(GameEnums.eCamp.Horde))
                    {
                        Console.SetCursorPosition(3210);
                        Console.WriteLine("{0} 진영에 속하는 종족 중 하나를 선택합니다.", newCharacter.characterCamp);
                        Console.WriteLine("\n\t\t\t\t1.오크 2.언데드 3.타우렌 4.트롤");
                        Console.Write("\n\t\t\t\t5.블러드엘프 6.고블린 7.판다렌 8.돌아가기    : ");
                        success = Int32.TryParse(Console.ReadLine(), out parseValue);
                        if (success)
                        {
                            switch (parseValue)
                            {
                                case 1:
                                    newCharacter.characterTribe = nameof(GameEnums.eHordeTribe.Orc);
                                    menuValue = 2;
                                    break;
                                case 2:
                                    newCharacter.characterTribe = nameof(GameEnums.eHordeTribe.Undead);
                                    menuValue = 2;
                                    break;
                                case 3:
                                    newCharacter.characterTribe = nameof(GameEnums.eHordeTribe.Tauren);
                                    menuValue = 2;
                                    break;
                                case 4:
                                    newCharacter.characterTribe = nameof(GameEnums.eHordeTribe.Troll);
                                    menuValue = 2;
                                    break;
                                case 5:
                                    newCharacter.characterTribe = nameof(GameEnums.eHordeTribe.BloodElf);
                                    menuValue = 2;
                                    break;
                                case 6:
                                    newCharacter.characterTribe = nameof(GameEnums.eHordeTribe.Goblin);
                                    menuValue = 2;
                                    break;
                                case 7:
                                    newCharacter.characterTribe = nameof(GameEnums.eHordeTribe.Pandaren);
                                    menuValue = 2;
                                    break;
                                case 8:
                                    menuValue = 0;
                                    break;
                                default:
                                    Console.Write("\t\t\t잘못된 입력입니다! 다시 선택해주세요!");
                                    System.Threading.Thread.Sleep(1000);
                                    Console.Clear();
                                    break;
                            }
                        }
                        else
                        {
                            Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                            System.Threading.Thread.Sleep(1000);
                            Console.Clear();
                        }
                    }
                }//종족 선택
 
                while (menuValue == 2)
                {
                    Console.Clear();
                    if (newCharacter.characterCamp == nameof(GameEnums.eCamp.Alliance))
                    {
                        Console.SetCursorPosition(3210);
                        Console.Write("{0}의 직업을 선택합니다.", newCharacter.characterTribe);
                        if (newCharacter.characterTribe == "Human")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.수도사 5.마법사");
                            Console.Write("\n\t\t\t\t6.흑마법사 7.사제 8.성기사 9.전사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warlock);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Paladin);
                                        menuValue = 3;
                                        break;
                                    case 9:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Dwarf")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.수도사 5.마법사");
                            Console.WriteLine("\n\t\t\t\t6.흑마법사 7.사제 8.성기사 9.전사 10.주술사");
                            Console.Write("\n\t\t\t\t0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warlock);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Paladin);
                                        menuValue = 3;
                                        break;
                                    case 9:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 10:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Shamen);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "NightElf")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.수도사 5.마법사");
                            Console.Write("\n\t\t\t\t6.악마사냥꾼 7.사제 8.드루이드 9.전사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DemonHunter);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Druid);
                                        menuValue = 3;
                                        break;
                                    case 9:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Gnome")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.수도사 5.마법사");
                            Console.Write("\n\t\t\t\t6.흑마법사 7.사제 8.전사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warlock);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Draenei")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.사냥꾼 3.수도사 4.마법사 5.사제");
                            Console.Write("\n\t\t\t\t6.성기사 7.전사 8.주술사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Paladin);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Shamen);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Worgen")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.마법사 5.흑마법사");
                            Console.Write("\n\t\t\t\t6.사제 7.드루이드 8.전사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warlock);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Druid);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Pandaren")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.도적 2.사냥꾼 3.수도사 4.마법사 5.사제");
                            Console.Write("\n\t\t\t\t6.전사 7.주술사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Shamen);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
 
                    }
                    else if (newCharacter.characterCamp == nameof(GameEnums.eCamp.Horde))
                    {
                        Console.SetCursorPosition(3210);
                        Console.Write("{0}의 직업을 선택합니다.", newCharacter.characterTribe);
                        if (newCharacter.characterTribe == "Orc")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.수도사 5.마법사");
                            Console.Write("\n\t\t\t\t6.흑마법사 7.전사 8.주술사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warlock);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Shamen);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Undead")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.수도사 5.마법사");
                            Console.Write("\n\t\t\t\t6.흑마법사 7.사제 8.전사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warlock);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Tauren")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.사냥꾼 3.수도사 4.사제 5.드루이드");
                            Console.Write("\n\t\t\t\t6.주술사 7.성기사 8.전사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Druid);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Shamen);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Paladin);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Troll")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.수도사 5.마법사");
                            Console.WriteLine("\n\t\t\t\t6.흑마법사 7.사제 8.전사 9.주술사 10.드루이드");
                            Console.Write("\n\t\t\t\t0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warlock);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 9:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Shamen);
                                        menuValue = 3;
                                        break;
                                    case 10:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Druid);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "BloodElf")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.수도사 5.마법사");
                            Console.WriteLine("\n\t\t\t\t6.흑마법사 7.사제 8.성기사 9.전사 10.악마사냥꾼");
                            Console.Write("\n\t\t\t\t0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warlock);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Paladin);
                                        menuValue = 3;
                                        break;
                                    case 9:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 10:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DemonHunter);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Goblin")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.죽음의기사 2.도적 3.사냥꾼 4.주술사 5.마법사");
                            Console.Write("\n\t\t\t\t6.흑마법사 7.사제 8.전사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.DeathKnight);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Shamen);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warlock);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 8:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                        else if (newCharacter.characterTribe == "Pandaren")
                        {
                            Console.WriteLine("\n\n\t\t\t\t1.도적 2.사냥꾼 3.수도사 4.마법사 5.주술사");
                            Console.Write("\n\t\t\t\t6.사제 7.전사 0.되돌아가기 : ");
                            success = Int32.TryParse(Console.ReadLine(), out parseValue);
                            if (success)
                            {
                                switch (parseValue)
                                {
                                    case 1:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Rogue);
                                        menuValue = 3;
                                        break;
                                    case 2:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Hunter);
                                        menuValue = 3;
                                        break;
                                    case 3:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Monk);
                                        menuValue = 3;
                                        break;
                                    case 4:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Mage);
                                        menuValue = 3;
                                        break;
                                    case 5:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Shamen);
                                        menuValue = 3;
                                        break;
                                    case 6:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Priest);
                                        menuValue = 3;
                                        break;
                                    case 7:
                                        newCharacter.characterJob = nameof(GameEnums.eJob.Warrior);
                                        menuValue = 3;
                                        break;
                                    case 0:
                                        menuValue = 1;
                                        break;
                                }
                            }
                            else
                            {
                                Console.Write("\t\t\t\t잘못된 입력입니다! 다시 입력해주세요!");
                                System.Threading.Thread.Sleep(1000);
                                Console.Clear();
                            }
                        }
                    }
                }//직업 선택
 
                while (menuValue == 3)
                {
                    Console.Clear();
                    Console.SetCursorPosition(3210);
                    Console.Write("캐릭터의 이름을 입력하세요 : ");
                    newCharacter.characterName = Console.ReadLine();
                    Console.WriteLine("\n\t\t\t\t{0}이(가) 생성됩니다. (Y/N)", newCharacter.characterName);
                    Console.Write("\n\t\t\t\t전단계로 되돌아가기(Z), 종료하기(X) : ");
                    ConsoleKey characterNameYN = Console.ReadKey().Key;
                    if (characterNameYN == ConsoleKey.Y)
                    {
                        if (newCharacter.characterJob == nameof(GameEnums.eJob.Warrior))
                        {
                            newCharacter.characterWeapon = "낡은 대검";
                            newCharacter.characterWeaponDamage = 3;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.Paladin))
                        {
                            newCharacter.characterWeapon = "낡은 대검";
                            newCharacter.characterWeaponDamage = 3;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.Hunter))
                        {
                            newCharacter.characterWeapon = "낡은 활";
                            newCharacter.characterWeaponDamage = 3;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.Rogue))
                        {
                            newCharacter.characterWeapon = "낡은 단도";
                            newCharacter.characterWeaponDamage = 2;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.Priest))
                        {
                            newCharacter.characterWeapon = "낡은 성경";
                            newCharacter.characterWeaponDamage = 1;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.DeathKnight))
                        {
                            newCharacter.characterWeapon = "영혼이 서린 대검";
                            newCharacter.characterWeaponDamage = 5;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.Shamen))
                        {
                            newCharacter.characterWeapon = "낡은 목걸이";
                            newCharacter.characterWeaponDamage = 2;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.Mage))
                        {
                            newCharacter.characterWeapon = "낡은 지팡이";
                            newCharacter.characterWeaponDamage = 1;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.Warlock))
                        {
                            newCharacter.characterWeapon = "낡은 지팡이";
                            newCharacter.characterWeaponDamage = 1;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.Monk))
                        {
                            newCharacter.characterWeapon = "낡은 메이스";
                            newCharacter.characterWeaponDamage = 4;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.Druid))
                        {
                            newCharacter.characterWeapon = "낡은 장창";
                            newCharacter.characterWeaponDamage = 1;
                        }
                        else if (newCharacter.characterJob == nameof(GameEnums.eJob.DemonHunter))
                        {
                            newCharacter.characterWeapon = "낡은 블레이드";
                            newCharacter.characterWeaponDamage = 3;
                        }
                        menuValue = 5;
                    }
                    else if (characterNameYN == ConsoleKey.N)
                    {
                        Console.Clear();
                        continue;
                    }
                    else if (characterNameYN == ConsoleKey.Z)
                    {
                        menuValue = 2;
                    }
                    else if (characterNameYN == ConsoleKey.X)
                    {
                        menuValue = 100;
                    }
                    else
                    {
                        Console.Write("\t\t\t\t잘못입력하셨습니다.");
                        System.Threading.Thread.Sleep(1000);
                        Console.Clear();
                        continue;
                    }
                }//닉네임 입력 및 무기지급 (생성완료)
 
                while (menuValue == 5)
                {
                    Console.Clear();
                    Console.SetCursorPosition(3210);
                    Console.WriteLine("유저의 데이터를 불러옵니다.");
                    System.Threading.Thread.Sleep(1500);
 
                    Console.SetCursorPosition(3512);
                    for (int i = 0; i < 10; i++)
                    {
                        Console.Write("■");
                        System.Threading.Thread.Sleep(500);
                    }
                    Console.Clear();
                    Console.SetCursorPosition(3210);
                    Console.Write("{0}님 환영합니다!", newCharacter.characterName);
                    System.Threading.Thread.Sleep(3000);
                    menuValue = 6;
 
                    while (menuValue == 6)
                    {
                        Console.Clear();
                        Console.SetCursorPosition(028);
                        Console.Write("1.캐릭터 정보보기  2.캐릭터 특성보기 3.종료하기");
                        var choiceCharacterInfo = Console.ReadKey().Key;
                        if (choiceCharacterInfo == ConsoleKey.D1 || choiceCharacterInfo == ConsoleKey.NumPad1)
                        {
                            Console.Clear();
                            Console.SetCursorPosition(3210);
                            Console.WriteLine("ID : {0}\t 진영 : {1}\t 종족 : {2}", newCharacter.characterName, newCharacter.characterCamp, newCharacter.characterTribe);
                            Console.WriteLine("\n\t\t\t\t직업 : {0}\t 착용 중인 무기 : {1}(데미지:{2})", newCharacter.characterJob, newCharacter.characterWeapon, newCharacter.characterWeaponDamage);
                            Console.ReadKey();
                        }
                        else if (choiceCharacterInfo == ConsoleKey.D2 || choiceCharacterInfo == ConsoleKey.NumPad2)
                        {
                            Console.Clear();
                            Console.SetCursorPosition(1901); //19,13으로 출력
                            color.ColorMagenta();
                            Console.WriteLine("종족 특성");
                            color.ColorReset();
                            Trait.PrintTribeTrait(newCharacter.characterTribe);
 
                            Console.SetCursorPosition(1915);
                            color.ColorGreen();
                            Console.WriteLine("직업 특성");
                            color.ColorReset();
                            Trait.PrintJobTrait(newCharacter.characterJob);
                            Console.ReadKey();
                        }
                        else if (choiceCharacterInfo == ConsoleKey.D3 || choiceCharacterInfo == ConsoleKey.NumPad3)
                        {
                            Console.Clear();
                            Console.SetCursorPosition(3210);
                            color.ColorRed();
                            Console.Write("{0}님, 전장에서 기다리고 있겠습니다...", newCharacter.characterName);
                            color.ColorReset();
                            System.Threading.Thread.Sleep(3000);
                            Console.SetCursorPosition(3220);
                            menuValue = 100;
                        }
                        else
                        {
                            Console.Clear();
                            Console.SetCursorPosition(3210);
                            Console.Write("잘못된 입력입니다.");
                            System.Threading.Thread.Sleep(1000);
                        }
                    }
                }
            }
        }
 
    }
}
 
cs





패치 방안

1. 멀티 쓰레딩을 통해 윈도우 폼을 활용하여 인터페이스 강화

2. 전투 기능 추가

3. 인벤토리 기능 추가

4. 지역별 배경음악 추가

5. 생성 후 인스턴스의 필드 값이 출력되는 것을 변환 ex)직업 : NightElf -> 직업 : 나이트엘프

6. 코드 분할, 메서드 화


느낀 점

역시 코딩은 재밌다.

'C# > 과제' 카테고리의 다른 글

Hash란?  (0) 2019.04.04
13. 인벤토리 구현하기  (0) 2019.03.27
11. const(상수)와 enum(열거형)  (0) 2019.03.27
10. Class의 생성흐름 읽기 (동영상)  (0) 2019.03.27
9. WoW캐릭터 만들기 [~ing .0326]  (0) 2019.03.26
:

11. const(상수)와 enum(열거형)

C#/과제 2019. 3. 27. 01:23

const(상수)

const 키워드는 상수를 선언할 때 사용한다.

상수는 변수와는 다르게 값을 변경할 수 없으며, 컴파일 타임에 값이 정해진다.

const는 선언과 동시에 초기화해야 하며, 사용자 정의 형식은 const를 사용할 수 없다.

또한, static 필드, 메서드와 같이 따로 인스턴스화 되지 않아도 접근하여 사용할 수 있다.

위의 캡처 처럼 L_Value가 될 수 없다. 변할 수 없는 값이기 때문에 R_Value의 값을 대입할 수 없기 때문이다.

또한, static처럼 App Class를 인스턴스화 하지 않아도 위의 App.number같이 접근하여 사용할 수 있다.


enum(열거형)

enum 키워드는 상수들의 집합을 열거형으로 선언하는데 사용된다.

사용 형식은 enum City {Seoul, Incheon, Sungnam, Paju, Suwon, Gwangju}; 이런식인데, 이들 모두가 상수여야한다.

Seoul부터 차례대로 0, 1, 2, 3, 4, 5의 값을 가지게 된다.

enum City {Seoul=10, Incheon, Sungnam, Paju, Suwon, Gwangju};

이렇게 사용했을 경우, Seoul부터 차례대로 10, 11, 12, 13, 14, 15의 값을 가지게 되는 것이다.

enum City {Seoul=10, Incheon=17, Sungnam=77, Paju=33, Suwon=55, Gwangju=29};

이런식으로 각자에게 값을 할당해 주는 것도 가능하다.

할당하지 않았을 때의 default 값

할당된 값


출처

Microsoft Docs

const 키워드(C# 참조)

https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/const


enum 키워드(C# 참조)

https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/enum


:

10. Class의 생성흐름 읽기 (동영상)

C#/과제 2019. 3. 27. 00:56


세세하게 설명한 버전



아래는 연습영상







'C# > 과제' 카테고리의 다른 글

12. WoW 캐릭터 생성 과제 (2단계+α 까지 완료)  (0) 2019.03.27
11. const(상수)와 enum(열거형)  (0) 2019.03.27
9. WoW캐릭터 만들기 [~ing .0326]  (0) 2019.03.26
8. 멤버변수와 지역변수  (0) 2019.03.26
7. 형식변환  (0) 2019.03.26
: